models, contracts, db implement.

This commit is contained in:
kirin 2024-05-01 19:29:21 +04:00
parent 7e15c92d41
commit 4a20353af1
78 changed files with 3913 additions and 0 deletions

39
AutoCenter/AutoCenter.sln Normal file
View File

@ -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

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AutoCenterContracts\AutoCenterContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -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<CarBrandLogic> logger, ICarBrandStorage CarBrandStorage)
{
_logger = logger;
_CarBrandStorage = CarBrandStorage;
}
public List<CarBrandViewModel>? 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("Такой бренд уже есть");
}
}
}
}

View File

@ -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<CarLogic> 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<CarViewModel>? 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("Такая машина уже существует");
}
}
}
}

View File

@ -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<EquipmentLogic> 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<EquipmentViewModel>? 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("Комплектация с таким названием уже есть");
}
}
}
}

View File

@ -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<UserLogic> 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<UserViewModel>? 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("Пользователь с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AutoCenterDataModels\AutoCenterDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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<CarBrandViewModel>? ReadList(CarBrandSearchModel? model);
CarBrandViewModel? ReadElement(CarBrandSearchModel model);
bool Create(CarBrandBindingModel model);
bool Update(CarBrandBindingModel model);
bool Delete(CarBrandBindingModel model);
}
}

View File

@ -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<CarViewModel>? ReadList(CarSearchModel? model);
CarViewModel? ReadElement(CarSearchModel model);
bool Create(CarBindingModel model);
bool Update(CarBindingModel model);
bool Delete(CarBindingModel model);
}
}

View File

@ -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<EquipmentViewModel>? ReadList(EquipmentSearchModel? model);
EquipmentViewModel? ReadElement(EquipmentSearchModel model);
bool Create(EquipmentBindingModel model);
bool Update(EquipmentBindingModel model);
bool Delete(EquipmentBindingModel model);
}
}

View File

@ -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<PresellingWorkViewModel>? ReadList(PresellingWorkSearchModel? model);
PresellingWorkViewModel? ReadElement(PresellingWorkSearchModel model);
bool Create(PresellingWorkBindingModel model);
bool Update(PresellingWorkBindingModel model);
bool Delete(PresellingWorkBindingModel model);
}
}

View File

@ -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<PurchaseViewModel>? ReadList(PurchaseSearchModel? model);
PurchaseViewModel? ReadElement(PurchaseSearchModel model);
bool Create(PurchaseBindingModel model);
bool Update(PurchaseBindingModel model);
bool Delete(PurchaseBindingModel model);
}
}

View File

@ -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<ShopViewModel>? ReadList(ShopSearchModel? model);
ShopViewModel? ReadElement(ShopSearchModel model);
bool Create(ShopBindingModel model);
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
}
}

View File

@ -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<UserViewModel>? ReadList(UserSearchModel? model);
UserViewModel? ReadElement(UserSearchModel model);
bool Create(UserBindingModel model);
bool Update(UserBindingModel model);
bool Delete(UserBindingModel model);
}
}

View File

@ -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<WishViewModel>? ReadList(WishSearchModel? model);
WishViewModel? ReadElement(WishSearchModel model);
bool Create(WishBindingModel model);
bool Update(WishBindingModel model);
bool Delete(WishBindingModel model);
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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<CarBrandViewModel> GetFullList();
List<CarBrandViewModel> GetFilteredList(CarBrandSearchModel model);
CarBrandViewModel? GetElement(CarBrandSearchModel model);
CarBrandViewModel? Insert(CarBrandBindingModel model);
CarBrandViewModel? Update(CarBrandBindingModel model);
CarBrandViewModel? Delete(CarBrandBindingModel model);
}
}

View File

@ -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<CarViewModel> GetFullList();
List<CarViewModel> GetFilteredList(CarSearchModel model);
CarViewModel? GetElement(CarSearchModel model);
CarViewModel? Insert(CarBindingModel model);
CarViewModel? Update(CarBindingModel model);
CarViewModel? Delete(CarBindingModel model);
}
}

