fix
This commit is contained in:
@@ -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))
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
namespace MyOffice.Web.Models.Item;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AutoMapper;
|
||||
using MyOffice.Services.Account.Domain;
|
||||
|
||||
public class ItemViewModel : BaseViewModel
|
||||
{
|
||||
@@ -15,3 +17,13 @@ public class ItemViewModel : BaseViewModel
|
||||
|
||||
public string? AccountId { get; set; }
|
||||
}
|
||||
|
||||
public class ItemViewModelProfile: Profile
|
||||
{
|
||||
public ItemViewModelProfile()
|
||||
{
|
||||
CreateMap<ItemDto, ItemViewModel>()
|
||||
.ForMember(x => x.Category, o => o.MapFrom(x => x.Category!.Name))
|
||||
;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user