refactoring
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
namespace MyOffice.Web.Models.Item
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using MyOffice.Core.Extensions;
|
||||
using MyOffice.Data.Models.Items;
|
||||
|
||||
public class ItemCategoryViewModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string? Name { get; set; }
|
||||
|
||||
public bool AllowDelete { get; set; }
|
||||
public int SortOrder { 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,
|
||||
SortOrder = input.Id == input.UserId ? 1 : 0
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user