This commit is contained in:
2023-12-16 21:18:01 +02:00
parent 775146ee86
commit 2feaf50802
46 changed files with 641 additions and 429 deletions
@@ -1,27 +1,22 @@
namespace MyOffice.Web.Models.Currency
/// <see cref="MyOffice.Data.Models.Currencies.CurrencyGlobal"/>
/// <see cref="MyOffice.Services.Currency.Domain.CurrencyGlobalDto"/>
namespace MyOffice.Web.Models.Currency;
using AutoMapper;
using MyOffice.Services.Currency.Domain;
public class CurrencyGlobalViewModel
{
using Data.Models.Currencies;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
public class CurrencyGlobalViewModel
{
public string Id { get; set; } = null!;
public string Name { get; set; } = null!;
public int Quantity { get; set; }
public string Symbol { get; set; } = null!;
}
public static class CurrencyGlobalViewModelExtensions
{
public static CurrencyGlobalViewModel ToModel(this CurrencyGlobal input)
{
return new CurrencyGlobalViewModel
{
Id = input.Id,
Name = input.Name,
Quantity = input.DefaultQuantity,
Symbol = input.Symbol,
};
}
}
public string Id { get; set; } = null!;
public string Name { get; set; } = null!;
public int Quantity { get; set; }
public string Symbol { get; set; } = null!;
}
public class CurrencyGlobalViewModelProfile : Profile
{
public CurrencyGlobalViewModelProfile()
{
CreateMap<CurrencyGlobalDto, CurrencyGlobalViewModel>();
}
}
@@ -1,9 +1,20 @@
namespace MyOffice.Web.Models.Currency;
using AutoMapper;
using MyOffice.Services.Currency.Domain;
public class CurrencyRateViewModel: BaseViewModel
{
public string Currency { get; set; } = null!;
public DateTime DateTime { get; set; }
public int Quantity { get; set; }
public decimal Rate { get; set; }
}
public class CurrencyRateViewModelProfile: Profile
{
public CurrencyRateViewModelProfile()
{
CreateMap<CurrencyRateDto, CurrencyRateViewModel>();
}
}
@@ -1,5 +1,8 @@
namespace MyOffice.Web.Models.Currency;
using AutoMapper;
using MyOffice.Services.Currency.Domain;
public class CurrencyViewModel: BaseViewModel
{
public string Id { get; set; } = null!;
@@ -11,4 +14,23 @@ public class CurrencyViewModel: BaseViewModel
public int? Quantity { get; set; }
public DateTime? RateDate { get; set; }
public bool IsPrimary { get; set; }
}
public class CurrencyViewModelProfile: Profile
{
public CurrencyViewModelProfile()
{
CreateMap<CurrencyDto, CurrencyViewModel>();
CreateMap<CurrencyWithRateDto, CurrencyViewModel>()
.ForMember(x => x.Id, o => o.MapFrom(x => x.Currency.Id))
.ForMember(x => x.Code, o => o.MapFrom(x => x.Currency.CurrencyGlobalId))
.ForMember(x => x.Name, o => o.MapFrom(x => x.Currency.Name))
.ForMember(x => x.ShortName, o => o.MapFrom(x => x.Currency.ShortName))
.ForMember(x => x.Rate, o => o.MapFrom(x => x.Rate == null ? (decimal?)null : x.Rate.Rate))
.ForMember(x => x.IsPrimary, o => o.MapFrom(x => x.Currency.IsPrimary))
.ForMember(x => x.Quantity, o => o.MapFrom(x => x.Rate == null ? (int?)null : x.Rate.Quantity))
.ForMember(x => x.RateDate, o => o.MapFrom(x => x.Rate == null ? (DateTime?)null : x.Rate.DateTime))
;
}
}