Skip to content

Commit

Permalink
fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonultasmf committed May 16, 2024
1 parent 3609f37 commit f1fff1e
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 153 deletions.
1 change: 1 addition & 0 deletions MyFinance/Context/MyFinanceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class MyFinanceContext : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<OperationItem> OperationItems { get; set; }


protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
Expand Down
2 changes: 2 additions & 0 deletions MyFinance/Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
global using MyFinance.DTOs;
global using MyFinance.Controls;
global using MyFinance.VMs;
global using MyFinance.Mapping;

global using Microsoft.EntityFrameworkCore;
global using AutoMapper;

global using LiveChartsCore;
global using LiveChartsCore.SkiaSharpView;
Expand Down
19 changes: 19 additions & 0 deletions MyFinance/Mapping/UserProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using AutoMapper;

namespace MyFinance.Mapping;

public class UserProfile : Profile
{
public UserProfile()
{
CreateMaps();
}

private void CreateMaps()
{
CreateMap<OperationItem, OperationItemsVM>()
.ForMember(dist => dist.Date, opt => opt.MapFrom(src => src.Date.ToString("dd.MM.yyyy HH:mm")))
.ForMember(dist => dist.Color, opt => opt.MapFrom(src => src.Color == nameof(Green) ? Green : Red))
.ForMember(dist => dist.Amount, opt => opt.MapFrom(src => $"{src.Amount}"));
}
}
35 changes: 33 additions & 2 deletions MyFinance/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Maui.Controls.Compatibility.Hosting;
using SkiaSharp.Views.Maui.Controls.Hosting;
using DXImage = DevExpress.Maui.Core.DXImage;
using SwipeItem = DevExpress.Maui.CollectionView.SwipeItem;

namespace MyFinance;

Expand All @@ -10,7 +11,8 @@ namespace MyFinance;
[MauiMarkup(typeof(PasswordEdit), typeof(CheckEdit), typeof(DXPopup), typeof(ComboBoxEditBase), typeof(ItemsEditBase))]
[MauiMarkup(typeof(DXImage), typeof(DXButton), typeof(DXViewBase), typeof(DXBorder), typeof(DXContentPresenterBase))]
[MauiMarkup(typeof(DXContentPresenter), typeof(DXCollectionView), typeof(CartesianChart), typeof(TabView), typeof(TabViewItem))]
[MauiMarkup(typeof(TabItem), typeof(DXButtonBase), typeof(ShimmerView))]
[MauiMarkup(typeof(TabItem), typeof(DXButtonBase), typeof(ShimmerView), typeof(DXCollectionViewBase), typeof(SwipeContainer))]
[MauiMarkup(typeof(SwipeItem))]
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
Expand All @@ -34,14 +36,16 @@ public static MauiApp CreateMauiApp()
.AddSingleton<App>()
.AddSingleton<AppShell>()
.AddDbContext<MyFinanceContext>()
.AddAutoMapper(typeof(App))
.AddScopedWithShellRoute<MainPage, MainPageViewModel>($"//{nameof(MainPage)}")
.AddScopedWithShellRoute<ChartPage, ChartPageViewModel>($"//{nameof(ChartPage)}")
.AddScopedWithShellRoute<ItemsPage, ItemsPageViewModel>($"//{nameof(ItemsPage)}")
.AddScopedWithShellRoute<AccountPage, AccountPageViewModel>($"//{nameof(AccountPage)}")
.AddScopedWithShellRoute<LoginPage, LoginPageViewModel>($"//{nameof(LoginPage)}")
.AddScopedWithShellRoute<RegisterPage, RegisterPageViewModel>($"//{nameof(RegisterPage)}")
.AddScoped<StartedPage>()
.AddScoped<IUserRepo, UserRepo>();
.AddScoped<IUserRepo, UserRepo>()
.AddScoped<IOperationItemsRepo, OperationItemsRepo>();

#region Init DB
var dbContext = new MyFinanceContext();
Expand All @@ -61,6 +65,33 @@ public static MauiApp CreateMauiApp()
});
dbContext.SaveChanges();
}

if (dbContext.OperationItems.Count() <= 0)
{
List<OperationItem> items = new List<OperationItem>();
Random random = new Random();
for (int i = 1; i <= 500; i++)
{
var amount = random.Next(1, 10000);
items.Add(
new OperationItem
{
Icon = amount % 2 == 0 ? "loss.png" : "profits.png",
Color = amount % 2 == 0 ? nameof(Red) : nameof(Green),
Date = DateTime.Now.AddDays(-(amount % 200)),
Title = amount % 2 == 0 ? "Borç ödendi" : "Ödeme Alındı",
Description = amount % 2 == 0 ? "Ödemeler yapıldı" : "Yaka parası alındı.",
Amount = amount,
CreateDate = DateTime.Now.AddDays(-(amount % 200)),
UpdateDate = DateTime.Now.AddDays(-(amount % 200)),
IsActive = true
}
);
}

dbContext.AddRange(items);
dbContext.SaveChanges();
}
dbContext.Dispose();
#endregion

