update
This commit is contained in:
@@ -3,16 +3,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using MyOffice.Core.Extensions;
|
||||
using MyOffice.Data.Models.Items;
|
||||
using MyOffice.Migrations.Postgres.Migrations;
|
||||
|
||||
public class ItemCategoryViewModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public bool AllowDelete { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public bool IsInternal { get; set; }
|
||||
}
|
||||
|
||||
public static class ItemCategoryViewModelExtensions
|
||||
@@ -24,8 +26,21 @@
|
||||
Id = input.Id.ToShort(),
|
||||
Name = input.Name,
|
||||
AllowDelete = !input.Items.Any() && input.Id != input.UserId,
|
||||
IsInternal = input.IsInternal,
|
||||
SortOrder = input.Id == input.UserId ? 1 : 0
|
||||
};
|
||||
}
|
||||
|
||||
public static ItemCategory FromModel(this ItemCategoryViewModel input)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
|
||||
return new ItemCategory
|
||||
{
|
||||
Name = input.Name,
|
||||
IsInternal = input.IsInternal,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace MyOffice.Web.Models.Item
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Data.Models.Accounts;
|
||||
using MyOffice.Core.Extensions;
|
||||
using MyOffice.Data.Models.Items;
|
||||
|
||||
@@ -9,24 +10,26 @@
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string CategoryId { get; set; } = null!;
|
||||
public string Category { get; set; } = null!;
|
||||
public string? Category { get; set; } = null!;
|
||||
[Required]
|
||||
public string? Name { get; set; }
|
||||
|
||||
public bool AllowDelete { get; set; }
|
||||
public string? AccountId { get; set; }
|
||||
}
|
||||
|
||||
public static class ItemViewModelExtensions
|
||||
{
|
||||
public static ItemViewModel ToModel(this Item input)
|
||||
public static ItemViewModel ToModel(this Item input, Account? account = null)
|
||||
{
|
||||
return new ItemViewModel
|
||||
{
|
||||
Id = input.ItemGlobalId.ToShort(),
|
||||
CategoryId = input.Category.Id.ToShort(),
|
||||
Category = input.Category.Name,
|
||||
Id = input.ItemGlobal.Id.ToShort(),
|
||||
CategoryId = input.CategoryId.ToShort(),
|
||||
Category = input.Category?.Name,
|
||||
Name = input.ItemGlobal.Name,
|
||||
AllowDelete = !input.Motions.Any(),
|
||||
AllowDelete = input.Motions != null && !input.Motions.Any(),
|
||||
AccountId = account?.Id.ToShort(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user