Skip to content

Commit 6bff7ed

Browse files
committed
devexpress added.
1 parent b13ac22 commit 6bff7ed

19 files changed

+470
-37
lines changed

MyFinance/App.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace MyFinance;
22

3-
public partial class App : Application
3+
public partial class App : MC.Application
44
{
55
public App(IServiceProvider services)
66
{

MyFinance/Context/MyFinanceContext.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace MyFinance.Context;
2+
3+
public class MyFinanceContext : DbContext
4+
{
5+
public DbSet<User> Users { get; set; }
6+
7+
8+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
9+
{
10+
if (!optionsBuilder.IsConfigured)
11+
{
12+
var connDb = $"Filename={PathDB.GetPath("MyFinanceDemo.db")}";
13+
optionsBuilder.UseSqlite(connDb);
14+
}
15+
}
16+
17+
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
18+
{
19+
var datas = ChangeTracker.Entries<BaseModel>();
20+
foreach (var data in datas)
21+
{
22+
_ = data.State switch
23+
{
24+
EntityState.Added => data.Entity.CreateDate = DateTime.Now,
25+
EntityState.Modified => data.Entity.UpdateDate = DateTime.Now,
26+
};
27+
}
28+
return base.SaveChangesAsync(cancellationToken);
29+
}
30+
}

MyFinance/DTOs/LoginDTO.cs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace MyFinance.DTOs;
2+
3+
public class LoginDTO
4+
{
5+
public string Username { get; set; }
6+
public string Password { get; set; }
7+
public bool IsRememberMe { get; set; }
8+
}

MyFinance/Enums/Gender.cs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace MyFinance.Enums;
2+
3+
public enum Gender
4+
{
5+
Male,
6+
Female
7+
}
8+

MyFinance/Imports.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,29 @@
1010
global using CommunityToolkit.Mvvm.Messaging;
1111
// Markup FmgLib
1212
global using FmgLib.MauiMarkup;
13+
1314
global using MyFinance;
1415
global using MyFinance.ViewModels;
1516
global using MyFinance.Views;
16-
global using UraniumUI.Material.Controls;
17+
global using MyFinance.Models;
18+
global using MyFinance.Enums;
19+
global using MyFinance.Utilities;
20+
global using MyFinance.Context;
21+
global using MyFinance.Repository;
22+
global using MyFinance.DTOs;
23+
24+
global using Microsoft.EntityFrameworkCore;
25+
26+
27+
global using DevExpress.Maui.Controls;
28+
global using DevExpress.Maui.Editors;
29+
global using DevExpress.Maui.DataForm;
30+
global using DevExpress.Maui.CollectionView;
31+
global using DevExpress.Maui;
1732
global using static Microsoft.Maui.Controls.FontAttributes;
1833
global using static Microsoft.Maui.Controls.LayoutAlignment;
1934
global using static Microsoft.Maui.Graphics.Colors;
35+
global using static Microsoft.Maui.TextDecorations;
2036

2137
global using MC = Microsoft.Maui.Controls;
38+
global using DC = DevExpress.Maui.Controls;

MyFinance/MauiProgram.cs

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
using Microsoft.Extensions.Logging;
2-
using UraniumUI;
32

43
namespace MyFinance;
54

65

7-
[MauiMarkup(typeof(StatusBarBehavior), typeof(ShellContent), typeof(TextField), typeof(InputField))]
6+
[MauiMarkup(typeof(StatusBarBehavior), typeof(ShellContent), typeof(TextEdit), typeof(TextEditBase), typeof(EditBase))]
7+
[MauiMarkup(typeof(PasswordEdit), typeof(CheckEdit), typeof(DXPopup))]
88
public static class MauiProgram
99
{
1010
public static MauiApp CreateMauiApp()
1111
{
1212
var builder = MauiApp.CreateBuilder();
1313
builder
1414
.UseMauiApp<App>()
15-
.UseUraniumUI()
16-
.UseUraniumUIMaterial()
15+
.UseDevExpress()
1716
.UseMauiCommunityToolkit()
1817
.ConfigureFonts(fonts =>
1918
{
@@ -26,9 +25,32 @@ public static MauiApp CreateMauiApp()
2625
builder.Services
2726
.AddSingleton<App>()
2827
.AddSingleton<AppShell>()
28+
.AddDbContext<MyFinanceContext>()
2929
.AddScopedWithShellRoute<MainPage, MainPageViewModel>($"//{nameof(MainPage)}")
3030
.AddScopedWithShellRoute<LoginPage, LoginPageViewModel>($"//{nameof(LoginPage)}")
31-
.AddScoped<StartedPage>();
31+
.AddScoped<StartedPage>()
32+
.AddScoped<IUserRepo, UserRepo>();
33+
34+
#region Init DB
35+
var dbContext = new MyFinanceContext();
36+
dbContext.Database.EnsureCreated();
37+
if (dbContext.Users.Count() <= 0)
38+
{
39+
dbContext.Users.Add(new()
40+
{
41+
Age = 23,
42+
Email = "mg",
43+
Password = "00",
44+
FirstName = "Mustafa",
45+
LastName = "Gönültaş",
46+
Gender = Gender.Male,
47+
IsActive = true,
48+
PhoneNumber = "1234567890"
49+
});
50+
dbContext.SaveChanges();
51+
}
52+
dbContext.Dispose();
53+
#endregion
3254

3355
return builder.Build();
3456
}

MyFinance/Models/Common/BaseModel.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace MyFinance.Models;
2+
3+
public class BaseModel
4+
{
5+
public Guid Id { get; set; }
6+
public DateTime CreateDate { get; set; }
7+
public Guid CreatedBy { get; set; }
8+
public DateTime UpdateDate { get; set; }
9+
public Guid UpdatedBy { get; set; }
10+
public bool IsActive { get; set; }
11+
}

MyFinance/Models/User.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace MyFinance.Models;
2+
3+
public class User : BaseModel
4+
{
5+
public required string FirstName { get; set; }
6+
public required string LastName { get; set; }
7+
public required string Email { get; set; }
8+
public required string Password { get; set; }
9+
public string? PhoneNumber { get; set; }
10+
public int Age { get; set; }
11+
public Gender Gender { get; set; }
12+
}

MyFinance/MyFinance.csproj

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
5-
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
6-
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7-
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
8-
9-
<!-- Note for MacCatalyst:
10-
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
11-
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
12-
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
13-
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
14-
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
4+
<TargetFrameworks>net8.0-android;net8.0-ios;</TargetFrameworks>
155

166
<OutputType>Exe</OutputType>
177
<RootNamespace>MyFinance</RootNamespace>
@@ -64,11 +54,13 @@
6454
<ItemGroup>
6555
<PackageReference Include="CommunityToolkit.Maui" Version="9.0.0" />
6656
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
57+
<PackageReference Include="DevExpress.Maui.Controls" Version="24.1.1-alpha-24085" />
58+
<PackageReference Include="DevExpress.Maui.Editors" Version="24.1.1-alpha-24085" />
6759
<PackageReference Include="FmgLib.MauiMarkup" Version="8.*" />
60+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
6861
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.21" />
6962
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.21" />
7063
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
71-
<PackageReference Include="UraniumUI.Material" Version="2.8.1" />
7264
</ItemGroup>
7365

7466
</Project>

MyFinance/Repository/IRepo.cs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Linq.Expressions;
2+
3+
namespace MyFinance.Repository;
4+
5+
public interface IRepo<TModel> where TModel : BaseModel
6+
{
7+
DbSet<TModel> Table { get; }
8+
Task<int> SaveAsync();
9+
10+
Task<List<TModel>> GetAllAsync(Expression<Func<TModel, bool>> expression = null, Expression<Func<TModel, object>> include = null, Expression<Func<TModel, object>> ordered = null, int? skip = null, int? limit = null);
11+
Task<TModel?> GetSingleAsync(Expression<Func<TModel, bool>> expression, Expression<Func<TModel, object>> include = null);
12+
Task<int> GetCountAsync(Expression<Func<TModel, bool>> filter = null);
13+
14+
Task<bool> InsertAsync(TModel item);
15+
Task<bool> UpdateAsync(TModel item);
16+
Task<bool> RemoveAsync(Guid id);
17+
Task<bool> RemoveRangeAsync(List<Guid> ids);
18+
}

MyFinance/Repository/Repo.cs

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
using Microsoft.EntityFrameworkCore.ChangeTracking;
2+
using System.Linq;
3+
using System.Linq.Expressions;
4+
5+
namespace MyFinance.Repository;
6+
7+
public class Repo<TModel> : IRepo<TModel> where TModel : BaseModel
8+
{
9+
private readonly MyFinanceContext _context;
10+
11+
public Repo(MyFinanceContext context)
12+
{
13+
_context = context;
14+
}
15+
16+
public DbSet<TModel> Table => _context.Set<TModel>();
17+
18+
public async Task<List<TModel>> GetAllAsync(Expression<Func<TModel, bool>> expression = null, Expression<Func<TModel, object>> include = null, Expression<Func<TModel, object>> ordered = null, int? skip = null, int? limit = null)
19+
{
20+
var query = Table.AsNoTracking();
21+
22+
if (expression != null)
23+
query = query.Where(expression);
24+
25+
if (include != null)
26+
query = query.Include(include);
27+
28+
if (ordered != null)
29+
query = query.OrderBy(ordered);
30+
31+
if (skip.HasValue)
32+
query = query.Skip(skip.Value);
33+
34+
if (limit.HasValue)
35+
query = query.Take(limit.Value);
36+
37+
return await query.ToListAsync();
38+
}
39+
40+
public async Task<int> GetCountAsync(Expression<Func<TModel, bool>> filter = null)
41+
{
42+
var query = Table.AsNoTracking();
43+
44+
if (filter != null)
45+
query = query.Where(filter);
46+
47+
return await query.CountAsync();
48+
}
49+
50+
public async Task<TModel?> GetSingleAsync(Expression<Func<TModel, bool>> expression, Expression<Func<TModel, object>> include = null)
51+
{
52+
var query = Table.AsNoTracking().Where(expression);
53+
54+
if (include != null)
55+
query = query.Include(include);
56+
57+
return await query.FirstOrDefaultAsync();
58+
}
59+
60+
public async Task<bool> InsertAsync(TModel item)
61+
{
62+
try
63+
{
64+
EntityEntry<TModel> entityEntry = await Table.AddAsync(item);
65+
await SaveAsync();
66+
67+
return true;
68+
}
69+
catch (Exception)
70+
{
71+
return false;
72+
}
73+
}
74+
75+
public async Task<bool> RemoveAsync(Guid id)
76+
{
77+
try
78+
{
79+
var model = await Table.FirstOrDefaultAsync(x => x.Id == id);
80+
Table.Remove(model);
81+
await SaveAsync();
82+
83+
return true;
84+
}
85+
catch (Exception)
86+
{
87+
return false;
88+
}
89+
}
90+
91+
public async Task<bool> RemoveRangeAsync(List<Guid> ids)
92+
{
93+
try
94+
{
95+
var models = await Table.AsNoTracking().Where(x => ids.Contains(x.Id)).ToListAsync();
96+
Table.RemoveRange(models);
97+
await SaveAsync();
98+
99+
return true;
100+
}
101+
catch (Exception)
102+
{
103+
return false;
104+
}
105+
}
106+
107+
public async Task<int> SaveAsync() => await _context.SaveChangesAsync();
108+
109+
public async Task<bool> UpdateAsync(TModel item)
110+
{
111+
try
112+
{
113+
EntityEntry<TModel> entityEntry = Table.Update(item);
114+
await SaveAsync();
115+
116+
return true;
117+
}
118+
catch (Exception)
119+
{
120+
return false;
121+
}
122+
}
123+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace MyFinance.Repository;
2+
3+
public interface IUserRepo : IRepo<User>
4+
{
5+
}

MyFinance/Repository/User/UserRepo.cs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+

2+
namespace MyFinance.Repository;
3+
4+
public class UserRepo(MyFinanceContext context) : Repo<User>(context), IUserRepo
5+
{ }

MyFinance/Resources/Styles/AppStyles.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class AppStyles
88
public static ResourceDictionary Default => new ResourceDictionary {
99

1010
// "ActivityIndicator"
11-
11+
1212
new Style<ActivityIndicator>(e => e
1313
.Color(e => e.OnLight(AppColors.Primary).OnDark(Colors.White))),
1414

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Text;
2+
3+
namespace MyFinance.Utilities;
4+
5+
public static class AuthCheckHelper
6+
{
7+
public static string BasicAuth(string username, string password, DateTime expireTime)
8+
{
9+
string credentials = $"{username}:{password}:{expireTime.ToShortDateString()}";
10+
byte[] credentialsBytes = Encoding.UTF8.GetBytes(credentials);
11+
string base64Credebtials = Convert.ToBase64String(credentialsBytes);
12+
13+
return base64Credebtials;
14+
}
15+
16+
public static (string?, string?, DateTime?) ParseBasicAuthToken(string authToken)
17+
{
18+
if (string.IsNullOrEmpty(authToken))
19+
return (null, null, null);
20+
21+
byte[] bytes = Convert.FromBase64String(authToken);
22+
string credentials = Encoding.UTF8.GetString(bytes);
23+
var userInfo = credentials.Split(':', StringSplitOptions.TrimEntries);
24+
25+
return (userInfo[0], userInfo[1], Convert.ToDateTime(userInfo[2]));
26+
}
27+
}
28+

0 commit comments

Comments
 (0)