Expand Down
11 changes: 11 additions & 0 deletions MyFinance/Models/OperationItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace MyFinance.Models;

public class OperationItem : BaseModel
{
public string Icon { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime Date { get; set; }
public double Amount { get; set; }
public string Color { get; set; }
}
1 change: 1 addition & 0 deletions MyFinance/MyFinance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="CommunityToolkit.Maui" Version="9.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="DevExpress.Maui.Controls" Version="24.1.1-alpha-24085" />
Expand Down
1 change: 1 addition & 0 deletions MyFinance/Repository/IRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface IRepo<TModel> where TModel : BaseModel
Task<int> SaveAsync();

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);
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);
Task<TModel?> GetSingleAsync(Expression<Func<TModel, bool>> expression, Expression<Func<TModel, object>> include = null);
Task<int> GetCountAsync(Expression<Func<TModel, bool>> filter = null);

Expand Down
5 changes: 5 additions & 0 deletions MyFinance/Repository/OperationItems/IOperationItemsRepo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace MyFinance.Repository;

public interface IOperationItemsRepo : IRepo<OperationItem>
{
}
6 changes: 6 additions & 0 deletions MyFinance/Repository/OperationItems/OperationItemsRepo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

namespace MyFinance.Repository;

public class OperationItemsRepo(MyFinanceContext context) : Repo<OperationItem>(context), IOperationItemsRepo
{
}
19 changes: 19 additions & 0 deletions MyFinance/Repository/Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ public async Task<List<TModel>> GetAllAsync(Expression<Func<TModel, bool>> expre
return await query.ToListAsync();
}

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)
{
var query = Table.AsNoTracking();

if (expression != null)
query = query.Where(expression);

if (include != null)
query = query.Include(include);

if (skip.HasValue)
query = query.Skip(skip.Value);

if (limit.HasValue)
query = query.Take(limit.Value);

return await query.SumAsync(sumProp);
}

public async Task<int> GetCountAsync(Expression<Func<TModel, bool>> filter = null)
{
var query = Table.AsNoTracking();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace MyFinance.VMs;

public class OperatonItemsVM
public class OperationItemsVM
{
public Guid Id { get; set; }
public string Icon { get; set; }
Expand Down
50 changes: 11 additions & 39 deletions MyFinance/ViewModels/ChartPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using LiveChartsCore.SkiaSharpView.Painting.Effects;
using LiveChartsCore.Drawing;
using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.SkiaSharpView.Painting;
using LiveChartsCore.SkiaSharpView.Painting.Effects;
using SkiaSharp;
using System.Linq;
using LiveChartsCore.Drawing;
using System.Linq.Expressions;
using System.Globalization;
using System;
using static System.Runtime.InteropServices.JavaScript.JSType;
using LiveChartsCore.Kernel.Sketches;

namespace MyFinance.ViewModels;

public partial class ChartPageViewModel : BaseViewModel
{
private readonly IOperationItemsRepo _operationItemsRepo;
CultureInfo culture = new CultureInfo("tr-TR");

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


private List<OperatonItemsVM> items = new();

public ChartPageViewModel()
public ChartPageViewModel(IOperationItemsRepo operationItemsRepo)
{
_operationItemsRepo = operationItemsRepo;
CType = (int)ChartType.Weekly;
TotalBalance = "25,291.50 ₺";
TotalExpense = "2,367.82 ₺";
TotalIncome = "167.82 ₺";



Random random = new Random();
for (int i = 1; i <= 500; i++)
{
var amount = random.Next(1, 10000);
items.Add(
new OperatonItemsVM
{
Id = Guid.NewGuid(),
Icon = amount % 2 == 0 ? "loss.png" : "profits.png",
Color = amount % 2 == 0 ? Red : Green,
Date = DateTime.Now.AddDays(-(amount % 180)).ToString("dd.MM.yyyy HH:mm"),
Title = amount % 2 == 0 ? "Borç ödendi" : "Ödeme Alındı",
Description = amount % 2 == 0 ? "Ödemeler yapıldı" : "Yaka parası alındı.",
Amount = $"{amount}"
}
);
}

Calc(7);
}
Expand All @@ -131,12 +103,12 @@ public void ChartTypeChanged()
Calc(180);
}

private void Calc(int days)
private async Task Calc(int days)
{
var graphVals = items
.Where(e => DateTime.Parse(e.Date) > DateTime.Now.AddDays(-days))
.Select(e => new OperationGraphVM { Date = DateTime.Parse(e.Date).Date, Amount = double.Parse(e.Amount.Trim().Trim('₺')), IsIncome = e.Color == Green })
.OrderBy(e => e.Date)
var graphVals = (await _operationItemsRepo.GetAllAsync(
expression: e => e.Date > DateTime.Now.AddDays(-days),
ordered: e => e.Date.Date))
.Select(e => new OperationGraphVM { Date = e.Date.Date, Amount = e.Amount, IsIncome = e.Color == nameof(Green) })
.ToList();

var strokeThickness = 6;
Expand Down
Loading

0 comments on commit f1fff1e

Please sign in to comment.