diff --git a/AutoCenter/AutoCenter.sln b/AutoCenter/AutoCenter.sln new file mode 100644 index 0000000..036b161 --- /dev/null +++ b/AutoCenter/AutoCenter.sln @@ -0,0 +1,39 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34622.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoCenterDataModels", "AutoCenterDataModels\AutoCenterDataModels.csproj", "{EAE9694C-31B4-4AD0-9FAC-99BBD4F44236}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoCenterContracts", "AutoCenterContracts\AutoCenterContracts.csproj", "{3458E50C-D0E1-4CC5-B7F2-308C38CA55E6}" +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}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EAE9694C-31B4-4AD0-9FAC-99BBD4F44236}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EAE9694C-31B4-4AD0-9FAC-99BBD4F44236}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EAE9694C-31B4-4AD0-9FAC-99BBD4F44236}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EAE9694C-31B4-4AD0-9FAC-99BBD4F44236}.Release|Any CPU.Build.0 = Release|Any CPU + {3458E50C-D0E1-4CC5-B7F2-308C38CA55E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3458E50C-D0E1-4CC5-B7F2-308C38CA55E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3458E50C-D0E1-4CC5-B7F2-308C38CA55E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3458E50C-D0E1-4CC5-B7F2-308C38CA55E6}.Release|Any CPU.Build.0 = Release|Any CPU + {617B8C58-1F96-44A5-9EE6-A78EA441CA66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {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 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D4AA40EB-6CB9-4650-85A1-035B23139ABF} + EndGlobalSection +EndGlobal diff --git a/AutoCenter/AutoCenterBusinessLogic/AutoCenterBusinessLogic.csproj b/AutoCenter/AutoCenterBusinessLogic/AutoCenterBusinessLogic.csproj new file mode 100644 index 0000000..9d9bb63 --- /dev/null +++ b/AutoCenter/AutoCenterBusinessLogic/AutoCenterBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/CarBrandLogic.cs b/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/CarBrandLogic.cs new file mode 100644 index 0000000..2c1c1e4 --- /dev/null +++ b/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/CarBrandLogic.cs @@ -0,0 +1,110 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.StoragesContracts; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterBusinessLogic.BusinessLogics +{ + public class CarBrandLogic : ICarBrandLogic + { + private readonly ILogger _logger; + private readonly ICarBrandStorage _CarBrandStorage; + public CarBrandLogic(ILogger logger, ICarBrandStorage CarBrandStorage) + { + _logger = logger; + _CarBrandStorage = CarBrandStorage; + } + public List? ReadList(CarBrandSearchModel? model) + { + _logger.LogInformation("CarBrand ReadList. Name:{Name}. Id:{Id}", model?.Name, model?.Id); + var list = model == null ? _CarBrandStorage.GetFullList() : + _CarBrandStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + return list; + } + public CarBrandViewModel? ReadElement(CarBrandSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("CarBrand ReadElement. Name:{Name}. Id:{Id}", model?.Name, model?.Id); + var element = _CarBrandStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(CarBrandBindingModel model) + { + CheckModel(model); + if (_CarBrandStorage.Insert(model) == null) + { + _logger.LogWarning("CarBrand Insert operation failed"); + return false; + } + return true; + } + public bool Update(CarBrandBindingModel model) + { + CheckModel(model); + if (_CarBrandStorage.Update(model) == null) + { + _logger.LogWarning("CarBrand Update operation failed"); + return false; + } + return true; + } + public bool Delete(CarBrandBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_CarBrandStorage.Delete(model) == null) + { + _logger.LogWarning("CarBrand Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(CarBrandBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия бренда", + nameof(model.Id)); + } + _logger.LogInformation("CarBrand. Name:{Name}. Id:{Id}", model?.Name, model?.Id); + var element = _CarBrandStorage.GetElement(new CarBrandSearchModel + { + Name = model.Name, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такой бренд уже есть"); + } + } + } +} diff --git a/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/CarLogic.cs b/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/CarLogic.cs new file mode 100644 index 0000000..093dd92 --- /dev/null +++ b/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/CarLogic.cs @@ -0,0 +1,137 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.StoragesContracts; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterBusinessLogic.BusinessLogics +{ + public class CarLogic: ICarLogic + { + private readonly ILogger _logger; + + private readonly ICarStorage _CarStorage; + + public CarLogic(ILogger logger, ICarStorage CarStorage) + { + _logger = logger; + _CarStorage = CarStorage; + } + public bool Create(CarBindingModel model) + { + CheckModel(model); + + if (_CarStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + public bool Delete(CarBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_CarStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + public CarViewModel? ReadElement(CarSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. CarName:{CarName}.Id:{Id}", model.Name, model.Id); + + var element = _CarStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + public List? ReadList(CarSearchModel? model) + { + _logger.LogInformation("ReadList. CarName:{CarName}.Id:{Id}", model.Name, model.Id); + + var list = model == null ? _CarStorage.GetFullList() : _CarStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + public bool Update(CarBindingModel model) + { + CheckModel(model); + + if (_CarStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + private void CheckModel(CarBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия автомобиля", nameof(model.Name)); + } + + if (model.BrandId < 1) + { + throw new ArgumentNullException("Нет бренда автомобиля", nameof(model.BrandId)); + } + + _logger.LogInformation("Car. CarName:{CarName}.Id:{Id}", model.Name, model.Id); + + var element = _CarStorage.GetElement(new CarSearchModel + { + BrandId = model.BrandId, + Name = model.Name + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такая машина уже существует"); + } + } + } +} diff --git a/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/EquipmentLogic.cs b/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/EquipmentLogic.cs new file mode 100644 index 0000000..dc69561 --- /dev/null +++ b/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/EquipmentLogic.cs @@ -0,0 +1,137 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.StoragesContracts; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterBusinessLogic.BusinessLogics +{ + public class EquipmentLogic: IEquipmentLogic + { + private readonly ILogger _logger; + + private readonly IEquipmentStorage _EquipmentStorage; + + public EquipmentLogic(ILogger logger, IEquipmentStorage EquipmentStorage) + { + _logger = logger; + _EquipmentStorage = EquipmentStorage; + } + public bool Create(EquipmentBindingModel model) + { + CheckModel(model); + + if (_EquipmentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + public bool Delete(EquipmentBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_EquipmentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + public EquipmentViewModel? ReadElement(EquipmentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Equipment:{Name}.Id:{Id}", model.Name, model.Id); + + var element = _EquipmentStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + public List? ReadList(EquipmentSearchModel? model) + { + _logger.LogInformation("ReadList. Equipment:{Name}.Id:{Id}", model.Name, model.Id); + + var list = model == null ? _EquipmentStorage.GetFullList() : _EquipmentStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + public bool Update(EquipmentBindingModel model) + { + CheckModel(model); + + if (_EquipmentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + private void CheckModel(EquipmentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия комплектации", nameof(model.Name)); + } + + if (string.IsNullOrEmpty(model.Description)) + { + throw new ArgumentNullException("Нет описания комплектации", nameof(model.Description)); + } + + _logger.LogInformation("Equipment. Equipment:{Name}.Id:{Id}", model.Name, model.Id); + + var element = _EquipmentStorage.GetElement(new EquipmentSearchModel + { + Name = model.Name, + Description = model.Description + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Комплектация с таким названием уже есть"); + } + } + } +} diff --git a/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/UserLogic.cs b/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/UserLogic.cs new file mode 100644 index 0000000..dbc32ad --- /dev/null +++ b/AutoCenter/AutoCenterBusinessLogic/BusinessLogics/UserLogic.cs @@ -0,0 +1,155 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.BusinessLogicsContracts; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.StoragesContracts; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterBusinessLogic.BusinessLogics +{ + public class UserLogic : IUserLogic + { + private readonly ILogger _logger; + + private readonly IUserStorage _UserStorage; + + public UserLogic(ILogger logger, IUserStorage UserStorage) + { + _logger = logger; + _UserStorage = UserStorage; + } + + public bool Create(UserBindingModel model) + { + CheckModel(model); + + if (_UserStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(UserBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_UserStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + public UserViewModel? ReadElement(UserSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. UserEmail:{UserFIO}.Id:{Id}", model.Email, model.Id); + + var element = _UserStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + + public List? ReadList(UserSearchModel? model) + { + _logger.LogInformation("ReadList. UserEmail:{UserFIO}.Id:{Id}", model.Email, model.Id); + + var list = model == null ? _UserStorage.GetFullList() : _UserStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + public bool Update(UserBindingModel model) + { + CheckModel(model); + + if (_UserStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + private void CheckModel(UserBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Нет почты пользователя", nameof(model.Email)); + } + + if (string.IsNullOrEmpty(model.Username)) + { + throw new ArgumentNullException("Нет имени пользователя", nameof(model.Email)); + } + + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Email)); + } + + if (string.IsNullOrEmpty(model.PhoneNumber)) + { + throw new ArgumentNullException("Нет номера телефона пользователя", nameof(model.Email)); + } + + _logger.LogInformation("User. UserEmail:{UserFIO}.Id:{Id}", model.Email, model.Id); + + var element = _UserStorage.GetElement(new UserSearchModel + { + Email = model.Email, + Username = model.Username, + Password = model.Password, + PhoneNumber = model.PhoneNumber, + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пользователь с таким названием уже есть"); + } + } + } +} diff --git a/AutoCenter/AutoCenterContracts/AutoCenterContracts.csproj b/AutoCenter/AutoCenterContracts/AutoCenterContracts.csproj new file mode 100644 index 0000000..b29a63d --- /dev/null +++ b/AutoCenter/AutoCenterContracts/AutoCenterContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/AutoCenter/AutoCenterContracts/BindingModels/CarBindingModel.cs b/AutoCenter/AutoCenterContracts/BindingModels/CarBindingModel.cs new file mode 100644 index 0000000..7e7dfd0 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BindingModels/CarBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterDataModels.Models; + +namespace AutoCenterContracts.BindingModels +{ + public class CarBindingModel : ICarModel + { + public int Id { get; set; } + public string Name { get; set; } + public int BrandId { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/BindingModels/CarBrandBindingModel.cs b/AutoCenter/AutoCenterContracts/BindingModels/CarBrandBindingModel.cs new file mode 100644 index 0000000..11ca982 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BindingModels/CarBrandBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterDataModels.Models; + +namespace AutoCenterContracts.BindingModels +{ + public class CarBrandBindingModel : ICarBrandModel + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/BindingModels/EquipmentBindingModel.cs b/AutoCenter/AutoCenterContracts/BindingModels/EquipmentBindingModel.cs new file mode 100644 index 0000000..d7fe919 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BindingModels/EquipmentBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterDataModels.Models; + +namespace AutoCenterContracts.BindingModels +{ + public class EquipmentBindingModel : IEquipmentModel + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/BindingModels/PresellingWorkBindingModel.cs b/AutoCenter/AutoCenterContracts/BindingModels/PresellingWorkBindingModel.cs new file mode 100644 index 0000000..129fbf0 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BindingModels/PresellingWorkBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterDataModels.Models; + +namespace AutoCenterContracts.BindingModels +{ + public class PresellingWorkBindingModel : IPresellingWorkModel + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public int UserId { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/BindingModels/PurchaseBindingModel.cs b/AutoCenter/AutoCenterContracts/BindingModels/PurchaseBindingModel.cs new file mode 100644 index 0000000..e52a619 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BindingModels/PurchaseBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterDataModels.Models; + +namespace AutoCenterContracts.BindingModels +{ + public class PurchaseBindingModel : IPurchaseModel + { + public int Id { get; set; } + public bool IsCashPaid { get; set; } + public int ShopId { get; set; } + public int UserId { get; set; } + public DateTime Date { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/BindingModels/ShopBindingModel.cs b/AutoCenter/AutoCenterContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..13de114 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterDataModels.Models; + +namespace AutoCenterContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string Address { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/BindingModels/UserBindingModel.cs b/AutoCenter/AutoCenterContracts/BindingModels/UserBindingModel.cs new file mode 100644 index 0000000..4037191 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BindingModels/UserBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterDataModels.Models; + +namespace AutoCenterContracts.BindingModels +{ + public class UserBindingModel : IUserModel + { + public int Id { get; set; } + public string Username { get; set; } + public string Email { get; set; } + public string Password { get; set; } + public string PhoneNumber { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/BindingModels/WishBindingModel.cs b/AutoCenter/AutoCenterContracts/BindingModels/WishBindingModel.cs new file mode 100644 index 0000000..86d4b01 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BindingModels/WishBindingModel.cs @@ -0,0 +1,17 @@ +using AutoCenterDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.BindingModels +{ + public class WishBindingModel : IWishModel + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public int PresellingWorkId { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/ICarBrandLogic.cs b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/ICarBrandLogic.cs new file mode 100644 index 0000000..d14e263 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/ICarBrandLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.BusinessLogicsContracts +{ + public interface ICarBrandLogic + { + List? ReadList(CarBrandSearchModel? model); + CarBrandViewModel? ReadElement(CarBrandSearchModel model); + bool Create(CarBrandBindingModel model); + bool Update(CarBrandBindingModel model); + bool Delete(CarBrandBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/ICarLogic.cs b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/ICarLogic.cs new file mode 100644 index 0000000..b364a77 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/ICarLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.BusinessLogicsContracts +{ + public interface ICarLogic + { + List? ReadList(CarSearchModel? model); + CarViewModel? ReadElement(CarSearchModel model); + bool Create(CarBindingModel model); + bool Update(CarBindingModel model); + bool Delete(CarBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IEquipmentLogic.cs b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IEquipmentLogic.cs new file mode 100644 index 0000000..77cc0f9 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IEquipmentLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.BusinessLogicsContracts +{ + public interface IEquipmentLogic + { + List? ReadList(EquipmentSearchModel? model); + EquipmentViewModel? ReadElement(EquipmentSearchModel model); + bool Create(EquipmentBindingModel model); + bool Update(EquipmentBindingModel model); + bool Delete(EquipmentBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IPresellingWorkLogic.cs b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IPresellingWorkLogic.cs new file mode 100644 index 0000000..39514f0 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IPresellingWorkLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.BusinessLogicsContracts +{ + public interface IPresellingWorkLogic + { + List? ReadList(PresellingWorkSearchModel? model); + PresellingWorkViewModel? ReadElement(PresellingWorkSearchModel model); + bool Create(PresellingWorkBindingModel model); + bool Update(PresellingWorkBindingModel model); + bool Delete(PresellingWorkBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IPurchaseLogic.cs b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IPurchaseLogic.cs new file mode 100644 index 0000000..a704648 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IPurchaseLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.BusinessLogicsContracts +{ + public interface IPurchaseLogic + { + List? ReadList(PurchaseSearchModel? model); + PurchaseViewModel? ReadElement(PurchaseSearchModel model); + bool Create(PurchaseBindingModel model); + bool Update(PurchaseBindingModel model); + bool Delete(PurchaseBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IShopLogic.cs b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..867091b --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IUserLogic.cs b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IUserLogic.cs new file mode 100644 index 0000000..9465c2c --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IUserLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.BusinessLogicsContracts +{ + public interface IUserLogic + { + List? ReadList(UserSearchModel? model); + UserViewModel? ReadElement(UserSearchModel model); + bool Create(UserBindingModel model); + bool Update(UserBindingModel model); + bool Delete(UserBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IWishLogic.cs b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IWishLogic.cs new file mode 100644 index 0000000..bf06c5d --- /dev/null +++ b/AutoCenter/AutoCenterContracts/BusinessLogicsContracts/IWishLogic.cs @@ -0,0 +1,20 @@ +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.BusinessLogicsContracts +{ + public interface IWishLogic + { + List? ReadList(WishSearchModel? model); + WishViewModel? ReadElement(WishSearchModel model); + bool Create(WishBindingModel model); + bool Update(WishBindingModel model); + bool Delete(WishBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/SearchModels/CarBrandSearchModel.cs b/AutoCenter/AutoCenterContracts/SearchModels/CarBrandSearchModel.cs new file mode 100644 index 0000000..ecbe1ff --- /dev/null +++ b/AutoCenter/AutoCenterContracts/SearchModels/CarBrandSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.SearchModels +{ + public class CarBrandSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/SearchModels/CarSearchModel.cs b/AutoCenter/AutoCenterContracts/SearchModels/CarSearchModel.cs new file mode 100644 index 0000000..46df66c --- /dev/null +++ b/AutoCenter/AutoCenterContracts/SearchModels/CarSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.SearchModels +{ + public class CarSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + public int? BrandId { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/SearchModels/EquipmentSearchModel.cs b/AutoCenter/AutoCenterContracts/SearchModels/EquipmentSearchModel.cs new file mode 100644 index 0000000..858b19e --- /dev/null +++ b/AutoCenter/AutoCenterContracts/SearchModels/EquipmentSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.SearchModels +{ + public class EquipmentSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + public string? Description { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/SearchModels/PresellingWorkSearchModel.cs b/AutoCenter/AutoCenterContracts/SearchModels/PresellingWorkSearchModel.cs new file mode 100644 index 0000000..bf40106 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/SearchModels/PresellingWorkSearchModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.SearchModels +{ + public class PresellingWorkSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + public string? Description { get; set; } + public int? UserId { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/SearchModels/PurchaseSearchModel.cs b/AutoCenter/AutoCenterContracts/SearchModels/PurchaseSearchModel.cs new file mode 100644 index 0000000..4ee031f --- /dev/null +++ b/AutoCenter/AutoCenterContracts/SearchModels/PurchaseSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.SearchModels +{ + public class PurchaseSearchModel + { + public int? Id { get; set; } + public bool? IsCashPaid { get; set; } + public int? ShopId { get; set; } + public int? UserId { get; set; } + public DateTime? Date { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/SearchModels/ShopSearchModel.cs b/AutoCenter/AutoCenterContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..2379424 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Address { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/SearchModels/UserSearchModel.cs b/AutoCenter/AutoCenterContracts/SearchModels/UserSearchModel.cs new file mode 100644 index 0000000..cf7d287 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/SearchModels/UserSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.SearchModels +{ + public class UserSearchModel + { + public int? Id { get; set; } + public string? Username { get; set; } + public string? Email { get; set; } + public string? Password { get; set; } + public string? PhoneNumber { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/SearchModels/WishSearchModel.cs b/AutoCenter/AutoCenterContracts/SearchModels/WishSearchModel.cs new file mode 100644 index 0000000..4e719b0 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/SearchModels/WishSearchModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.SearchModels +{ + public class WishSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + public string? Description { get; set; } + public int? PresellingWorkId { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/StoragesContracts/ICarBrandStorage.cs b/AutoCenter/AutoCenterContracts/StoragesContracts/ICarBrandStorage.cs new file mode 100644 index 0000000..c911538 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/StoragesContracts/ICarBrandStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.StoragesContracts +{ + public interface ICarBrandStorage + { + List GetFullList(); + List GetFilteredList(CarBrandSearchModel model); + CarBrandViewModel? GetElement(CarBrandSearchModel model); + CarBrandViewModel? Insert(CarBrandBindingModel model); + CarBrandViewModel? Update(CarBrandBindingModel model); + CarBrandViewModel? Delete(CarBrandBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/StoragesContracts/ICarStorage.cs b/AutoCenter/AutoCenterContracts/StoragesContracts/ICarStorage.cs new file mode 100644 index 0000000..7a8a659 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/StoragesContracts/ICarStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.StoragesContracts +{ + public interface ICarStorage + { + List GetFullList(); + List GetFilteredList(CarSearchModel model); + CarViewModel? GetElement(CarSearchModel model); + CarViewModel? Insert(CarBindingModel model); + CarViewModel? Update(CarBindingModel model); + CarViewModel? Delete(CarBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/StoragesContracts/IEquipmentStorage.cs b/AutoCenter/AutoCenterContracts/StoragesContracts/IEquipmentStorage.cs new file mode 100644 index 0000000..1ec5d38 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/StoragesContracts/IEquipmentStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.StoragesContracts +{ + public interface IEquipmentStorage + { + List GetFullList(); + List GetFilteredList(EquipmentSearchModel model); + EquipmentViewModel? GetElement(EquipmentSearchModel model); + EquipmentViewModel? Insert(EquipmentBindingModel model); + EquipmentViewModel? Update(EquipmentBindingModel model); + EquipmentViewModel? Delete(EquipmentBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/StoragesContracts/IPresellingWorkStorage.cs b/AutoCenter/AutoCenterContracts/StoragesContracts/IPresellingWorkStorage.cs new file mode 100644 index 0000000..4a625c4 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/StoragesContracts/IPresellingWorkStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.StoragesContracts +{ + public interface IPresellingWorkStorage + { + List GetFullList(); + List GetFilteredList(PresellingWorkSearchModel model); + PresellingWorkViewModel? GetElement(PresellingWorkSearchModel model); + PresellingWorkViewModel? Insert(PresellingWorkBindingModel model); + PresellingWorkViewModel? Update(PresellingWorkBindingModel model); + PresellingWorkViewModel? Delete(PresellingWorkBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/StoragesContracts/IPurchaseStorage.cs b/AutoCenter/AutoCenterContracts/StoragesContracts/IPurchaseStorage.cs new file mode 100644 index 0000000..d9d58ab --- /dev/null +++ b/AutoCenter/AutoCenterContracts/StoragesContracts/IPurchaseStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.StoragesContracts +{ + public interface IPurchaseStorage + { + List GetFullList(); + List GetFilteredList(PurchaseSearchModel model); + PurchaseViewModel? GetElement(PurchaseSearchModel model); + PurchaseViewModel? Insert(PurchaseBindingModel model); + PurchaseViewModel? Update(PurchaseBindingModel model); + PurchaseViewModel? Delete(PurchaseBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/StoragesContracts/IShopStorage.cs b/AutoCenter/AutoCenterContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..f62bde4 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/StoragesContracts/IUserStorage.cs b/AutoCenter/AutoCenterContracts/StoragesContracts/IUserStorage.cs new file mode 100644 index 0000000..5bd1c90 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/StoragesContracts/IUserStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; + +namespace AutoCenterContracts.StoragesContracts +{ + public interface IUserStorage + { + List GetFullList(); + List GetFilteredList(UserSearchModel model); + UserViewModel? GetElement(UserSearchModel model); + UserViewModel? Insert(UserBindingModel model); + UserViewModel? Update(UserBindingModel model); + UserViewModel? Delete(UserBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/StoragesContracts/IWishStorage.cs b/AutoCenter/AutoCenterContracts/StoragesContracts/IWishStorage.cs new file mode 100644 index 0000000..4b20cc4 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/StoragesContracts/IWishStorage.cs @@ -0,0 +1,21 @@ +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.StoragesContracts +{ + public interface IWishStorage + { + List GetFullList(); + List GetFilteredList(WishSearchModel model); + WishViewModel? GetElement(WishSearchModel model); + WishViewModel? Insert(WishBindingModel model); + WishViewModel? Update(WishBindingModel model); + WishViewModel? Delete(WishBindingModel model); + } +} diff --git a/AutoCenter/AutoCenterContracts/ViewModels/CarBrandViewModel.cs b/AutoCenter/AutoCenterContracts/ViewModels/CarBrandViewModel.cs new file mode 100644 index 0000000..48e69b8 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/ViewModels/CarBrandViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.ViewModels +{ + public class CarBrandViewModel + { + public int Id { get; set; } + + [DisplayName("Название бренда")] + public string Name { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/ViewModels/CarViewModel.cs b/AutoCenter/AutoCenterContracts/ViewModels/CarViewModel.cs new file mode 100644 index 0000000..58d23e6 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/ViewModels/CarViewModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.ViewModels +{ + public class CarViewModel + { + public int Id { get; set; } + + [DisplayName("Название машины")] + public string Name { get; set; } + + public int BrandId { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/ViewModels/EquipmentViewModel.cs b/AutoCenter/AutoCenterContracts/ViewModels/EquipmentViewModel.cs new file mode 100644 index 0000000..0dad6d0 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/ViewModels/EquipmentViewModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.ViewModels +{ + public class EquipmentViewModel + { + public int Id { get; set; } + + [DisplayName("Название")] + public string Name { get; set; } + + [DisplayName("Описание")] + public string Description { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/ViewModels/PresellingWorkViewModel.cs b/AutoCenter/AutoCenterContracts/ViewModels/PresellingWorkViewModel.cs new file mode 100644 index 0000000..f17df80 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/ViewModels/PresellingWorkViewModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.ViewModels +{ + public class PresellingWorkViewModel + { + public int Id { get; set; } + + [DisplayName("Название")] + public string Name { get; set; } + + [DisplayName("Описание")] + public string Description { get; set; } + public int UserId { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/ViewModels/PurchaseViewModel.cs b/AutoCenter/AutoCenterContracts/ViewModels/PurchaseViewModel.cs new file mode 100644 index 0000000..19fccde --- /dev/null +++ b/AutoCenter/AutoCenterContracts/ViewModels/PurchaseViewModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.ViewModels +{ + public class PurchaseViewModel + { + public int Id { get; set; } + + [DisplayName("Метод оплаты")] + public bool IsCashPaid { get; set; } + public int ShopId { get; set; } + public int UserId { get; set; } + + [DisplayName("Дата оплаты")] + public DateTime Date { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/ViewModels/ShopViewModel.cs b/AutoCenter/AutoCenterContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..0a8ef99 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.ViewModels +{ + public class ShopViewModel + { + public int Id { get; set; } + + [DisplayName("Адрес")] + public string Address { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/ViewModels/UserViewModel.cs b/AutoCenter/AutoCenterContracts/ViewModels/UserViewModel.cs new file mode 100644 index 0000000..34832c1 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/ViewModels/UserViewModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.ViewModels +{ + public class UserViewModel + { + public int Id { get; set; } + + [DisplayName("Имя пользователя")] + public string Username { get; set; } + + [DisplayName("Почта")] + public string Email { get; set; } + + [DisplayName("Пароль")] + public string Password { get; set; } + + [DisplayName("Номер телефона")] + public string PhoneNumber { get; set; } + } +} diff --git a/AutoCenter/AutoCenterContracts/ViewModels/WishViewModel.cs b/AutoCenter/AutoCenterContracts/ViewModels/WishViewModel.cs new file mode 100644 index 0000000..f135ff8 --- /dev/null +++ b/AutoCenter/AutoCenterContracts/ViewModels/WishViewModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterContracts.ViewModels +{ + public class WishViewModel + { + public int Id { get; set; } + + [DisplayName("Название")] + public string Name { get; set; } + + [DisplayName("Описание")] + public string Description { get; set; } + public int PresellingWorkId { get; set; } + } +} diff --git a/AutoCenter/AutoCenterDataModels/AutoCenterDataModels.csproj b/AutoCenter/AutoCenterDataModels/AutoCenterDataModels.csproj new file mode 100644 index 0000000..aebf5ce --- /dev/null +++ b/AutoCenter/AutoCenterDataModels/AutoCenterDataModels.csproj @@ -0,0 +1,16 @@ + + + + net6.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/AutoCenter/AutoCenterDataModels/IId.cs b/AutoCenter/AutoCenterDataModels/IId.cs new file mode 100644 index 0000000..0f83e41 --- /dev/null +++ b/AutoCenter/AutoCenterDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/AutoCenter/AutoCenterDataModels/Models/ICarBrandModel.cs b/AutoCenter/AutoCenterDataModels/Models/ICarBrandModel.cs new file mode 100644 index 0000000..6d9aebe --- /dev/null +++ b/AutoCenter/AutoCenterDataModels/Models/ICarBrandModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterDataModels.Models +{ + public interface ICarBrandModel : IId + { + string Name { get; } + } +} diff --git a/AutoCenter/AutoCenterDataModels/Models/ICarModel.cs b/AutoCenter/AutoCenterDataModels/Models/ICarModel.cs new file mode 100644 index 0000000..9b763e7 --- /dev/null +++ b/AutoCenter/AutoCenterDataModels/Models/ICarModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterDataModels.Models +{ + public interface ICarModel + { + string Name { get; } + int BrandId { get; } + } +} diff --git a/AutoCenter/AutoCenterDataModels/Models/IEquipmentModel.cs b/AutoCenter/AutoCenterDataModels/Models/IEquipmentModel.cs new file mode 100644 index 0000000..7cb0fc6 --- /dev/null +++ b/AutoCenter/AutoCenterDataModels/Models/IEquipmentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterDataModels.Models +{ + public interface IEquipmentModel + { + string Name { get; } + string Description { get; } + } +} diff --git a/AutoCenter/AutoCenterDataModels/Models/IPresellingWorkModel.cs b/AutoCenter/AutoCenterDataModels/Models/IPresellingWorkModel.cs new file mode 100644 index 0000000..543a5d0 --- /dev/null +++ b/AutoCenter/AutoCenterDataModels/Models/IPresellingWorkModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterDataModels.Models +{ + public interface IPresellingWorkModel: IId + { + string Name { get; } + string Description { get; } + int UserId { get; } + } +} diff --git a/AutoCenter/AutoCenterDataModels/Models/IPurchaseModel.cs b/AutoCenter/AutoCenterDataModels/Models/IPurchaseModel.cs new file mode 100644 index 0000000..99ed598 --- /dev/null +++ b/AutoCenter/AutoCenterDataModels/Models/IPurchaseModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterDataModels.Models +{ + public interface IPurchaseModel: IId + { + bool IsCashPaid { get; } + int ShopId { get; } + int UserId { get; } + DateTime Date { get; } + } +} diff --git a/AutoCenter/AutoCenterDataModels/Models/IShopModel.cs b/AutoCenter/AutoCenterDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..745a3de --- /dev/null +++ b/AutoCenter/AutoCenterDataModels/Models/IShopModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterDataModels.Models +{ + public interface IShopModel: IId + { + string Address { get; } + } +} diff --git a/AutoCenter/AutoCenterDataModels/Models/IUserModel.cs b/AutoCenter/AutoCenterDataModels/Models/IUserModel.cs new file mode 100644 index 0000000..64f38a8 --- /dev/null +++ b/AutoCenter/AutoCenterDataModels/Models/IUserModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterDataModels.Models +{ + public interface IUserModel : IId + { + string Username { get; } + string Email { get; } + string PhoneNumber { get; } + string Password { get; } + } +} diff --git a/AutoCenter/AutoCenterDataModels/Models/IWishModel.cs b/AutoCenter/AutoCenterDataModels/Models/IWishModel.cs new file mode 100644 index 0000000..cf6fea1 --- /dev/null +++ b/AutoCenter/AutoCenterDataModels/Models/IWishModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterDataModels.Models +{ + public interface IWishModel: IId + { + string Name { get; } + string Description { get; } + int PresellingWorkId { get; } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/AutoCenterDatabase.cs b/AutoCenter/AutoCenterDatabaseImplement/AutoCenterDatabase.cs new file mode 100644 index 0000000..1acd3cf --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/AutoCenterDatabase.cs @@ -0,0 +1,32 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterDatabaseImplement.Models; + +namespace AutoCenterDatabaseImplement +{ + public class AutoCenterDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-K0U29OV;Initial Catalog=AutoCenter;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); + } + + base.OnConfiguring(optionsBuilder); + } + + public virtual DbSet CarBrands { get; set; } + public virtual DbSet PresellingWorks { get; set; } + public virtual DbSet Cars { get; set; } + public virtual DbSet Purchases { get; set; } + public virtual DbSet Shops{ set; get; } + public virtual DbSet Users{ set; get; } + public virtual DbSet Wishes { get; set; } + public virtual DbSet Equipments { get; set; } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/AutoCenterDatabaseImplement.csproj b/AutoCenter/AutoCenterDatabaseImplement/AutoCenterDatabaseImplement.csproj new file mode 100644 index 0000000..347a8ae --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/AutoCenterDatabaseImplement.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/CarBrandStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/CarBrandStorage.cs new file mode 100644 index 0000000..2d16cf3 --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/CarBrandStorage.cs @@ -0,0 +1,94 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.StoragesContracts; +using AutoCenterContracts.ViewModels; +using AutoCenterDatabaseImplement.Models; + +namespace AutoCenterDatabaseImplement.Implements +{ + public class CarBrandStorage : ICarBrandStorage + { + public CarBrandViewModel? Delete(CarBrandBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var element = context.CarBrands.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.CarBrands.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + public CarBrandViewModel? GetElement(CarBrandSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + using var context = new AutoCenterDatabase(); + + return context.CarBrands.Include(x => x.Cars).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public List GetFilteredList(CarBrandSearchModel model) + { + using var context = new AutoCenterDatabase(); + + return context.CarBrands.Include(x => x.Cars).Where(x => ((!model.Id.HasValue || x.Id == model.Id) + && (!string.IsNullOrEmpty(model.Name) || x.Name == model.Name) + )).Select(x => x.GetViewModel).ToList(); + } + public List GetFullList() + { + using var context = new AutoCenterDatabase(); + + return context.CarBrands.Include(x => x.Cars).Select(x => x.GetViewModel).ToList(); + } + + public CarBrandViewModel? Insert(CarBrandBindingModel model) + { + var newCarBrand = CarBrand.Create(model); + + if (newCarBrand == null) + { + return null; + } + + using var context = new AutoCenterDatabase(); + + context.CarBrands.Add(newCarBrand); + context.SaveChanges(); + + return newCarBrand.GetViewModel; + } + + public CarBrandViewModel? Update(CarBrandBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var CarBrand = context.CarBrands.FirstOrDefault(x => x.Id == model.Id); + + if (CarBrand == null) + { + return null; + } + + CarBrand.Update(model); + context.SaveChanges(); + + return CarBrand.GetViewModel; + } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/CarStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/CarStorage.cs new file mode 100644 index 0000000..4330c4a --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/CarStorage.cs @@ -0,0 +1,95 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; +using AutoCenterContracts.StoragesContracts; +using AutoCenterDatabaseImplement.Models; + +namespace AutoCenterDatabaseImplement.Implements +{ + public class CarStorage : ICarStorage + { + public CarViewModel? Delete(CarBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var element = context.Cars.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Cars.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + public CarViewModel? GetElement(CarSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + using var context = new AutoCenterDatabase(); + + return context.Cars.Include(x => x.Brand).Include(x => x.Purchases).Include(x => x.Equipments).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public List GetFilteredList(CarSearchModel model) + { + using var context = new AutoCenterDatabase(); + + return context.Cars.Include(x => x.Brand).Include(x => x.Purchases).Include(x => x.Equipments).Where(x => ((!model.Id.HasValue || x.Id == model.Id) + && (!string.IsNullOrEmpty(model.Name) || x.Name == model.Name) + && (!model.BrandId.HasValue || x.BrandId == model.BrandId) + )).Select(x => x.GetViewModel).ToList(); + } + public List GetFullList() + { + using var context = new AutoCenterDatabase(); + + return context.Cars.Include(x => x.Purchases).Include(x => x.Equipments).Select(x => x.GetViewModel).ToList(); + } + public CarViewModel? Insert(CarBindingModel model) + { + var newCar = Car.Create(model); + + if (newCar == null) + { + return null; + } + + using var context = new AutoCenterDatabase(); + + context.Cars.Add(newCar); + context.SaveChanges(); + + return newCar.GetViewModel; + } + public CarViewModel? Update(CarBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var Car = context.Cars.FirstOrDefault(x => x.Id == model.Id); + + if (Car == null) + { + return null; + } + + Car.Update(model); + context.SaveChanges(); + + return Car.GetViewModel; + } + } + + +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/EquipmentStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/EquipmentStorage.cs new file mode 100644 index 0000000..b56b9c4 --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/EquipmentStorage.cs @@ -0,0 +1,97 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.StoragesContracts; +using AutoCenterContracts.ViewModels; +using AutoCenterDatabaseImplement.Models; + +namespace AutoCenterDatabaseImplement.Implements +{ + public class EquipmentStorage : IEquipmentStorage + { + public EquipmentViewModel? Delete(EquipmentBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var element = context.Equipments.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Equipments.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + public EquipmentViewModel? GetElement(EquipmentSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + using var context = new AutoCenterDatabase(); + + return context.Equipments.Include(x => x.Cars).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(EquipmentSearchModel model) + { + using var context = new AutoCenterDatabase(); + + return context.Equipments.Include(x => x.Cars) + .Where(x => ((!model.Id.HasValue || x.Id == model.Id) && (!string.IsNullOrEmpty(model.Name) || x.Name == model.Name) && + (!string.IsNullOrEmpty(model.Description) || x.Description == model.Description))) + .Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new AutoCenterDatabase(); + + return context.Equipments.Include(x => x.Cars).Select(x => x.GetViewModel).ToList(); + } + + public EquipmentViewModel? Insert(EquipmentBindingModel model) + { + using var context = new AutoCenterDatabase(); + var newEquipment = Equipment.Create(model); + + if (newEquipment == null) + { + return null; + } + + context.Equipments.Add(newEquipment); + context.SaveChanges(); + + return newEquipment.GetViewModel; + } + + public EquipmentViewModel? Update(EquipmentBindingModel model) + { + using var context = new AutoCenterDatabase(); + + + var Equipment = context.Equipments.FirstOrDefault(x => x.Id == model.Id); + if (Equipment == null) + { + return null; + } + + Equipment.Update(model); + context.SaveChanges(); + + return Equipment.GetViewModel; + + } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/PresellingWorkStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/PresellingWorkStorage.cs new file mode 100644 index 0000000..6e2a094 --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/PresellingWorkStorage.cs @@ -0,0 +1,96 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.StoragesContracts; +using AutoCenterContracts.ViewModels; +using AutoCenterDatabaseImplement.Models; + +namespace AutoCenterDatabaseImplement.Implements +{ + public class PresellingWorkStorage : IPresellingWorkStorage + { + public PresellingWorkViewModel? Delete(PresellingWorkBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var element = context.PresellingWorks.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.PresellingWorks.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + public PresellingWorkViewModel? GetElement(PresellingWorkSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + using var context = new AutoCenterDatabase(); + + return context.PresellingWorks.Include(x => x.Wishes).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(PresellingWorkSearchModel model) + { + using var context = new AutoCenterDatabase(); + + return context.PresellingWorks.Include(x => x.Wishes) + .Where(x => ((!model.Id.HasValue || x.Id == model.Id) + && (!string.IsNullOrEmpty(model.Name) || x.Name == model.Name) + && (!string.IsNullOrEmpty(model.Description) || x.Description == model.Description) + && (!model.UserId.HasValue || x.UserId == model.UserId) + )) + .Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new AutoCenterDatabase(); + + return context.PresellingWorks.Include(x => x.Wishes).Select(x => x.GetViewModel).ToList(); + } + + public PresellingWorkViewModel? Insert(PresellingWorkBindingModel model) + { + using var context = new AutoCenterDatabase(); + var newPresellingWork = PresellingWork.Create(model); + + if (newPresellingWork == null) + { + return null; + } + + context.PresellingWorks.Add(newPresellingWork); + context.SaveChanges(); + + return newPresellingWork.GetViewModel; + } + + public PresellingWorkViewModel? Update(PresellingWorkBindingModel model) + { + using var context = new AutoCenterDatabase(); + var PresellingWork = context.PresellingWorks.FirstOrDefault(x => x.Id == model.Id); + if (PresellingWork == null) + { + return null; + } + + PresellingWork.Update(model); + context.SaveChanges(); + return PresellingWork.GetViewModel; + } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/PurchaseStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/PurchaseStorage.cs new file mode 100644 index 0000000..202f5f7 --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/PurchaseStorage.cs @@ -0,0 +1,95 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; +using AutoCenterContracts.StoragesContracts; +using AutoCenterDatabaseImplement.Models; + +namespace AutoCenterDatabaseImplement.Implements +{ + public class PurchaseStorage : IPurchaseStorage + { + public PurchaseViewModel? Delete(PurchaseBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var element = context.Purchases.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Purchases.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + public PurchaseViewModel? GetElement(PurchaseSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + using var context = new AutoCenterDatabase(); + + return context.Purchases.Include(x => x.PresellingWorks).Include(x => x.Cars).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public List GetFilteredList(PurchaseSearchModel model) + { + using var context = new AutoCenterDatabase(); + + return context.Purchases.Include(x => x.PresellingWorks).Include(x => x.Cars).Where(x => ((!model.Id.HasValue || x.Id == model.Id) + && (!model.IsCashPaid.HasValue || x.IsCashPaid == model.IsCashPaid) + && (!model.UserId.HasValue || x.UserId == model.UserId) + && (!model.Date.HasValue || x.Date == model.Date) + && (!model.ShopId.HasValue || x.ShopId == model.ShopId))) + .Select(x => x.GetViewModel).ToList(); + } + public List GetFullList() + { + using var context = new AutoCenterDatabase(); + + return context.Purchases.Include(x => x.PresellingWorks).Include(x => x.Cars).Select(x => x.GetViewModel).ToList(); + } + public PurchaseViewModel? Insert(PurchaseBindingModel model) + { + using var context = new AutoCenterDatabase(); + var newPurchase = Purchase.Create(model); + + if (newPurchase == null) + { + return null; + } + + + + context.Purchases.Add(newPurchase); + context.SaveChanges(); + + return newPurchase.GetViewModel; + } + public PurchaseViewModel? Update(PurchaseBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var Purchase = context.Purchases.FirstOrDefault(x => x.Id == model.Id); + + if (Purchase == null) + { + return null; + } + + Purchase.Update(model); + context.SaveChanges(); + + return Purchase.GetViewModel; + } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/ShopStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..4f7c288 --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,91 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; +using AutoCenterContracts.StoragesContracts; +using AutoCenterDatabaseImplement.Models; + +namespace AutoCenterDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var element = context.Shops.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Shops.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + using var context = new AutoCenterDatabase(); + + return context.Shops.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public List GetFilteredList(ShopSearchModel model) + { + using var context = new AutoCenterDatabase(); + + return context.Shops.Where(x => ((!model.Id.HasValue || x.Id == model.Id) + && (!string.IsNullOrEmpty(model.Address) || x.Address == model.Address))) + .Select(x => x.GetViewModel).ToList(); + } + public List GetFullList() + { + using var context = new AutoCenterDatabase(); + + return context.Shops.Select(x => x.GetViewModel).ToList(); + } + public ShopViewModel? Insert(ShopBindingModel model) + { + var newShop = Shop.Create(model); + + if (newShop == null) + { + return null; + } + + using var context = new AutoCenterDatabase(); + + context.Shops.Add(newShop); + context.SaveChanges(); + + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var Shop = context.Shops.FirstOrDefault(x => x.Id == model.Id); + + if (Shop == null) + { + return null; + } + + Shop.Update(model); + context.SaveChanges(); + + return Shop.GetViewModel; + } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/UserStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/UserStorage.cs new file mode 100644 index 0000000..a5987a6 --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/UserStorage.cs @@ -0,0 +1,103 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.StoragesContracts; +using AutoCenterContracts.ViewModels; +using AutoCenterDatabaseImplement.Models; + +namespace AutoCenterDatabaseImplement.Implements +{ + public class UserStorage : IUserStorage + { + public UserViewModel? Delete(UserBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var element = context.Users.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Users.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + public UserViewModel? GetElement(UserSearchModel model) + { + using var context = new AutoCenterDatabase(); + + if (model.Id.HasValue) + { + return context.Users.Include(x => x.Equipments).Include(x => x.Purchases).Include(x => x.PresellingWorks).FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel; + } + else if (!string.IsNullOrEmpty(model.Username) && !string.IsNullOrEmpty(model.Password)) + { + return context.Users.Include(x => x.Equipments).Include(x => x.Purchases).Include(x => x.PresellingWorks).FirstOrDefault(x => (x.Password == model.Password && x.Username == model.Username))?.GetViewModel; + } + return null; + } + + public List GetFilteredList(UserSearchModel model) + { + using var context = new AutoCenterDatabase(); + + return context.Users.Include(x => x.Equipments).Include(x => x.Purchases).Include(x => x.PresellingWorks).Where(x => ((!model.Id.HasValue || x.Id == model.Id) + && (!string.IsNullOrEmpty(model.Username) || x.Username == model.Username) + && (!string.IsNullOrEmpty(model.Password) || x.Password == model.Password) + && (!string.IsNullOrEmpty(model.PhoneNumber) || x.PhoneNumber == model.PhoneNumber) + && (!string.IsNullOrEmpty(model.Email) || x.Email == model.Email) + )) + .Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new AutoCenterDatabase(); + + return context.Users.Include(x => x.Equipments).Include(x => x.Purchases).Include(x => x.PresellingWorks).Select(x => x.GetViewModel).ToList(); + } + + public UserViewModel? Insert(UserBindingModel model) + { + var newUser = User.Create(model); + + if (newUser == null) + { + return null; + } + + using var context = new AutoCenterDatabase(); + + context.Users.Add(newUser); + context.SaveChanges(); + + return newUser.GetViewModel; + } + + public UserViewModel? Update(UserBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var User = context.Users.FirstOrDefault(x => x.Id == model.Id); + + if (User == null) + { + return null; + } + + User.Update(model); + context.SaveChanges(); + + return User.GetViewModel; + } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Implements/WishStorage.cs b/AutoCenter/AutoCenterDatabaseImplement/Implements/WishStorage.cs new file mode 100644 index 0000000..1049d9f --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Implements/WishStorage.cs @@ -0,0 +1,94 @@ +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.SearchModels; +using AutoCenterContracts.ViewModels; +using AutoCenterDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterDatabaseImplement.Implements +{ + public class WishStorage + { + public WishViewModel? Delete(WishBindingModel model) + { + using var context = new AutoCenterDatabase(); + + var element = context.Wishes.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Wishes.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + public WishViewModel? GetElement(WishSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + using var context = new AutoCenterDatabase(); + + return context.Wishes.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(WishSearchModel model) + { + using var context = new AutoCenterDatabase(); + + return context.Wishes.Where(x => ((!model.Id.HasValue || x.Id == model.Id) + && (!string.IsNullOrEmpty(model.Name) || x.Name == model.Name) + && (!string.IsNullOrEmpty(model.Description) || x.Description == model.Description) + && (!model.PresellingWorkId.HasValue || x.PresellingWorkId == model.PresellingWorkId) + )) + .Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new AutoCenterDatabase(); + + return context.Wishes.Select(x => x.GetViewModel).ToList(); + } + + public WishViewModel? Insert(WishBindingModel model) + { + + var newWish = Wish.Create(model); + + if (newWish == null) + { + return null; + } + using var context = new AutoCenterDatabase(); + context.Wishes.Add(newWish); + context.SaveChanges(); + + return newWish.GetViewModel; + } + + public WishViewModel? Update(WishBindingModel model) + { + using var context = new AutoCenterDatabase(); + var Wish = context.Wishes.FirstOrDefault(x => x.Id == model.Id); + if (Wish == null) + { + return null; + } + + Wish.Update(model); + context.SaveChanges(); + return Wish.GetViewModel; + } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.Designer.cs b/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.Designer.cs new file mode 100644 index 0000000..eefe153 --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.Designer.cs @@ -0,0 +1,396 @@ +// +using System; +using AutoCenterDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AutoCenterDatabaseImplement.Migrations +{ + [DbContext(typeof(AutoCenterDatabase))] + [Migration("20240501151957_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Car", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BrandId") + .HasColumnType("int"); + + b.Property("CarBrandId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("CarBrandId"); + + b.ToTable("Cars"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.CarBrand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("CarBrands"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Equipment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Equipments"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.PresellingWork", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("PresellingWorks"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("IsCashPaid") + .HasColumnType("bit"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ShopId"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Username") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Wish", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PresellingWorkId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PresellingWorkId"); + + b.ToTable("Wishes"); + }); + + modelBuilder.Entity("CarEquipment", b => + { + b.Property("CarsId") + .HasColumnType("int"); + + b.Property("EquipmentsId") + .HasColumnType("int"); + + b.HasKey("CarsId", "EquipmentsId"); + + b.HasIndex("EquipmentsId"); + + b.ToTable("CarEquipment"); + }); + + modelBuilder.Entity("CarPurchase", b => + { + b.Property("CarsId") + .HasColumnType("int"); + + b.Property("PurchasesId") + .HasColumnType("int"); + + b.HasKey("CarsId", "PurchasesId"); + + b.HasIndex("PurchasesId"); + + b.ToTable("CarPurchase"); + }); + + modelBuilder.Entity("PresellingWorkPurchase", b => + { + b.Property("PresellingWorksId") + .HasColumnType("int"); + + b.Property("PurchasesId") + .HasColumnType("int"); + + b.HasKey("PresellingWorksId", "PurchasesId"); + + b.HasIndex("PurchasesId"); + + b.ToTable("PresellingWorkPurchase"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Car", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.CarBrand", "Brand") + .WithMany("Cars") + .HasForeignKey("CarBrandId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Brand"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Equipment", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.User", null) + .WithMany("Equipments") + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.PresellingWork", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.User", "User") + .WithMany("PresellingWorks") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Purchase", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.Shop", "Shop") + .WithMany("Purchases") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoCenterDatabaseImplement.Models.User", null) + .WithMany("Purchases") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Wish", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.PresellingWork", "PresellingWork") + .WithMany("Wishes") + .HasForeignKey("PresellingWorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PresellingWork"); + }); + + modelBuilder.Entity("CarEquipment", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.Car", null) + .WithMany() + .HasForeignKey("CarsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoCenterDatabaseImplement.Models.Equipment", null) + .WithMany() + .HasForeignKey("EquipmentsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarPurchase", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.Car", null) + .WithMany() + .HasForeignKey("CarsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoCenterDatabaseImplement.Models.Purchase", null) + .WithMany() + .HasForeignKey("PurchasesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("PresellingWorkPurchase", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.PresellingWork", null) + .WithMany() + .HasForeignKey("PresellingWorksId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoCenterDatabaseImplement.Models.Purchase", null) + .WithMany() + .HasForeignKey("PurchasesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.CarBrand", b => + { + b.Navigation("Cars"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.PresellingWork", b => + { + b.Navigation("Wishes"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Shop", b => + { + b.Navigation("Purchases"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.User", b => + { + b.Navigation("Equipments"); + + b.Navigation("PresellingWorks"); + + b.Navigation("Purchases"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.cs b/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.cs new file mode 100644 index 0000000..3b6f788 --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Migrations/20240501151957_Init.cs @@ -0,0 +1,322 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AutoCenterDatabaseImplement.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CarBrands", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CarBrands", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Address = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Username = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Cars", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + BrandId = table.Column(type: "int", nullable: false), + CarBrandId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Cars", x => x.Id); + table.ForeignKey( + name: "FK_Cars_CarBrands_CarBrandId", + column: x => x.CarBrandId, + principalTable: "CarBrands", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Equipments", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + UserId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Equipments", x => x.Id); + table.ForeignKey( + name: "FK_Equipments_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "PresellingWorks", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + UserId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PresellingWorks", x => x.Id); + table.ForeignKey( + name: "FK_PresellingWorks_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Purchases", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + IsCashPaid = table.Column(type: "bit", nullable: false), + ShopId = table.Column(type: "int", nullable: false), + UserId = table.Column(type: "int", nullable: false), + Date = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Purchases", x => x.Id); + table.ForeignKey( + name: "FK_Purchases_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Purchases_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CarEquipment", + columns: table => new + { + CarsId = table.Column(type: "int", nullable: false), + EquipmentsId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CarEquipment", x => new { x.CarsId, x.EquipmentsId }); + table.ForeignKey( + name: "FK_CarEquipment_Cars_CarsId", + column: x => x.CarsId, + principalTable: "Cars", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CarEquipment_Equipments_EquipmentsId", + column: x => x.EquipmentsId, + principalTable: "Equipments", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Wishes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + PresellingWorkId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Wishes", x => x.Id); + table.ForeignKey( + name: "FK_Wishes_PresellingWorks_PresellingWorkId", + column: x => x.PresellingWorkId, + principalTable: "PresellingWorks", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CarPurchase", + columns: table => new + { + CarsId = table.Column(type: "int", nullable: false), + PurchasesId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CarPurchase", x => new { x.CarsId, x.PurchasesId }); + table.ForeignKey( + name: "FK_CarPurchase_Cars_CarsId", + column: x => x.CarsId, + principalTable: "Cars", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CarPurchase_Purchases_PurchasesId", + column: x => x.PurchasesId, + principalTable: "Purchases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PresellingWorkPurchase", + columns: table => new + { + PresellingWorksId = table.Column(type: "int", nullable: false), + PurchasesId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PresellingWorkPurchase", x => new { x.PresellingWorksId, x.PurchasesId }); + table.ForeignKey( + name: "FK_PresellingWorkPurchase_PresellingWorks_PresellingWorksId", + column: x => x.PresellingWorksId, + principalTable: "PresellingWorks", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_PresellingWorkPurchase_Purchases_PurchasesId", + column: x => x.PurchasesId, + principalTable: "Purchases", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_CarEquipment_EquipmentsId", + table: "CarEquipment", + column: "EquipmentsId"); + + migrationBuilder.CreateIndex( + name: "IX_CarPurchase_PurchasesId", + table: "CarPurchase", + column: "PurchasesId"); + + migrationBuilder.CreateIndex( + name: "IX_Cars_CarBrandId", + table: "Cars", + column: "CarBrandId"); + + migrationBuilder.CreateIndex( + name: "IX_Equipments_UserId", + table: "Equipments", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_PresellingWorkPurchase_PurchasesId", + table: "PresellingWorkPurchase", + column: "PurchasesId"); + + migrationBuilder.CreateIndex( + name: "IX_PresellingWorks_UserId", + table: "PresellingWorks", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Purchases_ShopId", + table: "Purchases", + column: "ShopId"); + + migrationBuilder.CreateIndex( + name: "IX_Purchases_UserId", + table: "Purchases", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Wishes_PresellingWorkId", + table: "Wishes", + column: "PresellingWorkId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CarEquipment"); + + migrationBuilder.DropTable( + name: "CarPurchase"); + + migrationBuilder.DropTable( + name: "PresellingWorkPurchase"); + + migrationBuilder.DropTable( + name: "Wishes"); + + migrationBuilder.DropTable( + name: "Equipments"); + + migrationBuilder.DropTable( + name: "Cars"); + + migrationBuilder.DropTable( + name: "Purchases"); + + migrationBuilder.DropTable( + name: "PresellingWorks"); + + migrationBuilder.DropTable( + name: "CarBrands"); + + migrationBuilder.DropTable( + name: "Shops"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Migrations/AutoCenterDatabaseModelSnapshot.cs b/AutoCenter/AutoCenterDatabaseImplement/Migrations/AutoCenterDatabaseModelSnapshot.cs new file mode 100644 index 0000000..5a832d3 --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Migrations/AutoCenterDatabaseModelSnapshot.cs @@ -0,0 +1,393 @@ +// +using System; +using AutoCenterDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AutoCenterDatabaseImplement.Migrations +{ + [DbContext(typeof(AutoCenterDatabase))] + partial class AutoCenterDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Car", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BrandId") + .HasColumnType("int"); + + b.Property("CarBrandId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("CarBrandId"); + + b.ToTable("Cars"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.CarBrand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("CarBrands"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Equipment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Equipments"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.PresellingWork", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("PresellingWorks"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("IsCashPaid") + .HasColumnType("bit"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ShopId"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Username") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Wish", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PresellingWorkId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PresellingWorkId"); + + b.ToTable("Wishes"); + }); + + modelBuilder.Entity("CarEquipment", b => + { + b.Property("CarsId") + .HasColumnType("int"); + + b.Property("EquipmentsId") + .HasColumnType("int"); + + b.HasKey("CarsId", "EquipmentsId"); + + b.HasIndex("EquipmentsId"); + + b.ToTable("CarEquipment"); + }); + + modelBuilder.Entity("CarPurchase", b => + { + b.Property("CarsId") + .HasColumnType("int"); + + b.Property("PurchasesId") + .HasColumnType("int"); + + b.HasKey("CarsId", "PurchasesId"); + + b.HasIndex("PurchasesId"); + + b.ToTable("CarPurchase"); + }); + + modelBuilder.Entity("PresellingWorkPurchase", b => + { + b.Property("PresellingWorksId") + .HasColumnType("int"); + + b.Property("PurchasesId") + .HasColumnType("int"); + + b.HasKey("PresellingWorksId", "PurchasesId"); + + b.HasIndex("PurchasesId"); + + b.ToTable("PresellingWorkPurchase"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Car", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.CarBrand", "Brand") + .WithMany("Cars") + .HasForeignKey("CarBrandId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Brand"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Equipment", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.User", null) + .WithMany("Equipments") + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.PresellingWork", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.User", "User") + .WithMany("PresellingWorks") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Purchase", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.Shop", "Shop") + .WithMany("Purchases") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoCenterDatabaseImplement.Models.User", null) + .WithMany("Purchases") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Wish", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.PresellingWork", "PresellingWork") + .WithMany("Wishes") + .HasForeignKey("PresellingWorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PresellingWork"); + }); + + modelBuilder.Entity("CarEquipment", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.Car", null) + .WithMany() + .HasForeignKey("CarsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoCenterDatabaseImplement.Models.Equipment", null) + .WithMany() + .HasForeignKey("EquipmentsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarPurchase", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.Car", null) + .WithMany() + .HasForeignKey("CarsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoCenterDatabaseImplement.Models.Purchase", null) + .WithMany() + .HasForeignKey("PurchasesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("PresellingWorkPurchase", b => + { + b.HasOne("AutoCenterDatabaseImplement.Models.PresellingWork", null) + .WithMany() + .HasForeignKey("PresellingWorksId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoCenterDatabaseImplement.Models.Purchase", null) + .WithMany() + .HasForeignKey("PurchasesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.CarBrand", b => + { + b.Navigation("Cars"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.PresellingWork", b => + { + b.Navigation("Wishes"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Shop", b => + { + b.Navigation("Purchases"); + }); + + modelBuilder.Entity("AutoCenterDatabaseImplement.Models.User", b => + { + b.Navigation("Equipments"); + + b.Navigation("PresellingWorks"); + + b.Navigation("Purchases"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Models/Car.cs b/AutoCenter/AutoCenterDatabaseImplement/Models/Car.cs new file mode 100644 index 0000000..90a0cbf --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Models/Car.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.ViewModels; +using AutoCenterDataModels.Models; + +namespace AutoCenterDatabaseImplement.Models +{ + public class Car : ICarModel + { + public int Id { get; private set; } + [Required] + public string Name { get; private 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 static Car? Create(CarBindingModel model) + { + if (model == null) + { + return null; + } + + return new Car() + { + Id = model.Id, + Name = model.Name, + BrandId = model.BrandId + }; + } + public void Update(CarBindingModel? model) + { + if (model == null) + { + return; + } + + Name = model.Name; + BrandId = model.BrandId; + } + + public void UpdateEqiupment(AutoCenterDatabase context) + { + + } + public CarViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + BrandId = BrandId + }; + } + +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Models/CarBrand.cs b/AutoCenter/AutoCenterDatabaseImplement/Models/CarBrand.cs new file mode 100644 index 0000000..a240522 --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Models/CarBrand.cs @@ -0,0 +1,53 @@ +using Microsoft.Identity.Client; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.ViewModels; +using AutoCenterDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; + +namespace AutoCenterDatabaseImplement.Models +{ + public class CarBrand : ICarBrandModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } = string.Empty; + + [ForeignKey("CarBrandId")] + public List Cars { get; set; } = new(); + + public static CarBrand? Create(CarBrandBindingModel model) + { + if (model == null) + { + return null; + } + + return new CarBrand() + { + Id = model.Id, + Name = model.Name + }; + } + + public void Update(CarBrandBindingModel? model) + { + if (model == null) { + return; + } + + Name = model.Name; + } + + public CarBrandViewModel GetViewModel => new() + { + Id = Id, + Name = Name + }; + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Models/Equipment.cs b/AutoCenter/AutoCenterDatabaseImplement/Models/Equipment.cs new file mode 100644 index 0000000..80606f3 --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Models/Equipment.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.ViewModels; +using AutoCenterDataModels.Models; + +namespace AutoCenterDatabaseImplement.Models +{ + public class Equipment: IEquipmentModel + { + public int Id { get; private set; } + [Required] + public string Name { get; private set; } = string.Empty; + [Required] + public string Description { get; private set; } = string.Empty; + + public List Cars { get; private set; } = new(); + + public static Equipment? Create(EquipmentBindingModel model) + { + if (model == null) + { + return null; + } + + return new Equipment() + { + Id = model.Id, + Name = model.Name, + Description = model.Description + }; + } + public void Update(EquipmentBindingModel? model) + { + if (model == null) + { + return; + } + + Name = model.Name; + Description = model.Description; + } + public EquipmentViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Description = Description + }; + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Models/PresellingWork.cs b/AutoCenter/AutoCenterDatabaseImplement/Models/PresellingWork.cs new file mode 100644 index 0000000..61738aa --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Models/PresellingWork.cs @@ -0,0 +1,64 @@ +using Microsoft.Identity.Client; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.ViewModels; +using AutoCenterDataModels.Models; + +namespace AutoCenterDatabaseImplement.Models +{ + public class PresellingWork : IPresellingWorkModel + { + public int Id { get; set; } + [Required] + public string Name { get; private set; } = string.Empty; + [Required] + public string Description { get; private set; } = string.Empty; + [Required] + public int UserId { get;private set; } + public virtual User User { get; set; } = new(); + + public List Wishes { get; set; } = new(); + + public List Purchases { get; set; } = new(); + + public static PresellingWork? Create(PresellingWorkBindingModel model) + { + if (model == null) + { + return null; + } + + return new PresellingWork() + { + Id = model.Id, + Name = model.Name, + Description = model.Description + }; + } + + public void Update(PresellingWorkBindingModel? model) + { + if (model == null) + { + return; + } + + Id = model.Id; + Name = model.Name; + Description = model.Description; + } + + public PresellingWorkViewModel GetViewModel => new() + { + Id = Id, + Description = Description, + Name = Name + }; + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Models/Purchase.cs b/AutoCenter/AutoCenterDatabaseImplement/Models/Purchase.cs new file mode 100644 index 0000000..3414adb --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Models/Purchase.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.ViewModels; +using AutoCenterDataModels.Models; + +namespace AutoCenterDatabaseImplement.Models +{ + public class Purchase : IPurchaseModel + { + public int Id { get; set; } + [Required] + public bool IsCashPaid { get; set; } + [Required] + public int ShopId { get; set; } + public virtual Shop Shop { get; set; } = new(); + [Required] + public int UserId { get; set; } + [Required] + public DateTime Date { get; set; } + + public List Cars { get; set; } = new(); + public List PresellingWorks { get; set; } = new(); + public static Purchase? Create(PurchaseBindingModel model) + { + if (model == null) + { + return null; + } + + return new Purchase() + { + Id = model.Id, + IsCashPaid = model.IsCashPaid, + ShopId = model.ShopId, + UserId = model.UserId, + Date = model.Date + }; + } + + public void Update(PurchaseBindingModel? model) + { + if (model == null) + { + return; + } + + IsCashPaid = model.IsCashPaid; + ShopId = model.ShopId; + UserId = model.UserId; + Date = model.Date; + } + + public PurchaseViewModel GetViewModel => new() + { + Id = Id, + IsCashPaid = IsCashPaid, + ShopId = ShopId, + UserId = UserId, + Date = Date + }; + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Models/Shop.cs b/AutoCenter/AutoCenterDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..907a81f --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Models/Shop.cs @@ -0,0 +1,47 @@ +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.ViewModels; +using AutoCenterDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutoCenterDatabaseImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; set; } + [Required] + public string Address { get; private set; } = string.Empty; + public virtual List Purchases { get; set; } = new(); + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + + return new Shop() + { + Id = model.Id, + Address = model.Address + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + + Address = model.Address; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Address = Address + }; + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Models/User.cs b/AutoCenter/AutoCenterDatabaseImplement/Models/User.cs new file mode 100644 index 0000000..1a6cb8b --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Models/User.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.ViewModels; +using AutoCenterDataModels.Models; + +namespace AutoCenterDatabaseImplement.Models +{ + public class User : IUserModel + { + public int Id { get; set; } + [Required] + public string Username { get; set; } = string.Empty; + [Required] + public string Email { get; set; } = string.Empty; + [Required] + public string PhoneNumber { get; set; } = string.Empty; + [Required] + public string Password { get; set; } = string.Empty; + [ForeignKey("UserId")] + public virtual List Equipments { get; set; } = new(); + [ForeignKey("UserId")] + public virtual List Purchases { get; set; } = new(); + [ForeignKey("UserId")] + public virtual List PresellingWorks { get; set; } = new(); + + public static User? Create(UserBindingModel model) + { + if (model == null) + { + return null; + } + + return new User() + { + Id = model.Id, + Username = model.Username, + Email = model.Email, + Password = model.Password, + PhoneNumber = model.PhoneNumber + }; + } + public void Update(UserBindingModel? model) + { + if (model == null) + { + return; + } + + Username = model.Username; + Password = model.Password; + Email = model.Email; + PhoneNumber = model.PhoneNumber; + } + public UserViewModel GetViewModel => new() + { + Id = Id, + Username = Username, + Email = Email, + Password = Password, + PhoneNumber = PhoneNumber + }; + } +} diff --git a/AutoCenter/AutoCenterDatabaseImplement/Models/Wish.cs b/AutoCenter/AutoCenterDatabaseImplement/Models/Wish.cs new file mode 100644 index 0000000..ca7733e --- /dev/null +++ b/AutoCenter/AutoCenterDatabaseImplement/Models/Wish.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoCenterContracts.BindingModels; +using AutoCenterContracts.ViewModels; +using AutoCenterDataModels.Models; + +namespace AutoCenterDatabaseImplement.Models +{ + public class Wish : IWishModel + { + public int Id { get; set; } + + [Required] + public string Name { get; set; } = string.Empty; + + [Required] + public string Description { get; set; } = string.Empty; + [Required] + public int PresellingWorkId { get; set; } + public virtual PresellingWork PresellingWork { get; set; } = new(); + + public static Wish? Create(WishBindingModel model) + { + if (model == null) + { + return null; + } + + return new Wish() + { + Id = model.Id, + Name = model.Name, + Description = model.Description, + PresellingWorkId = model.PresellingWorkId + }; + } + public void Update(WishBindingModel? model) + { + if (model == null) + { + return; + } + + Name = model.Name; + Description = model.Description; + PresellingWorkId = model.PresellingWorkId; + } + public WishViewModel GetViewModel => new() + { + Id = Id, + Description = Description, + PresellingWorkId = PresellingWorkId + }; + } +}