-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
farthingt
committed
Apr 5, 2024
1 parent
c9d2d02
commit 8aa6fc5
Showing
15 changed files
with
262 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="WebAppCW.AccountPage" | ||
Title="AccountPage"> | ||
<VerticalStackLayout> | ||
<Label | ||
Text="Account Details" | ||
VerticalOptions="Center" | ||
HorizontalOptions="Center" /> | ||
</VerticalStackLayout> | ||
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace WebAppCW; | ||
|
||
public partial class AccountPage : ContentPage | ||
{ | ||
public AccountPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using SQLite; | ||
|
||
namespace WebAppCW | ||
{ | ||
[Table("User")] | ||
public class User | ||
{ | ||
[PrimaryKey] | ||
[AutoIncrement] | ||
[Column("id")] | ||
public int Id { get; set; } | ||
|
||
[Column("username")] | ||
public string? Username { get; set; } | ||
|
||
[Column("password")] | ||
public string? Password { get; set; } | ||
|
||
[Column("email")] | ||
public string? Email { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using Microsoft.Maui.Storage; | ||
using SQLite; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
|
||
namespace WebAppCW | ||
{ | ||
public class UserDB | ||
{ | ||
string _dbPath; | ||
|
||
public string? StatusMessage { get; set; } | ||
|
||
private SQLiteConnection conn; | ||
|
||
private void Init() | ||
{ | ||
if (conn != null) | ||
return; | ||
|
||
conn = new SQLiteConnection(_dbPath); | ||
conn.CreateTable<User>(); | ||
} | ||
|
||
public UserDB(string dbPath) | ||
{ | ||
_dbPath = dbPath; | ||
conn = new SQLiteConnection(_dbPath); | ||
} | ||
|
||
public void AddNewUser(string username, string password, string email) | ||
{ | ||
int result = 0; | ||
try | ||
{ | ||
Init(); | ||
|
||
result = conn.Insert(new User { Username = username, Password = password, Email = email}); | ||
result = 0; | ||
|
||
StatusMessage = string.Format("{0} record(s) added (Name: {1})", result, username); | ||
} | ||
catch (Exception ex) | ||
{ | ||
StatusMessage = string.Format("Failed to add {0}. Error: {1}", username, ex.Message); | ||
} | ||
|
||
} | ||
|
||
public List<User> GetAllUsers() | ||
{ | ||
try | ||
{ | ||
Init(); | ||
return conn.Table<User>().ToList(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
StatusMessage = string.Format("Failed to retrieve data. {0}", ex.Message); | ||
} | ||
|
||
return new List<User>(); | ||
} | ||
|
||
public User GetByUsername(string username) | ||
{ | ||
try | ||
{ | ||
Init(); | ||
var user = from u in conn.Table<User>() | ||
where u.Username == username | ||
select u; | ||
return user.FirstOrDefault(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
StatusMessage = string.Format("Failed to retrieve data. {0}", ex.Message); | ||
} | ||
return null; | ||
} | ||
|
||
public int UpdateUser(User user) | ||
{ | ||
int result = 0; | ||
result = conn.Update(user); | ||
return result; | ||
} | ||
|
||
public int DeleteUser(int userID) | ||
{ | ||
int result = 0; | ||
result = conn.Delete<User>(userID); | ||
return result; | ||
} | ||
public bool IsUsernameAvailable(string username) | ||
{ | ||
try | ||
{ | ||
Init(); | ||
var existingUser = conn.Table<User>().FirstOrDefault(u => u.Username == username); | ||
return existingUser == null; | ||
} | ||
catch (Exception ex) | ||
{ | ||
StatusMessage = $"Failed to check username availability. Error: {ex.Message}"; | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace WebAppCW | ||
{ | ||
public class FileAccessHelper | ||
{ | ||
public static string GetLocalFilePath(string filename) | ||
{ | ||
return System.IO.Path.Combine(FileSystem.AppDataDirectory, filename); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.