Skip to content

Commit f1fff1e

Browse files
committed
fixes.
1 parent 3609f37 commit f1fff1e

15 files changed

+221
-153
lines changed

MyFinance/Context/MyFinanceContext.cs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public class MyFinanceContext : DbContext
44
{
55
public DbSet<User> Users { get; set; }
6+
public DbSet<OperationItem> OperationItems { get; set; }
67

78

89
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

MyFinance/Imports.cs

+2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
global using MyFinance.DTOs;
2323
global using MyFinance.Controls;
2424
global using MyFinance.VMs;
25+
global using MyFinance.Mapping;
2526

2627
global using Microsoft.EntityFrameworkCore;
28+
global using AutoMapper;
2729

2830
global using LiveChartsCore;
2931
global using LiveChartsCore.SkiaSharpView;

MyFinance/Mapping/UserProfile.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using AutoMapper;
2+
3+
namespace MyFinance.Mapping;
4+
5+
public class UserProfile : Profile
6+
{
7+
public UserProfile()
8+
{
9+
CreateMaps();
10+
}
11+
12+
private void CreateMaps()
13+
{
14+
CreateMap<OperationItem, OperationItemsVM>()
15+
.ForMember(dist => dist.Date, opt => opt.MapFrom(src => src.Date.ToString("dd.MM.yyyy HH:mm")))
16+
.ForMember(dist => dist.Color, opt => opt.MapFrom(src => src.Color == nameof(Green) ? Green : Red))
17+
.ForMember(dist => dist.Amount, opt => opt.MapFrom(src => $"{src.Amount} ₺"));
18+
}
19+
}

MyFinance/MauiProgram.cs

+33-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.Maui.Controls.Compatibility.Hosting;
33
using SkiaSharp.Views.Maui.Controls.Hosting;
44
using DXImage = DevExpress.Maui.Core.DXImage;
5+
using SwipeItem = DevExpress.Maui.CollectionView.SwipeItem;
56

67
namespace MyFinance;
78

@@ -10,7 +11,8 @@ namespace MyFinance;
1011
[MauiMarkup(typeof(PasswordEdit), typeof(CheckEdit), typeof(DXPopup), typeof(ComboBoxEditBase), typeof(ItemsEditBase))]
1112
[MauiMarkup(typeof(DXImage), typeof(DXButton), typeof(DXViewBase), typeof(DXBorder), typeof(DXContentPresenterBase))]
1213
[MauiMarkup(typeof(DXContentPresenter), typeof(DXCollectionView), typeof(CartesianChart), typeof(TabView), typeof(TabViewItem))]
13-
[MauiMarkup(typeof(TabItem), typeof(DXButtonBase), typeof(ShimmerView))]
14+
[MauiMarkup(typeof(TabItem), typeof(DXButtonBase), typeof(ShimmerView), typeof(DXCollectionViewBase), typeof(SwipeContainer))]
15+
[MauiMarkup(typeof(SwipeItem))]
1416
public static class MauiProgram
1517
{
1618
public static MauiApp CreateMauiApp()
@@ -34,14 +36,16 @@ public static MauiApp CreateMauiApp()
3436
.AddSingleton<App>()
3537
.AddSingleton<AppShell>()
3638
.AddDbContext<MyFinanceContext>()
39+
.AddAutoMapper(typeof(App))
3740
.AddScopedWithShellRoute<MainPage, MainPageViewModel>($"//{nameof(MainPage)}")
3841
.AddScopedWithShellRoute<ChartPage, ChartPageViewModel>($"//{nameof(ChartPage)}")
3942
.AddScopedWithShellRoute<ItemsPage, ItemsPageViewModel>($"//{nameof(ItemsPage)}")
4043
.AddScopedWithShellRoute<AccountPage, AccountPageViewModel>($"//{nameof(AccountPage)}")
4144
.AddScopedWithShellRoute<LoginPage, LoginPageViewModel>($"//{nameof(LoginPage)}")
4245
.AddScopedWithShellRoute<RegisterPage, RegisterPageViewModel>($"//{nameof(RegisterPage)}")
4346
.AddScoped<StartedPage>()
44-
.AddScoped<IUserRepo, UserRepo>();
47+
.AddScoped<IUserRepo, UserRepo>()
48+
.AddScoped<IOperationItemsRepo, OperationItemsRepo>();
4549

4650
#region Init DB
4751
var dbContext = new MyFinanceContext();
@@ -61,6 +65,33 @@ public static MauiApp CreateMauiApp()
6165
});
6266
dbContext.SaveChanges();
6367
}
68+
69+
if (dbContext.OperationItems.Count() <= 0)
70+
{
71+
List<OperationItem> items = new List<OperationItem>();
72+
Random random = new Random();
73+
for (int i = 1; i <= 500; i++)
74+
{
75+
var amount = random.Next(1, 10000);
76+
items.Add(
77+
new OperationItem
78+
{
79+
Icon = amount % 2 == 0 ? "loss.png" : "profits.png",
80+
Color = amount % 2 == 0 ? nameof(Red) : nameof(Green),
81+
Date = DateTime.Now.AddDays(-(amount % 200)),
82+
Title = amount % 2 == 0 ? "Borç ödendi" : "Ödeme Alındı",
83+
Description = amount % 2 == 0 ? "Ödemeler yapıldı" : "Yaka parası alındı.",
84+
Amount = amount,
85+
CreateDate = DateTime.Now.AddDays(-(amount % 200)),
86+
UpdateDate = DateTime.Now.AddDays(-(amount % 200)),
87+
IsActive = true
88+
}
89+
);
90+
}
91+
92+
dbContext.AddRange(items);
93+
dbContext.SaveChanges();
94+
}
6495
dbContext.Dispose();
6596
#endregion
6697

