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,32 +1,45 @@
namespace MyOffice.Web.Models.Item
namespace MyOffice.Web.Models.Item;
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using Services.Account.Domain;
public class ItemCategoryViewModel
{
using System.ComponentModel.DataAnnotations;
using Services.Account.Domain;
public string? Id { get; set; }
public class ItemCategoryViewModel
[Required]
public string Name { get; set; } = null!;
public bool AllowDelete { get; set; }
public int SortOrder { get; set; }
public bool Internal { get; set; }
}
//TODO: REMOVE
public static class ItemCategoryViewModelExtensions
{
public static ItemCategoryDto FromModel(this ItemCategoryViewModel input)
{
public string? Id { get; set; }
if (input == null)
throw new ArgumentNullException(nameof(input));
[Required]
public string Name { get; set; } = null!;
public bool AllowDelete { get; set; }
public int SortOrder { get; set; }
public bool Internal { get; set; }
}
public static class ItemCategoryViewModelExtensions
{
public static ItemCategoryDto FromModel(this ItemCategoryViewModel input)
return new ItemCategoryDto
{
if (input == null)
throw new ArgumentNullException(nameof(input));
return new ItemCategoryDto
{
Name = input.Name,
IsInternal = input.Internal,
};
}
Name = input.Name,
IsInternal = input.Internal,
};
}
}
public class ItemCategoryViewModelProfile: Profile
{
public ItemCategoryViewModelProfile()
{
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))
;
}
}