diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CostItemLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CostItemLogic.cs index 4addd9e..f0375d8 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CostItemLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CostItemLogic.cs @@ -95,7 +95,11 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic if (string.IsNullOrEmpty(model.Name)) { throw new ArgumentNullException("Отсутствует название статьи затрат", nameof(model.Price)); } - _logger.LogInformation($"CostItem. ID:{model.ID}.EmployeeID:{model.EmployeeID}.Name:{model.Name}.Price:{model.Price}"); + if (model.CostNum <= 0) { + throw new ArgumentOutOfRangeException("Номер счета должен идти от 1"); + } + _logger.LogInformation($"CostItem. ID:{model.ID}.EmployeeID:{model.EmployeeID}.Name:{model.Name}.Price:{model.Price}" + + $"CostNum:{model.CostNum}"); var element = _storage.GetElement(new CostItemSearchModel { ID = model.ID }); if (element != null && element.ID != model.EmployeeID) { diff --git a/ElectronicsShop/ElectronicsShopContracts/BindingModels/CostItemBindingModel.cs b/ElectronicsShop/ElectronicsShopContracts/BindingModels/CostItemBindingModel.cs index 44b4d45..eefa6c4 100644 --- a/ElectronicsShop/ElectronicsShopContracts/BindingModels/CostItemBindingModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/BindingModels/CostItemBindingModel.cs @@ -14,5 +14,7 @@ namespace ElectronicsShopContracts.BindingModels { public string Name { get; set; } = string.Empty; public double Price { get; set; } + + public int CostNum { get; set; } } } diff --git a/ElectronicsShop/ElectronicsShopContracts/SearchModels/CostItemSearchModel.cs b/ElectronicsShop/ElectronicsShopContracts/SearchModels/CostItemSearchModel.cs index 8197a35..ba55a1a 100644 --- a/ElectronicsShop/ElectronicsShopContracts/SearchModels/CostItemSearchModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/SearchModels/CostItemSearchModel.cs @@ -8,5 +8,6 @@ namespace ElectronicsShopContracts.SearchModels { public class CostItemSearchModel { public int? ID { get; set; } public string? Name { get; set; } + public int? CostNum { get; set; } } } diff --git a/ElectronicsShop/ElectronicsShopContracts/ViewModels/CostItemViewModel.cs b/ElectronicsShop/ElectronicsShopContracts/ViewModels/CostItemViewModel.cs index b8b52d7..2388648 100644 --- a/ElectronicsShop/ElectronicsShopContracts/ViewModels/CostItemViewModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/ViewModels/CostItemViewModel.cs @@ -18,5 +18,8 @@ namespace ElectronicsShopContracts.ViewModels { [DisplayName("Затраты")] public double Price { get; set; } + + [DisplayName("Номер счета")] + public int CostNum { get; set; } } } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs index b04932d..d5a8b5d 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs @@ -10,7 +10,7 @@ namespace ElectronicsShopDataBaseImplement optionsBuilder) { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase11;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-O0N00SH\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.Designer.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527175902_InitMigration.Designer.cs similarity index 98% rename from ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.Designer.cs rename to ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527175902_InitMigration.Designer.cs index a6a4844..7214802 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.Designer.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527175902_InitMigration.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ElectronicsShopDataBaseImplement.Migrations { [DbContext(typeof(Database))] - [Migration("20240527144429_test")] - partial class test + [Migration("20240527175902_InitMigration")] + partial class InitMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -58,6 +58,9 @@ namespace ElectronicsShopDataBaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + b.Property("CostNum") + .HasColumnType("int"); + b.Property("EmployeeID") .HasColumnType("int"); diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527175902_InitMigration.cs similarity index 98% rename from ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.cs rename to ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527175902_InitMigration.cs index 161dfc1..d23eb50 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527175902_InitMigration.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace ElectronicsShopDataBaseImplement.Migrations { /// - public partial class test : Migration + public partial class InitMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -34,7 +34,8 @@ namespace ElectronicsShopDataBaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), EmployeeID = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false) + Price = table.Column(type: "float", nullable: false), + CostNum = table.Column(type: "int", nullable: false) }, constraints: table => { diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs index 44aa1c4..fbdc60c 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs @@ -55,6 +55,9 @@ namespace ElectronicsShopDataBaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + b.Property("CostNum") + .HasColumnType("int"); + b.Property("EmployeeID") .HasColumnType("int"); diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs index a992d97..af4193e 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs @@ -24,7 +24,10 @@ namespace ElectronicsShopDataBaseImplement.Models [Required] public double Price { get; set; } - public static CostItem? Create(CostItemBindingModel? model) + [Required] + public int CostNum { get; set; } + + public static CostItem? Create(CostItemBindingModel? model) { if (model == null) { @@ -36,6 +39,7 @@ namespace ElectronicsShopDataBaseImplement.Models EmployeeID = model.EmployeeID, Name = model.Name, Price = model.Price, + CostNum = model.CostNum, }; } public void Update(CostItemBindingModel? model) @@ -47,6 +51,7 @@ namespace ElectronicsShopDataBaseImplement.Models EmployeeID = model.EmployeeID; Name = model.Name; Price = model.Price; + CostNum = model.CostNum; } public CostItemViewModel GetViewModel => new() @@ -55,7 +60,7 @@ namespace ElectronicsShopDataBaseImplement.Models EmployeeID = EmployeeID, Name = Name, Price = Price, + CostNum = CostNum, }; - - } + } } diff --git a/ElectronicsShop/ElectronicsShopDataModels/Models/ICostItemModel.cs b/ElectronicsShop/ElectronicsShopDataModels/Models/ICostItemModel.cs index 5591102..4de8b5f 100644 --- a/ElectronicsShop/ElectronicsShopDataModels/Models/ICostItemModel.cs +++ b/ElectronicsShop/ElectronicsShopDataModels/Models/ICostItemModel.cs @@ -9,5 +9,6 @@ namespace ElectronicsShopDataModels.Models { int EmployeeID { get; } string Name { get; } double Price { get; } + int CostNum { get; } } } diff --git a/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs index 9b484d2..7bb35c6 100644 --- a/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs @@ -89,6 +89,27 @@ namespace ElectronicsShopEmployeeApp.Controllers { return; } + [HttpGet] + public IActionResult CreateCostItem() { + return View(); + } + + [HttpPost] + public void CreateCostItem(string name, double price, int costNum) { + if (APIEmployee.Employee == null) { + throw new Exception(" "); + } + if (price <= 0) { + throw new Exception(" 0"); + } + APIEmployee.PostRequest("api/main/createcostitem", new CostItemBindingModel { + EmployeeID = APIEmployee.Employee.ID, + Name = name, + Price = price, + CostNum = costNum + }); + } + [HttpGet] public IActionResult Create() { ViewBag.Orders = APIEmployee.GetRequset>("api/main/getproductlist"); @@ -96,7 +117,7 @@ namespace ElectronicsShopEmployeeApp.Controllers { } [HttpPost] - public void Create(int price, int costItem, string productName) { + public void Create(int price, int costNum, string productName) { if (APIEmployee.Employee == null) { throw new Exception(" "); } @@ -104,9 +125,9 @@ namespace ElectronicsShopEmployeeApp.Controllers { throw new Exception(" 0"); } APIEmployee.PostRequest("api/main/createproduct", new ProductBindingModel { - CostItemID = costItem, + CostItemID = costNum, ProductName = productName, - Price = Calc(price, costItem) + Price = Calc(price, costNum) }); Response.Redirect("Index"); } diff --git a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/CreateCostItem.cshtml b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/CreateCostItem.cshtml new file mode 100644 index 0000000..d9d921c --- /dev/null +++ b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/CreateCostItem.cshtml @@ -0,0 +1,47 @@ +@{ + ViewData["Title"] = "CreateCostItem"; +} + +
+

Создание статьи затрат

+
+
+
+
Название статьи затрат:
+
+ +
+
+
+
Номер счета:
+
+ +
+
+
+
Затраты:
+
+ +
+
+
+
+
+ +
+
+ +
+ + \ No newline at end of file diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs index 7fa5473..0548887 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs @@ -14,11 +14,14 @@ namespace ElectronicsShopRestAPI.Controllers { private readonly ILogger _logger; private readonly IProductLogic _product; private readonly IOrderLogic _order; + private readonly ICostItemLogic _costItem; - public MainController(ILogger logger, IProductLogic product, IOrderLogic orderLogic) { + public MainController(ILogger logger, IProductLogic product, + IOrderLogic orderLogic, ICostItemLogic costItemLogic) { _logger = logger; _product = product; _order = orderLogic; + _costItem = costItemLogic; } [HttpGet] @@ -72,6 +75,17 @@ namespace ElectronicsShopRestAPI.Controllers { return; } - //Мейби нужны будут удаления, обновления, выбор конкретного заказа или продукта. Короче потом.... + [HttpPost] + public void CreateCostItem(CostItemBindingModel model) { + try { + _costItem.Create(model); + } + catch (Exception ex) { + _logger.LogError(ex, "Ошибка создания заказа"); + throw; + } + } + //Мейби нужны будут удаления, обновления, выбор конкретного заказа или продукта. Короче потом... + //А также для статей затрат. } } diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Program.cs b/ElectronicsShop/ElectronicsShopRestAPI/Program.cs index 831a84b..1b0f4c2 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Program.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Program.cs @@ -14,11 +14,13 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle