namespace MyOffice.Web.Models.Item; using System.ComponentModel.DataAnnotations; using AutoMapper; using Services.Account.Domain; public class ItemCategoryViewModel: IResponseModel { public string? Id { get; set; } [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) { if (input == null) throw new ArgumentNullException(nameof(input)); return new ItemCategoryDto { Name = input.Name, IsInternal = input.Internal, }; } } public class ItemCategoryViewModelProfile: Profile { public ItemCategoryViewModelProfile() { CreateMap() .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)) ; } }