Files
myoffice/MyOffice.Web/Models/Account/AccountViewModel.cs
T
2023-06-22 10:01:27 +03:00

46 lines
1.0 KiB
C#

namespace MyOffice.Web.Models.Account
{
using System.ComponentModel.DataAnnotations;
using Core.Extensions;
using Data.Models.Accounts;
public class AccountViewModel
{
public string? Id { get; set; }
[Required]
public string Name { get; set; } = null!;
[Required]
public string CurrencyId { get; set; } = null!;
public string? CurrencyName { get; set; }
public List<AccountCategoryViewModel>? Categories { get; set; }
[Required]
public string CategoryId { get; set; } = null!;
public List<AccessRightsViewModel>? AccessRights { get; set; }
}
public static class AccountViewModelExtensions
{
public static AccountViewModel ToModel(this Account input)
{
return new AccountViewModel
{
Id = input.Id.ToShort(),
Name = input.Name,
CurrencyId = input.CurrencyGlobalId,
CurrencyName = input.CurrencyGlobal!.Name,
Categories = input.Categories!
.Select(x => x.Category!.ToModel())
.ToList(),
AccessRights = input.AccessRights!
.Select(x => x.ToModel())
.ToList(),
};
}
}
}