View File

@ -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<EquipmentViewModel> GetFullList();
List<EquipmentViewModel> GetFilteredList(EquipmentSearchModel model);
EquipmentViewModel? GetElement(EquipmentSearchModel model);
EquipmentViewModel? Insert(EquipmentBindingModel model);
EquipmentViewModel? Update(EquipmentBindingModel model);
EquipmentViewModel? Delete(EquipmentBindingModel model);
}
}

View File

@ -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<PresellingWorkViewModel> GetFullList();
List<PresellingWorkViewModel> GetFilteredList(PresellingWorkSearchModel model);
PresellingWorkViewModel? GetElement(PresellingWorkSearchModel model);
PresellingWorkViewModel? Insert(PresellingWorkBindingModel model);
PresellingWorkViewModel? Update(PresellingWorkBindingModel model);
PresellingWorkViewModel? Delete(PresellingWorkBindingModel model);
}
}

View File

@ -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<PurchaseViewModel> GetFullList();
List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model);
PurchaseViewModel? GetElement(PurchaseSearchModel model);
PurchaseViewModel? Insert(PurchaseBindingModel model);
PurchaseViewModel? Update(PurchaseBindingModel model);
PurchaseViewModel? Delete(PurchaseBindingModel model);
}
}

View File

@ -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<ShopViewModel> GetFullList();
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
ShopViewModel? GetElement(ShopSearchModel model);
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
}
}

View File

@ -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<UserViewModel> GetFullList();
List<UserViewModel> GetFilteredList(UserSearchModel model);
UserViewModel? GetElement(UserSearchModel model);
UserViewModel? Insert(UserBindingModel model);
UserViewModel? Update(UserBindingModel model);
UserViewModel? Delete(UserBindingModel model);
}
}

View File

@ -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<WishViewModel> GetFullList();
List<WishViewModel> GetFilteredList(WishSearchModel model);
WishViewModel? GetElement(WishSearchModel model);
WishViewModel? Insert(WishBindingModel model);
WishViewModel? Update(WishBindingModel model);
WishViewModel? Delete(WishBindingModel model);
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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<CarBrand> CarBrands { get; set; }
public virtual DbSet<PresellingWork> PresellingWorks { get; set; }
public virtual DbSet<Car> Cars { get; set; }
public virtual DbSet<Purchase> Purchases { get; set; }
public virtual DbSet<Shop> Shops{ set; get; }
public virtual DbSet<User> Users{ set; get; }
public virtual DbSet<Wish> Wishes { get; set; }
public virtual DbSet<Equipment> Equipments { get; set; }
}
}

View File

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AutoCenterContracts\AutoCenterContracts.csproj" />
<ProjectReference Include="..\AutoCenterDataModels\AutoCenterDataModels.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>

View File

@ -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<CarBrandViewModel> 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<CarBrandViewModel> 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;
}
}
}

View File

@ -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<CarViewModel> 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<CarViewModel> 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;
}
}
}

View File

@ -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<EquipmentViewModel> 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<EquipmentViewModel> 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;
}
}
}

View File

@ -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<PresellingWorkViewModel> 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<PresellingWorkViewModel> 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;
}
}
}

View File

@ -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<PurchaseViewModel> 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<PurchaseViewModel> 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;
}
}
}

View File

@ -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<ShopViewModel> 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<ShopViewModel> 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;
}
}
}

View File

@ -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<UserViewModel> 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<UserViewModel> 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;
}
}
}

View File

@ -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<WishViewModel> 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<WishViewModel> 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;
}
}
}

View File

@ -0,0 +1,396 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BrandId")
.HasColumnType("int");
b.Property<int>("CarBrandId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("CarBrandId");
b.ToTable("Cars");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.CarBrand", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("CarBrands");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Equipment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Equipments");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.PresellingWork", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("PresellingWorks");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Purchase", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<bool>("IsCashPaid")
.HasColumnType("bit");
b.Property<int>("ShopId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ShopId");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Wish", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("PresellingWorkId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PresellingWorkId");
b.ToTable("Wishes");
});
modelBuilder.Entity("CarEquipment", b =>
{
b.Property<int>("CarsId")
.HasColumnType("int");
b.Property<int>("EquipmentsId")
.HasColumnType("int");
b.HasKey("CarsId", "EquipmentsId");
b.HasIndex("EquipmentsId");
b.ToTable("CarEquipment");
});
modelBuilder.Entity("CarPurchase", b =>
{
b.Property<int>("CarsId")
.HasColumnType("int");
b.Property<int>("PurchasesId")
.HasColumnType("int");
b.HasKey("CarsId", "PurchasesId");
b.HasIndex("PurchasesId");
b.ToTable("CarPurchase");
});
modelBuilder.Entity("PresellingWorkPurchase", b =>
{
b.Property<int>("PresellingWorksId")
.HasColumnType("int");
b.Property<int>("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
}
}
}

View File

@ -0,0 +1,322 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AutoCenterDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class Init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "CarBrands",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CarBrands", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Shops",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Address = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Shops", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Username = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Cars",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
BrandId = table.Column<int>(type: "int", nullable: false),
CarBrandId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
UserId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
UserId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
IsCashPaid = table.Column<bool>(type: "bit", nullable: false),
ShopId = table.Column<int>(type: "int", nullable: false),
UserId = table.Column<int>(type: "int", nullable: false),
Date = table.Column<DateTime>(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<int>(type: "int", nullable: false),
EquipmentsId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
PresellingWorkId = table.Column<int>(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<int>(type: "int", nullable: false),
PurchasesId = table.Column<int>(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<int>(type: "int", nullable: false),
PurchasesId = table.Column<int>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -0,0 +1,393 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BrandId")
.HasColumnType("int");
b.Property<int>("CarBrandId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("CarBrandId");
b.ToTable("Cars");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.CarBrand", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("CarBrands");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Equipment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Equipments");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.PresellingWork", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("PresellingWorks");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Purchase", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<bool>("IsCashPaid")
.HasColumnType("bit");
b.Property<int>("ShopId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ShopId");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("AutoCenterDatabaseImplement.Models.Wish", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("PresellingWorkId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PresellingWorkId");
b.ToTable("Wishes");
});
modelBuilder.Entity("CarEquipment", b =>
{
b.Property<int>("CarsId")
.HasColumnType("int");
b.Property<int>("EquipmentsId")
.HasColumnType("int");
b.HasKey("CarsId", "EquipmentsId");
b.HasIndex("EquipmentsId");
b.ToTable("CarEquipment");
});
modelBuilder.Entity("CarPurchase", b =>
{
b.Property<int>("CarsId")
.HasColumnType("int");
b.Property<int>("PurchasesId")
.HasColumnType("int");
b.HasKey("CarsId", "PurchasesId");
b.HasIndex("PurchasesId");
b.ToTable("CarPurchase");
});
modelBuilder.Entity("PresellingWorkPurchase", b =>
{
b.Property<int>("PresellingWorksId")
.HasColumnType("int");
b.Property<int>("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
}
}
}

View File

@ -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<Equipment> Equipments { get; private set; } = new();
public List<Purchase> 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
};
}
}

View File

@ -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<Car> 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
};
}
}

View File

@ -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<Car> 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
};
}
}

View File

@ -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<Wish> Wishes { get; set; } = new();
public List<Purchase> 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
};
}
}

View File

@ -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<Car> Cars { get; set; } = new();
public List<PresellingWork> 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
};
}
}

View File

@ -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<Purchase> 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
};
}
}

View File

@ -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<Equipment> Equipments { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Purchase> Purchases { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<PresellingWork> 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
};
}
}

View File

@ -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
};
}
}