This commit is contained in:
2023-07-31 08:50:05 +03:00
parent cca943f37d
commit c5d9ae7b93
49 changed files with 546 additions and 398 deletions
@@ -1,22 +1,7 @@
namespace MyOffice.Web.Models.Account;
using Data.Models.Accounts;
using Services.Account.Domain;
public class AccountDetailedViewModel
public class AccountDetailedViewModel: BaseViewModel
{
public AccountViewModel Account { get; set; } = null!;
public decimal Rest { get; set; }
}
/*public static class AccountDetailedViewModelExtensions
{
public static AccountDetailedViewModel ToModel(this AccountDetailedDto input)
{
return new AccountDetailedViewModel
{
Account = input.Account.ToModel(),
Rest = input.Rest,
};
}
}*/
@@ -1,7 +1,12 @@
namespace MyOffice.Web.Models.Account;
using AutoMapper;
using MyOffice.Services.Currency.Domain;
using MyOffice.Services.Identity;
using Currency;
using Item;
using Motion;
using Services.Account.Domain;
using User;
@@ -67,5 +72,35 @@ public class AccountViewModelProfile : Profile
CreateMap<AccountAccessInviteDto, AccountAccessInviteViewModel>()
.ForMember(x => x.AllowWrite, o => o.MapFrom(x => x.IsAllowWrite))
;
CreateMap<MotionDto, MotionViewModel>()
;
CreateMap<ItemDto, ItemViewModel>()
.ForMember(x => x.Category, o => o.MapFrom(x => x.Category!.Name))
;
CreateMap<ItemCategoryDto, ItemCategoryViewModel>()
.ForMember(x => x.Internal, o => o.MapFrom(x => x.IsInternal))
.ForMember(x => x.AllowDelete, o => o.MapFrom(x => !x.Items.Any() && x.Id != x.UserId))
.ForMember(x => x.SortOrder, o => o.MapFrom(x => x.Id == x.UserId ? 1 : 0))
;
CreateMap<CurrencyGlobalDto, CurrencyGlobalViewModel>();
CreateMap<CurrencyDto, CurrencyViewModel>();
CreateMap<CurrencyRateDto, CurrencyRateViewModel>();
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))
;
}
}
@@ -2,7 +2,7 @@
{
using System.ComponentModel.DataAnnotations;
public class MotionsGetModel
public class MotionsGetRequest
{
[Required]
public DateTime From { get; set; }
+6
View File
@@ -0,0 +1,6 @@
namespace MyOffice.Web.Models;
public class BaseViewModel : IResponseModel
{
}
@@ -0,0 +1,9 @@
namespace MyOffice.Web.Models.Currency;
public class CurrencyRateViewModel: BaseViewModel
{
public string Currency { get; set; }
public DateTime DateTime { get; set; }
public int Quantity { get; set; }
public decimal Rate { get; set; }
}
@@ -1,38 +1,14 @@
namespace MyOffice.Web.Models.Currency
namespace MyOffice.Web.Models.Currency;
public class CurrencyViewModel: BaseViewModel
{
using Core.Extensions;
using Data.Models.Currencies;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
public class CurrencyViewModel
{
public string Id { get; set; } = null!;
public string Code { get; set; } = null!;
public string Symbol { get; set; } = null!;
public string Name { get; set; } = null!;
public string ShortName { get; set; } = null!;
public decimal? Rate { get; set; }
public int? Quantity { get; set; }
public DateTime? RateDate { get; set; }
public bool IsPrimary { get; set; }
}
public static class CurrencyViewModelExtensions
{
public static CurrencyViewModel ToModel(this Currency input, CurrencyRate? rate = null)
{
return new CurrencyViewModel
{
Id = input.Id.ToShort(),
Code = input.CurrencyGlobal!.Id,
Symbol = input.CurrencyGlobal!.Symbol,
Name = input.Name,
ShortName = input.ShortName,
Quantity = input.CurrentRate?.Quantity ?? rate?.Quantity,
Rate = input.CurrentRate?.Rate ?? rate?.Rate,
RateDate = input.CurrentRate?.DateTime ?? rate?.DateTime,
IsPrimary = input.IsPrimary,
};
}
}
}
public string Id { get; set; } = null!;
public string Code { get; set; } = null!;
public string Symbol { get; set; } = null!;
public string Name { get; set; } = null!;
public string ShortName { get; set; } = null!;
public decimal? Rate { get; set; }
public int? Quantity { get; set; }
public DateTime? RateDate { get; set; }
public bool IsPrimary { get; set; }
}
+5
View File
@@ -0,0 +1,5 @@
namespace MyOffice.Web.Models;
public interface IRequestModel
{
}
+5
View File
@@ -0,0 +1,5 @@
namespace MyOffice.Web.Models;
public interface IResponseModel
{
}
@@ -1,9 +1,7 @@
namespace MyOffice.Web.Models.Item
{
using System.ComponentModel.DataAnnotations;
using MyOffice.Core.Extensions;
using MyOffice.Data.Models.Items;
using MyOffice.Migrations.Postgres.Migrations;
using Services.Account.Domain;
public class ItemCategoryViewModel
{
@@ -14,32 +12,20 @@
public bool AllowDelete { get; set; }
public int SortOrder { get; set; }
public bool IsInternal { get; set; }
public bool Internal { get; set; }
}
public static class ItemCategoryViewModelExtensions
{
public static ItemCategoryViewModel ToModel(this ItemCategory input)
{
return new ItemCategoryViewModel
{
Id = input.Id.ToShort(),
Name = input.Name,
AllowDelete = !input.Items.Any() && input.Id != input.UserId,
IsInternal = input.IsInternal,
SortOrder = input.Id == input.UserId ? 1 : 0
};
}
public static ItemCategory FromModel(this ItemCategoryViewModel input)
public static ItemCategoryDto FromModel(this ItemCategoryViewModel input)
{
if (input == null)
throw new ArgumentNullException(nameof(input));
return new ItemCategory
return new ItemCategoryDto
{
Name = input.Name,
IsInternal = input.IsInternal,
IsInternal = input.Internal,
};
}
}
+12 -31
View File
@@ -1,36 +1,17 @@
namespace MyOffice.Web.Models.Item
namespace MyOffice.Web.Models.Item;
using System.ComponentModel.DataAnnotations;
public class ItemViewModel : BaseViewModel
{
using System.ComponentModel.DataAnnotations;
using Data.Models.Accounts;
using MyOffice.Core.Extensions;
using MyOffice.Data.Models.Items;
public string? Id { get; set; }
[Required]
public string? Name { get; set; }
public class ItemViewModel
{
public string? Id { get; set; }
public bool AllowDelete { get; set; }
public string CategoryId { get; set; } = null!;
public string? Category { get; set; } = null!;
[Required]
public string? Name { get; set; }
public string CategoryId { get; set; } = null!;
public string? Category { get; set; } = null!;
public bool AllowDelete { get; set; }
public string? AccountId { get; set; }
}
public static class ItemViewModelExtensions
{
public static ItemViewModel ToModel(this Item input, Account? account = null)
{
return new ItemViewModel
{
Id = input.ItemGlobal.Id.ToShort(),
CategoryId = input.CategoryId.ToShort(),
Category = input.Category?.Name,
Name = input.ItemGlobal.Name,
AllowDelete = input.Motions != null && !input.Motions.Any(),
AccountId = account?.Id.ToShort(),
};
}
}
public string? AccountId { get; set; }
}
+1 -20
View File
@@ -1,9 +1,6 @@
namespace MyOffice.Web.Models.Motion
{
using Core.Extensions;
using Data.Models.Accounts;
public class MotionViewModel
public class MotionViewModel: BaseViewModel
{
public string Id { get; set; } = null!;
public DateTime Date { get; set; }
@@ -13,20 +10,4 @@
public decimal Plus { get; set; }
public decimal Minus { get; set; }
}
public static class MotionViewModelExtensions
{
public static MotionViewModel ToModel(this Motion input)
{
return new MotionViewModel
{
Id = input.Id.ToShort(),
Date = input.DateTime,
Item = input.Item.ItemGlobal.Name,
Description = input.Description,
Plus = input.AmountPlus,
Minus = input.AmountMinus,
};
}
}
}
@@ -1,4 +1,4 @@
namespace MyOffice.Web.Models.Account;
namespace MyOffice.Web.Models;
using AutoMapper;
using Core.Extensions;