MyFinance/Models/OperationItem.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace MyFinance.Models;
2+
3+
public class OperationItem : BaseModel
4+
{
5+
public string Icon { get; set; }
6+
public string Title { get; set; }
7+
public string Description { get; set; }
8+
public DateTime Date { get; set; }
9+
public double Amount { get; set; }
10+
public string Color { get; set; }
11+
}

MyFinance/MyFinance.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
</ItemGroup>
6363

6464
<ItemGroup>
65+
<PackageReference Include="AutoMapper" Version="13.0.1" />
6566
<PackageReference Include="CommunityToolkit.Maui" Version="9.0.0" />
6667
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
6768
<PackageReference Include="DevExpress.Maui.Controls" Version="24.1.1-alpha-24085" />

MyFinance/Repository/IRepo.cs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public interface IRepo<TModel> where TModel : BaseModel
88
Task<int> SaveAsync();
99

1010
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<double> GetSumAsync(Expression<Func<TModel, double>> sumProp, Expression<Func<TModel, bool>> expression = null, Expression<Func<TModel, object>> include = null, int? skip = null, int? limit = null);
1112
Task<TModel?> GetSingleAsync(Expression<Func<TModel, bool>> expression, Expression<Func<TModel, object>> include = null);
1213
Task<int> GetCountAsync(Expression<Func<TModel, bool>> filter = null);
1314

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace MyFinance.Repository;
2+
3+
public interface IOperationItemsRepo : IRepo<OperationItem>
4+
{
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+

2+
namespace MyFinance.Repository;
3+
4+
public class OperationItemsRepo(MyFinanceContext context) : Repo<OperationItem>(context), IOperationItemsRepo
5+
{
6+
}

MyFinance/Repository/Repo.cs

+19
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ public async Task<List<TModel>> GetAllAsync(Expression<Func<TModel, bool>> expre
3737
return await query.ToListAsync();
3838
}
3939

40+
public async Task<double> GetSumAsync(Expression<Func<TModel, double>> sumProp, Expression<Func<TModel, bool>> expression = null, Expression<Func<TModel, object>> include = null, int? skip = null, int? limit = null)
41+
{
42+
var query = Table.AsNoTracking();
43+
44+
if (expression != null)
45+
query = query.Where(expression);
46+
47+
if (include != null)
48+
query = query.Include(include);
49+
50+
if (skip.HasValue)
51+
query = query.Skip(skip.Value);
52+
53+
if (limit.HasValue)
54+
query = query.Take(limit.Value);
55+
56+
return await query.SumAsync(sumProp);
57+
}
58+
4059
public async Task<int> GetCountAsync(Expression<Func<TModel, bool>> filter = null)
4160
{
4261
var query = Table.AsNoTracking();

MyFinance/VMs/OperatonItemsVM.cs MyFinance/VMs/OperationItemsVM.cs

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

3-
public class OperatonItemsVM
3+
public class OperationItemsVM
44
{
55
public Guid Id { get; set; }
66
public string Icon { get; set; }

MyFinance/ViewModels/ChartPageViewModel.cs

+11-39
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
using LiveChartsCore.SkiaSharpView.Painting.Effects;
1+
using LiveChartsCore.Drawing;
2+
using LiveChartsCore.Kernel.Sketches;
23
using LiveChartsCore.SkiaSharpView.Painting;
4+
using LiveChartsCore.SkiaSharpView.Painting.Effects;
35
using SkiaSharp;
4-
using System.Linq;
5-
using LiveChartsCore.Drawing;
6-
using System.Linq.Expressions;
76
using System.Globalization;
8-
using System;
9-
using static System.Runtime.InteropServices.JavaScript.JSType;
10-
using LiveChartsCore.Kernel.Sketches;
117

128
namespace MyFinance.ViewModels;
139

1410
public partial class ChartPageViewModel : BaseViewModel
1511
{
12+
private readonly IOperationItemsRepo _operationItemsRepo;
1613
CultureInfo culture = new CultureInfo("tr-TR");
1714

1815
[ObservableProperty]
@@ -86,35 +83,10 @@ public partial class ChartPageViewModel : BaseViewModel
8683
private static readonly SKColor s_red = new(255, 0, 0);
8784
private static readonly SKColor s_blue = new(0, 0, 255);
8885

89-
90-
private List<OperatonItemsVM> items = new();
91-
92-
public ChartPageViewModel()
86+
public ChartPageViewModel(IOperationItemsRepo operationItemsRepo)
9387
{
88+
_operationItemsRepo = operationItemsRepo;
9489
CType = (int)ChartType.Weekly;
95-
TotalBalance = "25,291.50 ₺";
96-
TotalExpense = "2,367.82 ₺";
97-
TotalIncome = "167.82 ₺";
98-
99-
100-
101-
Random random = new Random();
102-
for (int i = 1; i <= 500; i++)
103-
{
104-
var amount = random.Next(1, 10000);
105-
items.Add(
106-
new OperatonItemsVM
107-
{
108-
Id = Guid.NewGuid(),
109-
Icon = amount % 2 == 0 ? "loss.png" : "profits.png",
110-
Color = amount % 2 == 0 ? Red : Green,
111-
Date = DateTime.Now.AddDays(-(amount % 180)).ToString("dd.MM.yyyy HH:mm"),
112-
Title = amount % 2 == 0 ? "Borç ödendi" : "Ödeme Alındı",
113-
Description = amount % 2 == 0 ? "Ödemeler yapıldı" : "Yaka parası alındı.",
114-
Amount = $"{amount} ₺"
115-
}
116-
);
117-
}
11890

11991
Calc(7);
12092
}
@@ -131,12 +103,12 @@ public void ChartTypeChanged()
131103
Calc(180);
132104
}
133105

134-
private void Calc(int days)
106+
private async Task Calc(int days)
135107
{
136-
var graphVals = items
137-
.Where(e => DateTime.Parse(e.Date) > DateTime.Now.AddDays(-days))
138-
.Select(e => new OperationGraphVM { Date = DateTime.Parse(e.Date).Date, Amount = double.Parse(e.Amount.Trim().Trim('₺')), IsIncome = e.Color == Green })
139-
.OrderBy(e => e.Date)
108+
var graphVals = (await _operationItemsRepo.GetAllAsync(
109+
expression: e => e.Date > DateTime.Now.AddDays(-days),
110+
ordered: e => e.Date.Date))
111+
.Select(e => new OperationGraphVM { Date = e.Date.Date, Amount = e.Amount, IsIncome = e.Color == nameof(Green) })
140112
.ToList();
141113

142114
var strokeThickness = 6;

0 commit comments

Comments
 (0)