This commit is contained in:
2023-07-20 21:38:05 +03:00
parent 4bac59f322
commit 2f108bef4f
35 changed files with 1863 additions and 909 deletions
@@ -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,
};
}
}
}
+9 -6
View File
@@ -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(),
};
}
}
+2 -2
View File
@@ -5,7 +5,7 @@ using MyOffice.Services.Account.Domain;
public class MotionRequest
{
public DateTime Date { get; set; }
public string Motion { get; set; } = null!;
public string Item { get; set; } = null!;
public string? Description { get; set; }
public decimal? Plus { get; set; }
public decimal? Minus { get; set; }
@@ -18,7 +18,7 @@ public static class MotionRequestExtension
return new MotionAddUpdate
{
Date = input.Date,
Motion = input.Motion,
Item = input.Item,
Minus = input.Minus ?? 0,
Plus = input.Plus ?? 0,
Description = input.Description,
@@ -7,7 +7,7 @@
{
public string Id { get; set; } = null!;
public DateTime Date { get; set; }
public string Motion { get; set; } = null!;
public string Item { get; set; } = null!;
public string? Description { get; set; }
public decimal Plus { get; set; }
public decimal Minus { get; set; }
@@ -21,7 +21,7 @@
{
Id = input.Id.ToShort(),
Date = input.DateTime,
Motion = input.Item.ItemGlobal.Name,
Item = input.Item.ItemGlobal.Name,
Description = input.Description,
Plus = input.AmountPlus,
Minus = input.AmountMinus,