From 82cc504aba2c0be993323d16e572beb7c54c0182 Mon Sep 17 00:00:00 2001 From: kirin Date: Sat, 4 May 2024 03:05:06 +0400 Subject: [PATCH] many to many fixed. rest api done --- AutoCenter/AutoCenter.sln | 12 ++- .../BindingModels/CarBindingModel.cs | 3 +- .../BindingModels/EquipmentBindingModel.cs | 1 + .../BindingModels/PurchaseBindingModel.cs | 3 + .../ViewModels/CarViewModel.cs | 2 + .../ViewModels/PurchaseViewModel.cs | 3 + .../AutoCenterDataModels/Models/ICarModel.cs | 3 +- .../Models/IEquipmentModel.cs | 3 +- .../Models/IPurchaseModel.cs | 2 + .../Implements/CarBrandStorage.cs | 8 +- .../Implements/CarStorage.cs | 17 ++-- .../Implements/EquipmentStorage.cs | 8 +- .../Implements/PresellingWorkStorage.cs | 8 +- .../Implements/PurchaseStorage.cs | 18 +++- .../Implements/ShopStorage.cs | 8 +- .../Implements/UserStorage.cs | 8 +- .../Implements/WishStorage.cs | 11 ++- ...ner.cs => 20240503230402_Init.Designer.cs} | 2 +- ...1151957_Init.cs => 20240503230402_Init.cs} | 4 +- .../AutoCenterDatabaseImplement/Models/Car.cs | 43 ++++++--- .../Models/Equipment.cs | 8 +- .../Models/Purchase.cs | 60 +++++++++++- .../AutoCenterRestApi.csproj | 20 ++++ .../Controllers/CarBrandController.cs | 93 ++++++++++++++++++ .../Controllers/CarController.cs | 94 ++++++++++++++++++ .../Controllers/EquipmentController.cs | 94 ++++++++++++++++++ .../Controllers/PreSellingWorkController.cs | 95 +++++++++++++++++++ .../Controllers/PurchaseController.cs | 94 ++++++++++++++++++ .../Controllers/ShopController.cs | 93 ++++++++++++++++++ .../Controllers/UserController.cs | 69 ++++++++++++++ .../Controllers/WishController.cs | 94 ++++++++++++++++++ AutoCenter/AutoCenterRestApi/Program.cs | 56 +++++++++++ .../Properties/launchSettings.json | 31 ++++++ .../appsettings.Development.json | 8 ++ AutoCenter/AutoCenterRestApi/appsettings.json | 9 ++ AutoCenter/AutoCenterRestApi/log4net.config | 16 ++++ 36 files changed, 1040 insertions(+), 61 deletions(-) rename AutoCenter/AutoCenterDatabaseImplement/Migrations/{20240501151957_Init.Designer.cs => 20240503230402_Init.Designer.cs} (99%) rename AutoCenter/AutoCenterDatabaseImplement/Migrations/{20240501151957_Init.cs => 20240503230402_Init.cs} (99%) create mode 100644 AutoCenter/AutoCenterRestApi/AutoCenterRestApi.csproj create mode 100644 AutoCenter/AutoCenterRestApi/Controllers/CarBrandController.cs create mode 100644 AutoCenter/AutoCenterRestApi/Controllers/CarController.cs create mode 100644 AutoCenter/AutoCenterRestApi/Controllers/EquipmentController.cs create mode 100644 AutoCenter/AutoCenterRestApi/Controllers/PreSellingWorkController.cs create mode 100644 AutoCenter/AutoCenterRestApi/Controllers/PurchaseController.cs create mode 100644 AutoCenter/AutoCenterRestApi/Controllers/ShopController.cs create mode 100644 AutoCenter/AutoCenterRestApi/Controllers/UserController.cs create mode 100644 AutoCenter/AutoCenterRestApi/Controllers/WishController.cs create mode 100644 AutoCenter/AutoCenterRestApi/Program.cs create mode 100644 AutoCenter/AutoCenterRestApi/Properties/launchSettings.json create mode 100644 AutoCenter/AutoCenterRestApi/appsettings.Development.json create mode 100644 AutoCenter/AutoCenterRestApi/appsettings.json create mode 100644 AutoCenter/AutoCenterRestApi/log4net.config diff --git a/AutoCenter/AutoCenter.sln b/AutoCenter/AutoCenter.sln index 036b161..11a8fc9 100644 --- a/AutoCenter/AutoCenter.sln +++ b/AutoCenter/AutoCenter.sln @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoCenterContracts", "Auto EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoCenterDatabaseImplement", "AutoCenterDatabaseImplement\AutoCenterDatabaseImplement.csproj", "{617B8C58-1F96-44A5-9EE6-A78EA441CA66}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoCenterBusinessLogic", "AutoCenterBusinessLogic\AutoCenterBusinessLogic.csproj", "{617B8C58-1F96-44A5-9EE6-A78EA441CA66}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoCenterBusinessLogic", "AutoCenterBusinessLogic\AutoCenterBusinessLogic.csproj", "{FFB35620-52C9-46A7-8607-E1CA5A70D80A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoCenterRestApi", "AutoCenterRestApi\AutoCenterRestApi.csproj", "{2FE0682F-5405-4548-99E5-8AB155DF50E0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -29,6 +31,14 @@ Global {617B8C58-1F96-44A5-9EE6-A78EA441CA66}.Debug|Any CPU.Build.0 = Debug|Any CPU {617B8C58-1F96-44A5-9EE6-A78EA441CA66}.Release|Any CPU.ActiveCfg = Release|Any CPU {617B8C58-1F96-44A5-9EE6-A78EA441CA66}.Release|Any CPU.Build.0 = Release|Any CPU + {FFB35620-52C9-46A7-8607-E1CA5A70D80A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FFB35620-52C9-46A7-8607-E1CA5A70D80A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FFB35620-52C9-46A7-8607-E1CA5A70D80A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FFB35620-52C9-46A7-8607-E1CA5A70D80A}.Release|Any CPU.Build.0 = Release|Any CPU + {2FE0682F-5405-4548-99E5-8AB155DF50E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2FE0682F-5405-4548-99E5-8AB155DF50E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2FE0682F-5405-4548-99E5-8AB155DF50E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2FE0682F-5405-4548-99E5-8AB155DF50E0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AutoCenter/AutoCenterContracts/BindingModels/CarBindingModel.cs b/AutoCenter/AutoCenterContracts/BindingModels/CarBindingModel.cs index 7e7dfd0..59d23c5 100644 --- a/AutoCenter/AutoCenterContracts/BindingModels/CarBindingModel.cs +++ b/AutoCenter/AutoCenterContracts/BindingModels/CarBindingModel.cs @@ -11,6 +11,7 @@ namespace AutoCenterContracts.BindingModels { public int Id { get; set; } public string Name { get; set; } - public int BrandId { get; set; } + public int BrandId { get; set; } + public Dictionary CarEquipments { get; set; } = new(); } } diff --git a/AutoCenter/AutoCenterContracts/BindingModels/EquipmentBindingModel.cs b/AutoCenter/AutoCenterContracts/BindingModels/EquipmentBindingModel.cs index d7fe919..57fa790 100644 --- a/AutoCenter/AutoCenterContracts/BindingModels/EquipmentBindingModel.cs +++ b/AutoCenter/AutoCenterContracts/BindingModels/EquipmentBindingModel.cs @@ -12,5 +12,6 @@ namespace AutoCenterContracts.BindingModels public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } + } } diff --git a/AutoCenter/AutoCenterContracts/BindingModels/PurchaseBindingModel.cs b/AutoCenter/AutoCenterContracts/BindingModels/PurchaseBindingModel.cs index e52a619..08f02f6 100644 --- a/AutoCenter/AutoCenterContracts/BindingModels/PurchaseBindingModel.cs +++ b/AutoCenter/AutoCenterContracts/BindingModels/PurchaseBindingModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.ConstrainedExecution; using System.Text; using System.Threading.Tasks; using AutoCenterDataModels.Models; @@ -14,5 +15,7 @@ namespace AutoCenterContracts.BindingModels public int ShopId { get; set; } public int UserId { get; set; } public DateTime Date { get; set; } + public Dictionary PurchasePresellingWorks { get; } = new(); + public Dictionary PurchaseCars { get; } = new(); } } diff --git a/AutoCenter/AutoCenterContracts/ViewModels/CarViewModel.cs b/AutoCenter/AutoCenterContracts/ViewModels/CarViewModel.cs index 58d23e6..9fd3e75 100644 --- a/AutoCenter/AutoCenterContracts/ViewModels/CarViewModel.cs +++ b/AutoCenter/AutoCenterContracts/ViewModels/CarViewModel.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using AutoCenterDataModels.Models; namespace AutoCenterContracts.ViewModels { @@ -15,5 +16,6 @@ namespace AutoCenterContracts.ViewModels public string Name { get; set; } public int BrandId { get; set; } + public Dictionary CarEquipments { get; set; } = new(); } } diff --git a/AutoCenter/AutoCenterContracts/ViewModels/PurchaseViewModel.cs b/AutoCenter/AutoCenterContracts/ViewModels/PurchaseViewModel.cs index 19fccde..4ed4f70 100644 --- a/AutoCenter/AutoCenterContracts/ViewModels/PurchaseViewModel.cs +++ b/AutoCenter/AutoCenterContracts/ViewModels/PurchaseViewModel.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using AutoCenterDataModels.Models; namespace AutoCenterContracts.ViewModels { @@ -18,5 +19,7 @@ namespace AutoCenterContracts.ViewModels [DisplayName("Дата оплаты")] public DateTime Date { get; set; } + public Dictionary PurchasePresellingWorks { get; set; } = new(); + public Dictionary PurchaseCars { get; set; } = new(); } } diff --git a/AutoCenter/AutoCenterDataModels/Models/ICarModel.cs b/AutoCenter/AutoCenterDataModels/Models/ICarModel.cs index 9b763e7..9238551 100644 --- a/AutoCenter/AutoCenterDataModels/Models/ICarModel.cs +++ b/AutoCenter/AutoCenterDataModels/Models/ICarModel.cs @@ -6,9 +6,10 @@ using System.Threading.Tasks; namespace AutoCenterDataModels.Models { - public interface ICarModel + public interface ICarModel : IId { string Name { get; } int BrandId { get; } + Dictionary CarEquipments { get; } } } diff --git a/AutoCenter/AutoCenterDataModels/Models/IEquipmentModel.cs b/AutoCenter/AutoCenterDataModels/Models/IEquipmentModel.cs index 7cb0fc6..23eb4ce 100644 --- a/AutoCenter/AutoCenterDataModels/Models/IEquipmentModel.cs +++ b/AutoCenter/AutoCenterDataModels/Models/IEquipmentModel.cs @@ -1,12 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.ConstrainedExecution; using System.Text; using System.Threading.Tasks; namespace AutoCenterDataModels.Models { - public interface IEquipmentModel + public interface IEquipmentModel : IId { string Name { get; } string Description { get; } diff --git a/AutoCenter/AutoCenterDataModels/Models/IPurchaseModel.cs b/AutoCenter/AutoCenterDataModels/Models/IPurchaseModel.cs index 99ed598..1cedf47 100644 --- a/AutoCenter/AutoCenterDataModels/Models/IPurchaseModel.cs +++ b/AutoCenter/AutoCenterDataModels/Models/IPurchaseModel.cs @@ -12,5 +12,7 @@ namespace AutoCenterDataModels.Models int ShopId { get; } int UserId { get; } DateTime Date { get; } + Dictionary PurchasePresellingWorks { get; } + Dictionary PurchaseCars { get; } } } diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/CarBrandStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/CarBrandStorage.cs index 2d16cf3..a2e5a6a 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Implements/CarBrandStorage.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/CarBrandStorage.cs @@ -78,17 +78,17 @@ namespace AutoCenterDatabaseImplement.Implements { using var context = new AutoCenterDatabase(); - var CarBrand = context.CarBrands.FirstOrDefault(x => x.Id == model.Id); + var carBrand = context.CarBrands.FirstOrDefault(x => x.Id == model.Id); - if (CarBrand == null) + if (carBrand == null) { return null; } - CarBrand.Update(model); + carBrand.Update(model); context.SaveChanges(); - return CarBrand.GetViewModel; + return carBrand.GetViewModel; } } } diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/CarStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/CarStorage.cs index 4330c4a..04a10ca 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Implements/CarStorage.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/CarStorage.cs @@ -59,14 +59,15 @@ namespace AutoCenterDatabaseImplement.Implements } public CarViewModel? Insert(CarBindingModel model) { - var newCar = Car.Create(model); + using var context = new AutoCenterDatabase(); + var newCar = Car.Create(context, model); if (newCar == null) { return null; } - using var context = new AutoCenterDatabase(); + context.Cars.Add(newCar); context.SaveChanges(); @@ -77,17 +78,21 @@ namespace AutoCenterDatabaseImplement.Implements { using var context = new AutoCenterDatabase(); - var Car = context.Cars.FirstOrDefault(x => x.Id == model.Id); + var car = context.Cars.FirstOrDefault(x => x.Id == model.Id); - if (Car == null) + if (car == null) { return null; } - Car.Update(model); + car.Update(model); + if (model.CarEquipments != null) + { + car.UpdateEqiupment(context, model); + } context.SaveChanges(); - return Car.GetViewModel; + return car.GetViewModel; } } diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/EquipmentStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/EquipmentStorage.cs index b56b9c4..ae40248 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Implements/EquipmentStorage.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/EquipmentStorage.cs @@ -81,16 +81,16 @@ namespace AutoCenterDatabaseImplement.Implements using var context = new AutoCenterDatabase(); - var Equipment = context.Equipments.FirstOrDefault(x => x.Id == model.Id); - if (Equipment == null) + var equipment = context.Equipments.FirstOrDefault(x => x.Id == model.Id); + if (equipment == null) { return null; } - Equipment.Update(model); + equipment.Update(model); context.SaveChanges(); - return Equipment.GetViewModel; + return equipment.GetViewModel; } } diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/PresellingWorkStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/PresellingWorkStorage.cs index 6e2a094..b408a96 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Implements/PresellingWorkStorage.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/PresellingWorkStorage.cs @@ -82,15 +82,15 @@ namespace AutoCenterDatabaseImplement.Implements public PresellingWorkViewModel? Update(PresellingWorkBindingModel model) { using var context = new AutoCenterDatabase(); - var PresellingWork = context.PresellingWorks.FirstOrDefault(x => x.Id == model.Id); - if (PresellingWork == null) + var presellingWork = context.PresellingWorks.FirstOrDefault(x => x.Id == model.Id); + if (presellingWork == null) { return null; } - PresellingWork.Update(model); + presellingWork.Update(model); context.SaveChanges(); - return PresellingWork.GetViewModel; + return presellingWork.GetViewModel; } } } diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/PurchaseStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/PurchaseStorage.cs index 202f5f7..f48a4c1 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Implements/PurchaseStorage.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/PurchaseStorage.cs @@ -61,7 +61,7 @@ namespace AutoCenterDatabaseImplement.Implements public PurchaseViewModel? Insert(PurchaseBindingModel model) { using var context = new AutoCenterDatabase(); - var newPurchase = Purchase.Create(model); + var newPurchase = Purchase.Create(context, model); if (newPurchase == null) { @@ -79,17 +79,25 @@ namespace AutoCenterDatabaseImplement.Implements { using var context = new AutoCenterDatabase(); - var Purchase = context.Purchases.FirstOrDefault(x => x.Id == model.Id); + var purchase = context.Purchases.FirstOrDefault(x => x.Id == model.Id); - if (Purchase == null) + if (purchase == null) { return null; } - Purchase.Update(model); + purchase.Update(model); + if (model.PurchasePresellingWorks != null) + { + purchase.UpdatePresellingWorks(context, model); + } + if (model.PurchaseCars != null) + { + purchase.UpdateCars(context, model); + } context.SaveChanges(); - return Purchase.GetViewModel; + return purchase.GetViewModel; } } } diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/ShopStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/ShopStorage.cs index 4f7c288..8dd800d 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Implements/ShopStorage.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/ShopStorage.cs @@ -75,17 +75,17 @@ namespace AutoCenterDatabaseImplement.Implements { using var context = new AutoCenterDatabase(); - var Shop = context.Shops.FirstOrDefault(x => x.Id == model.Id); + var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id); - if (Shop == null) + if (shop == null) { return null; } - Shop.Update(model); + shop.Update(model); context.SaveChanges(); - return Shop.GetViewModel; + return shop.GetViewModel; } } } diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/UserStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/UserStorage.cs index a5987a6..dbd4c45 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Implements/UserStorage.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/UserStorage.cs @@ -87,17 +87,17 @@ namespace AutoCenterDatabaseImplement.Implements { using var context = new AutoCenterDatabase(); - var User = context.Users.FirstOrDefault(x => x.Id == model.Id); + var user = context.Users.FirstOrDefault(x => x.Id == model.Id); - if (User == null) + if (user == null) { return null; } - User.Update(model); + user.Update(model); context.SaveChanges(); - return User.GetViewModel; + return user.GetViewModel; } } } diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/WishStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/WishStorage.cs index 1049d9f..a71cf38 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Implements/WishStorage.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/WishStorage.cs @@ -1,5 +1,6 @@ using AutoCenterContracts.BindingModels; using AutoCenterContracts.SearchModels; +using AutoCenterContracts.StoragesContracts; using AutoCenterContracts.ViewModels; using AutoCenterDatabaseImplement.Models; using Microsoft.EntityFrameworkCore; @@ -11,7 +12,7 @@ using System.Threading.Tasks; namespace AutoCenterDatabaseImplement.Implements { - public class WishStorage + public class WishStorage : IWishStorage { public WishViewModel? Delete(WishBindingModel model) { @@ -80,15 +81,15 @@ namespace AutoCenterDatabaseImplement.Implements public WishViewModel? Update(WishBindingModel model) { using var context = new AutoCenterDatabase(); - var Wish = context.Wishes.FirstOrDefault(x => x.Id == model.Id); - if (Wish == null) + var wish = context.Wishes.FirstOrDefault(x => x.Id == model.Id); + if (wish == null) { return null; } - Wish.Update(model); + wish.Update(model); context.SaveChanges(); - return Wish.GetViewModel; + return wish.GetViewModel; } } } diff --git a/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.Designer.cs b/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240503230402_Init.Designer.cs similarity index 99% rename from AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.Designer.cs rename to AutoCenter/AutoCenterDatabaseImplement/Migrations/20240503230402_Init.Designer.cs index eefe153..7edc129 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.Designer.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240503230402_Init.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace AutoCenterDatabaseImplement.Migrations { [DbContext(typeof(AutoCenterDatabase))] - [Migration("20240501151957_Init")] + [Migration("20240503230402_Init")] partial class Init { /// diff --git a/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.cs b/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240503230402_Init.cs similarity index 99% rename from AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.cs rename to AutoCenter/AutoCenterDatabaseImplement/Migrations/20240503230402_Init.cs index 3b6f788..0706ca1 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240503230402_Init.cs @@ -227,13 +227,13 @@ namespace AutoCenterDatabaseImplement.Migrations column: x => x.PresellingWorksId, principalTable: "PresellingWorks", principalColumn: "Id", - onDelete: ReferentialAction.Restrict); + onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_PresellingWorkPurchase_Purchases_PurchasesId", column: x => x.PurchasesId, principalTable: "Purchases", principalColumn: "Id", - onDelete: ReferentialAction.Restrict); + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( diff --git a/AutoCenter/AutoCenterDatabaseImplement/Models/Car.cs b/AutoCenter/AutoCenterDatabaseImplement/Models/Car.cs index 90a0cbf..d13ff9a 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Models/Car.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Models/Car.cs @@ -13,17 +13,31 @@ namespace AutoCenterDatabaseImplement.Models { public class Car : ICarModel { - public int Id { get; private set; } + public int Id { get; set; } [Required] - public string Name { get; private set; } = string.Empty; + public string Name { get; set; } = string.Empty; [Required] - public int BrandId { get; private set; } - public virtual CarBrand Brand { get; private set; } - public List Equipments { get; private set; } = new(); - public List Purchases { get; private set; } = new(); + public int BrandId { get; set; } + public virtual CarBrand Brand { get; set; } = new(); + public List Equipments { get; set; } = new(); + public List Purchases { get; set; } = new(); - public static Car? Create(CarBindingModel model) + private Dictionary? _equipments = null; + [NotMapped] + public Dictionary CarEquipments + { + get + { + if (_equipments == null) + { + _equipments = Equipments.ToDictionary(record => record.Id, record => (record as IEquipmentModel)); + } + return _equipments; + } + } + + public static Car? Create(AutoCenterDatabase context, CarBindingModel model) { if (model == null) { @@ -34,7 +48,10 @@ namespace AutoCenterDatabaseImplement.Models { Id = model.Id, Name = model.Name, - BrandId = model.BrandId + BrandId = model.BrandId, + Equipments = model.CarEquipments.Select(x => new Equipment { + Id = context.Equipments.First(y => y.Id == x.Key).Id + }).ToList(), }; } public void Update(CarBindingModel? model) @@ -48,15 +65,19 @@ namespace AutoCenterDatabaseImplement.Models BrandId = model.BrandId; } - public void UpdateEqiupment(AutoCenterDatabase context) + public void UpdateEqiupment(AutoCenterDatabase context, CarBindingModel model) { - + Equipments.Clear(); + foreach (var id in model.CarEquipments.Keys) { + Equipments.Add(context.Equipments.First(x => x.Id == id)); + } } public CarViewModel GetViewModel => new() { Id = Id, Name = Name, - BrandId = BrandId + BrandId = BrandId, + CarEquipments = CarEquipments }; } diff --git a/AutoCenter/AutoCenterDatabaseImplement/Models/Equipment.cs b/AutoCenter/AutoCenterDatabaseImplement/Models/Equipment.cs index 80606f3..9b42229 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Models/Equipment.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Models/Equipment.cs @@ -13,13 +13,13 @@ namespace AutoCenterDatabaseImplement.Models { public class Equipment: IEquipmentModel { - public int Id { get; private set; } + public int Id { get; set; } [Required] - public string Name { get; private set; } = string.Empty; + public string Name { get; set; } = string.Empty; [Required] - public string Description { get; private set; } = string.Empty; + public string Description { get; set; } = string.Empty; - public List Cars { get; private set; } = new(); + public List Cars { get; set; } = new(); public static Equipment? Create(EquipmentBindingModel model) { diff --git a/AutoCenter/AutoCenterDatabaseImplement/Models/Purchase.cs b/AutoCenter/AutoCenterDatabaseImplement/Models/Purchase.cs index 3414adb..169e380 100644 --- a/AutoCenter/AutoCenterDatabaseImplement/Models/Purchase.cs +++ b/AutoCenter/AutoCenterDatabaseImplement/Models/Purchase.cs @@ -25,8 +25,34 @@ namespace AutoCenterDatabaseImplement.Models public DateTime Date { get; set; } public List Cars { get; set; } = new(); + private Dictionary? _cars = null; + [NotMapped] + public Dictionary PurchaseCars + { + get + { + if (_cars == null) + { + _cars = Cars.ToDictionary(record => record.Id, record => (record as ICarModel)); + } + return _cars; + } + } public List PresellingWorks { get; set; } = new(); - public static Purchase? Create(PurchaseBindingModel model) + private Dictionary? _presellingWorks = null; + [NotMapped] + public Dictionary PurchasePresellingWorks + { + get + { + if (_presellingWorks == null) + { + _presellingWorks = PresellingWorks.ToDictionary(record => record.Id, record => (record as IPresellingWorkModel)); + } + return _presellingWorks; + } + } + public static Purchase? Create(AutoCenterDatabase context, PurchaseBindingModel model) { if (model == null) { @@ -39,7 +65,15 @@ namespace AutoCenterDatabaseImplement.Models IsCashPaid = model.IsCashPaid, ShopId = model.ShopId, UserId = model.UserId, - Date = model.Date + Date = model.Date, + Cars = model.PurchaseCars.Select(x => new Car + { + Id = context.Cars.First(y => y.Id == x.Key).Id + }).ToList(), + PresellingWorks = model.PurchasePresellingWorks.Select(x => new PresellingWork + { + Id = context.Equipments.First(y => y.Id == x.Key).Id + }).ToList() }; } @@ -56,13 +90,33 @@ namespace AutoCenterDatabaseImplement.Models Date = model.Date; } + public void UpdatePresellingWorks(AutoCenterDatabase context, PurchaseBindingModel? model) + { + PresellingWorks.Clear(); + foreach (var id in model.PurchasePresellingWorks.Keys) + { + PresellingWorks.Add(context.PresellingWorks.First(x => x.Id == id)); + } + } + + public void UpdateCars(AutoCenterDatabase context, PurchaseBindingModel? model) + { + Cars.Clear(); + foreach (var id in model.PurchaseCars.Keys) + { + Cars.Add(context.Cars.First(x => x.Id == id)); + } + } + public PurchaseViewModel GetViewModel => new() { Id = Id, IsCashPaid = IsCashPaid, ShopId = ShopId, UserId = UserId, - Date = Date + Date = Date, + PurchaseCars = PurchaseCars, + PurchasePresellingWorks = PurchasePresellingWorks, }; } } diff --git a/AutoCenter/AutoCenterRestApi/AutoCenterRestApi.csproj b/AutoCenter/AutoCenterRestApi/AutoCenterRestApi.csproj new file mode 100644 index 0000000..cd4de52 --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/AutoCenterRestApi.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + diff --git a/AutoCenter/AutoCenterRestApi/Controllers/CarBrandController.cs b/AutoCenter/AutoCenterRestApi/Controllers/CarBrandController.cs new file mode 100644 index 0000000..f260f57 --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/Controllers/CarBrandController.cs @@ -0,0 +1,93 @@ +using Microsoft.AspNetCore.Mvc; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class CarBrandController : Controller + { + private readonly ILogger _logger; + private readonly ICarBrandLogic _CarBrandLogic; + public CarBrandController(ILogger logger, ICarBrandLogic CarBrandLogic) + { + _logger = logger; + _CarBrandLogic = CarBrandLogic; + } + + [HttpGet] + public CarBrandViewModel? GetCarBrand(int CarBrandId) + { + try + { + return _CarBrandLogic.ReadElement(new CarBrandSearchModel + { + Id = CarBrandId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения марки машины по id={Id}", CarBrandId); + throw; + } + } + + [HttpGet] + public List? GetCarBrandList() + { + try + { + return _CarBrandLogic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения марок машин"); + throw; + } + } + [HttpPost] + public bool CreateCarBrand(CarBrandBindingModel model) + { + try + { + return _CarBrandLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать марки машины"); + throw; + } + } + + [HttpPost] + public bool UpdateCarBrand(CarBrandBindingModel model) + { + try + { + return _CarBrandLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить марку машины"); + throw; + } + } + + [HttpPost] + public bool DeleteCarBrand(CarBrandBindingModel model) + { + try + { + return _CarBrandLogic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления марки машины"); + throw; + } + } + } +} diff --git a/AutoCenter/AutoCenterRestApi/Controllers/CarController.cs b/AutoCenter/AutoCenterRestApi/Controllers/CarController.cs new file mode 100644 index 0000000..3fdc349 --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/Controllers/CarController.cs @@ -0,0 +1,94 @@ +using Microsoft.AspNetCore.Mvc; +using AutoCenterBusinessLogic.BusinessLogics; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class CarController : Controller + { + private readonly ILogger _logger; + private readonly ICarLogic _CarLogic; + public CarController(ILogger logger, ICarLogic Car) + { + _logger = logger; + _CarLogic = Car; + } + + [HttpGet] + public CarViewModel? GetCar(int CarId) + { + try + { + return _CarLogic.ReadElement(new CarSearchModel + { + Id = CarId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения машины по id={Id}", CarId); + throw; + } + } + + [HttpGet] + public List? GetCarList(int? carBrandId = null) + { + try + { + return !carBrandId.HasValue ? _CarLogic.ReadList(null) : _CarLogic.ReadList(new CarSearchModel { BrandId = carBrandId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка машин"); + throw; + } + } + [HttpPost] + public bool CreateCar(CarBindingModel model) + { + try + { + return _CarLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать машины"); + throw; + } + } + + [HttpPost] + public bool UpdateCar(CarBindingModel model) + { + try + { + return _CarLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить машину"); + throw; + } + } + + [HttpPost] + public bool DeleteCar(CarBindingModel model) + { + try + { + return _CarLogic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления машины"); + throw; + } + } + } +} diff --git a/AutoCenter/AutoCenterRestApi/Controllers/EquipmentController.cs b/AutoCenter/AutoCenterRestApi/Controllers/EquipmentController.cs new file mode 100644 index 0000000..41a433b --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/Controllers/EquipmentController.cs @@ -0,0 +1,94 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class EquipmentController : Controller + { + private readonly ILogger _logger; + private readonly IEquipmentLogic _EquipmentLogic; + public EquipmentController(ILogger logger, IEquipmentLogic EquipmentLogic) + { + _logger = logger; + _EquipmentLogic = EquipmentLogic; + } + + [HttpGet] + public EquipmentViewModel? GetEquipment(int EquipmentId) + { + try + { + return _EquipmentLogic.ReadElement(new EquipmentSearchModel + { + Id = EquipmentId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения комплектации по id={Id}", EquipmentId); + throw; + } + } + + [HttpGet] + public List? GetEquipmentList() + { + try + { + return _EquipmentLogic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка комплектаций"); + throw; + } + } + [HttpPost] + public bool CreateEquipment(EquipmentBindingModel model) + { + try + { + return _EquipmentLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать комплектацию"); + throw; + } + } + + [HttpPost] + public bool UpdateEquipment(EquipmentBindingModel model) + { + try + { + return _EquipmentLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить комплектацию"); + throw; + } + } + + [HttpPost] + public bool DeleteEquipment(EquipmentBindingModel model) + { + try + { + return _EquipmentLogic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления комплектации"); + throw; + } + } + } +} diff --git a/AutoCenter/AutoCenterRestApi/Controllers/PreSellingWorkController.cs b/AutoCenter/AutoCenterRestApi/Controllers/PreSellingWorkController.cs new file mode 100644 index 0000000..db82732 --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/Controllers/PreSellingWorkController.cs @@ -0,0 +1,95 @@ +using Microsoft.AspNetCore.Mvc; +using AutoCenterBusinessLogic.BusinessLogics; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; +using AutoCenterDatabaseImplement.Models; + +namespace AutoCenterRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class PreSellingWorkController : Controller + { + private readonly ILogger _logger; + private readonly IPresellingWorkLogic _PresellingWorkLogic; + public PreSellingWorkController(ILogger logger, IPresellingWorkLogic PresellingWork) + { + _logger = logger; + _PresellingWorkLogic = PresellingWork; + } + + [HttpGet] + public PresellingWorkViewModel? GetPresellingWork(int PresellingWorkId) + { + try + { + return _PresellingWorkLogic.ReadElement(new PresellingWorkSearchModel + { + Id = PresellingWorkId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения предпродажной работы по id={Id}", PresellingWorkId); + throw; + } + } + + [HttpGet] + public List? GetPresellingWorkList(int? userId = null) + { + try + { + return !userId.HasValue ? _PresellingWorkLogic.ReadList(null) : _PresellingWorkLogic.ReadList(new PresellingWorkSearchModel { UserId = userId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка предпродажных работ"); + throw; + } + } + [HttpPost] + public bool CreatePresellingWork(PresellingWorkBindingModel model) + { + try + { + return _PresellingWorkLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать предпродажную работу"); + throw; + } + } + + [HttpPost] + public bool UpdatePresellingWork(PresellingWorkBindingModel model) + { + try + { + return _PresellingWorkLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить предпродажную работу"); + throw; + } + } + + [HttpPost] + public bool DeletePresellingWork(PresellingWorkBindingModel model) + { + try + { + return _PresellingWorkLogic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления предпродажной работы"); + throw; + } + } + } +} diff --git a/AutoCenter/AutoCenterRestApi/Controllers/PurchaseController.cs b/AutoCenter/AutoCenterRestApi/Controllers/PurchaseController.cs new file mode 100644 index 0000000..06f5ba5 --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/Controllers/PurchaseController.cs @@ -0,0 +1,94 @@ +using Microsoft.AspNetCore.Mvc; +using AutoCenterBusinessLogic.BusinessLogics; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class PurchaseController : Controller + { + private readonly ILogger _logger; + private readonly IPurchaseLogic _PurchaseLogic; + public PurchaseController(ILogger logger, IPurchaseLogic PurchaseLogic) + { + _logger = logger; + _PurchaseLogic = PurchaseLogic; + } + + [HttpGet] + public PurchaseViewModel? GetPurchase(int PurchaseId) + { + try + { + return _PurchaseLogic.ReadElement(new PurchaseSearchModel + { + Id = PurchaseId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения покупки по id={Id}", PurchaseId); + throw; + } + } + + [HttpGet] + public List? GetPurchaseList(int? userId = null) + { + try + { + return !userId.HasValue ? _PurchaseLogic.ReadList(null) : _PurchaseLogic.ReadList(new PurchaseSearchModel { UserId = userId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка покупок"); + throw; + } + } + [HttpPost] + public bool CreatePurchase(PurchaseBindingModel model) + { + try + { + return _PurchaseLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать покупку"); + throw; + } + } + + [HttpPost] + public bool UpdatePurchase(PurchaseBindingModel model) + { + try + { + return _PurchaseLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить покупку"); + throw; + } + } + + [HttpPost] + public bool DeletePurchase(PurchaseBindingModel model) + { + try + { + return _PurchaseLogic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления покупки"); + throw; + } + } + } +} diff --git a/AutoCenter/AutoCenterRestApi/Controllers/ShopController.cs b/AutoCenter/AutoCenterRestApi/Controllers/ShopController.cs new file mode 100644 index 0000000..d354391 --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/Controllers/ShopController.cs @@ -0,0 +1,93 @@ +using Microsoft.AspNetCore.Mvc; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ShopController : Controller + { + private readonly ILogger _logger; + private readonly IShopLogic _ShopLogic; + public ShopController(ILogger logger, IShopLogic ShopLogic) + { + _logger = logger; + _ShopLogic = ShopLogic; + } + + [HttpGet] + public ShopViewModel? GetShop(int ShopId) + { + try + { + return _ShopLogic.ReadElement(new ShopSearchModel + { + Id = ShopId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения магазина по id={Id}", ShopId); + throw; + } + } + + [HttpGet] + public List? GetShopList() + { + try + { + return _ShopLogic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка магазинов"); + throw; + } + } + [HttpPost] + public bool CreateShop(ShopBindingModel model) + { + try + { + return _ShopLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать магазин"); + throw; + } + } + + [HttpPost] + public bool UpdateShop(ShopBindingModel model) + { + try + { + return _ShopLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить магазин"); + throw; + } + } + + [HttpPost] + public bool DeleteShop(ShopBindingModel model) + { + try + { + return _ShopLogic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + throw; + } + } + } +} diff --git a/AutoCenter/AutoCenterRestApi/Controllers/UserController.cs b/AutoCenter/AutoCenterRestApi/Controllers/UserController.cs new file mode 100644 index 0000000..4746410 --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/Controllers/UserController.cs @@ -0,0 +1,69 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class UserController : Controller + { + + private readonly ILogger _logger; + private readonly IUserLogic _UserLogic; + public UserController(ILogger logger, IUserLogic UserLogic) + { + _logger = logger; + _UserLogic = UserLogic; + } + + [HttpGet] + public UserViewModel? Login(string username, string password) + { + try + { + return _UserLogic.ReadElement(new UserSearchModel + { + Username = username, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + + [HttpPost] + public void Register(UserBindingModel model) + { + try + { + _UserLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + + [HttpPost] + public void UpdateData(UserBindingModel model) + { + try + { + _UserLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + } +} diff --git a/AutoCenter/AutoCenterRestApi/Controllers/WishController.cs b/AutoCenter/AutoCenterRestApi/Controllers/WishController.cs new file mode 100644 index 0000000..cc02be7 --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/Controllers/WishController.cs @@ -0,0 +1,94 @@ +using Microsoft.AspNetCore.Mvc; +using AutoCenterBusinessLogic.BusinessLogics; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class WishController : Controller + { + private readonly ILogger _logger; + private readonly IWishLogic _WishLogic; + public WishController(ILogger logger, IWishLogic Wish) + { + _logger = logger; + _WishLogic = Wish; + } + + [HttpGet] + public WishViewModel? GetWish(int WishId) + { + try + { + return _WishLogic.ReadElement(new WishSearchModel + { + Id = WishId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения пожелания по id={Id}", WishId); + throw; + } + } + + [HttpGet] + public List? GetWishList(int? presellingWorkId = null) + { + try + { + return !presellingWorkId.HasValue ? _WishLogic.ReadList(null) : _WishLogic.ReadList(new WishSearchModel { PresellingWorkId = presellingWorkId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка пожеланий"); + throw; + } + } + [HttpPost] + public bool CreateWish(WishBindingModel model) + { + try + { + return _WishLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать пожелание"); + throw; + } + } + + [HttpPost] + public bool UpdateWish(WishBindingModel model) + { + try + { + return _WishLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить пожелание"); + throw; + } + } + + [HttpPost] + public bool DeleteWish(WishBindingModel model) + { + try + { + return _WishLogic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления пожелания"); + throw; + } + } + } +} diff --git a/AutoCenter/AutoCenterRestApi/Program.cs b/AutoCenter/AutoCenterRestApi/Program.cs new file mode 100644 index 0000000..804315c --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/Program.cs @@ -0,0 +1,56 @@ +using Microsoft.OpenApi.Models; +using AutoCenterBusinessLogic.BusinessLogics; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.StoragesContracts; +using AutoCenterDatabaseImplement.Implements; + +var builder = WebApplication.CreateBuilder(args); + +builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.AddLog4Net("log4net.config"); + +// Add services to the container. + +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.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 +builder.Services.AddEndpointsApiExplorer(); + +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo { Title = "AutoCenterRestApi", Version = "v1" }); +}); +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AutoCenterRestApi v1")); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/AutoCenter/AutoCenterRestApi/Properties/launchSettings.json b/AutoCenter/AutoCenterRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..e2ec7b5 --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:39318", + "sslPort": 44359 + } + }, + "profiles": { + "AutoCenterRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7079;http://localhost:5250", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/AutoCenter/AutoCenterRestApi/appsettings.Development.json b/AutoCenter/AutoCenterRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/AutoCenter/AutoCenterRestApi/appsettings.json b/AutoCenter/AutoCenterRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/AutoCenter/AutoCenterRestApi/log4net.config b/AutoCenter/AutoCenterRestApi/log4net.config new file mode 100644 index 0000000..8a3fdc2 --- /dev/null +++ b/AutoCenter/AutoCenterRestApi/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file