many to many fixed. rest api done
This commit is contained in:
parent
166e13913b
commit
82cc504aba
@ -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
|
||||
|
@ -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<int, IEquipmentModel> CarEquipments { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,6 @@ namespace AutoCenterContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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<int, IPresellingWorkModel> PurchasePresellingWorks { get; } = new();
|
||||
public Dictionary<int, ICarModel> PurchaseCars { get; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -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<int, IEquipmentModel> CarEquipments { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -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<int, IPresellingWorkModel> PurchasePresellingWorks { get; set; } = new();
|
||||
public Dictionary<int, ICarModel> PurchaseCars { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -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<int, IEquipmentModel> CarEquipments { get; }
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
|
@ -12,5 +12,7 @@ namespace AutoCenterDataModels.Models
|
||||
int ShopId { get; }
|
||||
int UserId { get; }
|
||||
DateTime Date { get; }
|
||||
Dictionary<int, IPresellingWorkModel> PurchasePresellingWorks { get; }
|
||||
Dictionary<int, ICarModel> PurchaseCars { get; }
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace AutoCenterDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(AutoCenterDatabase))]
|
||||
[Migration("20240501151957_Init")]
|
||||
[Migration("20240503230402_Init")]
|
||||
partial class Init
|
||||
{
|
||||
/// <inheritdoc />
|
@ -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(
|
@ -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<Equipment> Equipments { get; private set; } = new();
|
||||
public List<Purchase> Purchases { get; private set; } = new();
|
||||
public int BrandId { get; set; }
|
||||
public virtual CarBrand Brand { get; set; } = new();
|
||||
public List<Equipment> Equipments { get; set; } = new();
|
||||
public List<Purchase> Purchases { get; set; } = new();
|
||||
|
||||
public static Car? Create(CarBindingModel model)
|
||||
private Dictionary<int, IEquipmentModel>? _equipments = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IEquipmentModel> 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
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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<Car> Cars { get; private set; } = new();
|
||||
public List<Car> Cars { get; set; } = new();
|
||||
|
||||
public static Equipment? Create(EquipmentBindingModel model)
|
||||
{
|
||||
|
@ -25,8 +25,34 @@ namespace AutoCenterDatabaseImplement.Models
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public List<Car> Cars { get; set; } = new();
|
||||
private Dictionary<int, ICarModel>? _cars = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, ICarModel> PurchaseCars
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_cars == null)
|
||||
{
|
||||
_cars = Cars.ToDictionary(record => record.Id, record => (record as ICarModel));
|
||||
}
|
||||
return _cars;
|
||||
}
|
||||
}
|
||||
public List<PresellingWork> PresellingWorks { get; set; } = new();
|
||||
public static Purchase? Create(PurchaseBindingModel model)
|
||||
private Dictionary<int, IPresellingWorkModel>? _presellingWorks = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IPresellingWorkModel> 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
20
AutoCenter/AutoCenterRestApi/AutoCenterRestApi.csproj
Normal file
20
AutoCenter/AutoCenterRestApi/AutoCenterRestApi.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoCenterBusinessLogic\AutoCenterBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\AutoCenterContracts\AutoCenterContracts.csproj" />
|
||||
<ProjectReference Include="..\AutoCenterDatabaseImplement\AutoCenterDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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<CarBrandController> 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<CarBrandViewModel>? 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
94
AutoCenter/AutoCenterRestApi/Controllers/CarController.cs
Normal file
94
AutoCenter/AutoCenterRestApi/Controllers/CarController.cs
Normal file
@ -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<CarController> 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<CarViewModel>? 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<EquipmentController> 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<EquipmentViewModel>? 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<PreSellingWorkController> 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<PresellingWorkViewModel>? 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<PurchaseController> 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<PurchaseViewModel>? 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
93
AutoCenter/AutoCenterRestApi/Controllers/ShopController.cs
Normal file
93
AutoCenter/AutoCenterRestApi/Controllers/ShopController.cs
Normal file
@ -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<ShopController> 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<ShopViewModel>? 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
69
AutoCenter/AutoCenterRestApi/Controllers/UserController.cs
Normal file
69
AutoCenter/AutoCenterRestApi/Controllers/UserController.cs
Normal file
@ -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<UserController> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
94
AutoCenter/AutoCenterRestApi/Controllers/WishController.cs
Normal file
94
AutoCenter/AutoCenterRestApi/Controllers/WishController.cs
Normal file
@ -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<WishController> 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<WishViewModel>? 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
AutoCenter/AutoCenterRestApi/Program.cs
Normal file
56
AutoCenter/AutoCenterRestApi/Program.cs
Normal file
@ -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<ICarBrandStorage, CarBrandStorage>();
|
||||
builder.Services.AddTransient<ICarStorage, CarStorage>();
|
||||
builder.Services.AddTransient<IEquipmentStorage, EquipmentStorage>();
|
||||
builder.Services.AddTransient<IPresellingWorkStorage, PresellingWorkStorage>();
|
||||
builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>();
|
||||
builder.Services.AddTransient<IShopStorage, ShopStorage>();
|
||||
builder.Services.AddTransient<IUserStorage, UserStorage>();
|
||||
builder.Services.AddTransient<IWishStorage, WishStorage>();
|
||||
|
||||
|
||||
builder.Services.AddTransient<ICarBrandLogic, CarBrandLogic>();
|
||||
builder.Services.AddTransient<ICarLogic, CarLogic>();
|
||||
builder.Services.AddTransient<IEquipmentLogic, EquipmentLogic>();
|
||||
builder.Services.AddTransient<IPresellingWorkLogic, PresellingWorkLogic>();
|
||||
builder.Services.AddTransient<IPurchaseLogic, PurchaseLogic>();
|
||||
builder.Services.AddTransient<IShopLogic, ShopLogic>();
|
||||
builder.Services.AddTransient<IUserLogic, UserLogic>();
|
||||
builder.Services.AddTransient<IWishLogic, WishLogic>();
|
||||
|
||||
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();
|
31
AutoCenter/AutoCenterRestApi/Properties/launchSettings.json
Normal file
31
AutoCenter/AutoCenterRestApi/Properties/launchSettings.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
AutoCenter/AutoCenterRestApi/appsettings.json
Normal file
9
AutoCenter/AutoCenterRestApi/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
16
AutoCenter/AutoCenterRestApi/log4net.config
Normal file
16
AutoCenter/AutoCenterRestApi/log4net.config
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<log4net>
|
||||
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
|
||||
<file value="c:/temp/BlacksmithWorkshopResrApi.log" />
|
||||
<appendToFile value="true" />
|
||||
<maximumFileSize value="100KB" />
|
||||
<maxSizeRollBackups value="2" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
|
||||
</layout>
|
||||
</appender>
|
||||
<root>
|
||||
<level value="TRACE" />
|
||||
<appender-ref ref="RollingFile" />
|
||||
</root>
|
||||
</log4net>
|
Loading…
Reference in New Issue
Block a user