обновил хранилище

This commit is contained in:
Stepan 2024-05-28 15:09:28 +04:00
parent 606a4a25f9
commit 80973fc18d
21 changed files with 190 additions and 432 deletions

View File

@ -123,7 +123,7 @@ namespace CarCenterBusinessLogic.BusinessLogics
throw new ArgumentNullException("Стоимость продажи не может быть меньше нуля", nameof(model.SalePrice));
}
_logger.LogInformation("Sale. SaleDate:{SaleDate}.SalePrice:{ SalePrice}. Id: { Id}", model.SaleDate, model.SalePrice, model.Id);
_logger.LogInformation("Sale. DateCreate:{DateCreate}.SalePrice:{ SalePrice}. Id: { Id}", model.DateCreate, model.SalePrice, model.Id);
}
}
}

View File

@ -7,7 +7,7 @@ namespace CarCenterContracts.BindingModels
public int Id { get; set; }
public string SaleName { get; set; } = string.Empty;
public double SalePrice { get; set; }
public DateTime SaleDate { get; set; } = DateTime.Now;
public DateTime DateCreate { get; set; } = DateTime.Now;
public int ManagerId { get; set; }
}
}

View File

@ -14,7 +14,7 @@ namespace CarCenterContracts.ViewModels
public double SalePrice { get; set; }
[DisplayName("Дата продажи")]
public DateTime SaleDate { get; set; }
public DateTime DateCreate { get; set; }
public int ManagerId { get; set; }
}

View File

@ -9,7 +9,7 @@ namespace CarCenterDataBaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D5A5OOG\GOLDFEST;Initial Catalog=CarCenter2;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D5A5OOG\GOLDFEST;Initial Catalog=CarCenter;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);

View File

@ -12,130 +12,61 @@ namespace CarCenterDataBaseImplement.Implemets
public EmployeeViewModel? Delete(EmployeeBindingModel model)
{
using var context = new CarCenterDataBase();
var element = context.Employees
.Include(x => x.Sales)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Employees.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
var newEmployee = context.Employees.FirstOrDefault(x => x.Id == model.Id);
if (newEmployee == null)
return null;
newEmployee.UpdateSales(context, model);
context.Employees.Remove(newEmployee);
context.SaveChanges();
return newEmployee.GetViewModel;
}
public EmployeeViewModel? GetElement(EmployeeSearchModel model)
{
if (string.IsNullOrEmpty(model.EmployeeFIO) && !model.Id.HasValue)
{
return null;
}
using var context = new CarCenterDataBase();
return context.Employees
.Include(x => x.Sales)
.ThenInclude(x => x.Sale)
.Include(x => x.Inspections)
.Include(x => x.Manager)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.EmployeeFIO) && x.EmployeeFIO == model.EmployeeFIO) || (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
return context.Employees.Include(x => x.Sales).ThenInclude(x => x.Sale).FirstOrDefault(x => (!string.IsNullOrEmpty(model.EmployeeFIO) && x.EmployeeFIO.Contains(model.EmployeeFIO)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
{
if (!model.ManagerId.HasValue)
if (!model.ManagerId.HasValue && !model.SaleId.HasValue)
{
return new();
}
using var context = new CarCenterDataBase();
if (model.ManagerId.HasValue)
return context.Employees
.Include(x => x.Sales)
.ThenInclude(x => x.Sale)
.Include(x => x.Inspections)
.Include(x => x.Manager)
.Where(x => x.ManagerId == model.ManagerId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
return context.Employees
.Include(x => x.Sales)
.ThenInclude(x => x.Sale)
.Include(x => x.Inspections)
.Include(x => x.Manager)
.Where(x => x.EmployeeFIO.Contains(model.EmployeeFIO))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
if (model.SaleId.HasValue)
return context.Employees.Include(x => x.Sales).ThenInclude(x => x.Sale).Where(x => x.ManagerId == model.ManagerId).Where(x => x.Sales.FirstOrDefault(y => y.SaleId == model.SaleId) != null).Include(x => x.Manager).Select(x => x.GetViewModel).ToList();
else
return context.Employees.Include(x => x.Sales).ThenInclude(x => x.Sale).Where(x => x.ManagerId == model.ManagerId).Select(x => x.GetViewModel).ToList();
}
public List<EmployeeViewModel> GetFullList()
{
using var context = new CarCenterDataBase();
return context.Employees
.Include(x => x.Sales)
.ThenInclude(x => x.Sale)
.Include(x => x.Inspections)
.Include(x => x.Manager)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
return context.Employees.Include(x => x.Sales).ThenInclude(x => x.Sale).Select(x => x.GetViewModel).ToList();
}
public EmployeeViewModel? Insert(EmployeeBindingModel model)
{
using var context = new CarCenterDataBase();
var newEmployee = Employee.Create(context,model);
var newEmployee = Employee.Create(context, model);
if (newEmployee == null)
{
return null;
}
context.Employees.Add(newEmployee);
context.SaveChanges();
return context.Employees
.Include(x => x.Sales)
.ThenInclude(x => x.Sale)
.Include(x => x.Inspections)
.Include(x => x.Manager)
.FirstOrDefault(x => x.Id == newEmployee.Id)
?.GetViewModel;
return newEmployee.GetViewModel;
}
public EmployeeViewModel? Update(EmployeeBindingModel model)
{
using var context = new CarCenterDataBase();
using var transaction = context.Database.BeginTransaction();
try
{
var elem = context.Employees.FirstOrDefault(rec => rec.Id == model.Id);
if (elem == null)
{
return null;
}
elem.Update(model);
context.SaveChanges();
if (model.EmployeeSales != null)
elem.UpdateSales(context, model);
transaction.Commit();
return elem.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
var newEmployee = context.Employees.FirstOrDefault(x => x.Id == model.Id);
if (newEmployee == null)
return null;
newEmployee.Update(model);
newEmployee.UpdateSales(context, model);
context.SaveChanges();
return newEmployee.GetViewModel;
}
}
}
}

View File

@ -12,111 +12,62 @@ namespace CarCenterDataBaseImplement.Implemets
public ManagerViewModel? Delete(ManagerBindingModel model)
{
using var context = new CarCenterDataBase();
var element = context.Managers.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Managers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
var newManager = context.Managers.FirstOrDefault(x => x.Id == model.Id);
if (newManager == null)
return null;
context.Managers.Remove(newManager);
context.SaveChanges();
return newManager.GetViewModel;
}
public ManagerViewModel? GetElement(ManagerSearchModel model)
{
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ManagerLogin)) { return null; }
using var context = new CarCenterDataBase();
if (model.Id.HasValue)
return context.Managers
.Include(x => x.PreSaleWorks)
.Include(x => x.Sales)
.Include(x => x.Employees)
.FirstOrDefault(x => x.Id == model.Id)?
.GetViewModel;
if (!string.IsNullOrEmpty(model.ManagerEmail) && !string.IsNullOrEmpty(model.ManagerPassword))
return context.Managers
.Include(x => x.PreSaleWorks)
.Include(x => x.Sales)
.Include(x => x.Employees)
.FirstOrDefault(x => x.ManagerEmail.Equals(model.ManagerEmail) && x.ManagerPassword.Equals(model.ManagerPassword))?
.GetViewModel;
if (!string.IsNullOrEmpty(model.ManagerEmail))
return context.Managers
.Include(x => x.PreSaleWorks)
.Include(x => x.Sales)
.Include(x => x.Employees)
.FirstOrDefault(x => x.ManagerEmail.Equals(model.ManagerEmail))?
.GetViewModel;
return null;
return context.Managers.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.ManagerLogin) && !string.IsNullOrEmpty(model.ManagerPassword) && x.ManagerLogin.Equals(model.ManagerLogin) && x.ManagerPassword.Equals(model.ManagerPassword)))?.GetViewModel; ;
}
public List<ManagerViewModel> GetFilteredList(ManagerSearchModel model)
{
if (string.IsNullOrEmpty(model.ManagerFIO))
{
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ManagerLogin))
return new();
}
using var context = new CarCenterDataBase();
return context.Managers
.Include(x => x.PreSaleWorks)
.Include(x => x.Sales)
.Include(x => x.Employees)
.Where(x => x.ManagerLogin.Contains(model.ManagerLogin) && x.ManagerPassword == model.ManagerPassword)
.Select(x => x.GetViewModel)
.ToList();
if (model.Id.HasValue)
{
return context.Managers.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
}
else
{
return context.Managers.Where(x => x.ManagerLogin.Equals(model.ManagerLogin)).Select(x => x.GetViewModel).ToList();
}
}
public List<ManagerViewModel> GetFullList()
{
using var context = new CarCenterDataBase();
return context.Managers
.Select(x => x.GetViewModel)
.ToList();
return context.Managers.Select(x => x.GetViewModel).ToList();
}
public ManagerViewModel? Insert(ManagerBindingModel model)
{
var newManager = Manager.Create(model);
if (newManager == null)
{
return null;
}
using var context = new CarCenterDataBase();
var newManager = Manager.Create(model);
if (newManager == null)
return null;
context.Managers.Add(newManager);
context.SaveChanges();
return newManager.GetViewModel;
}
public ManagerViewModel? Update(ManagerBindingModel model)
{
using var context = new CarCenterDataBase();
var Manager = context.Managers
.FirstOrDefault(x => x.Id == model.Id);
if (Manager == null)
{
var newManager = context.Managers.FirstOrDefault(x => x.Id == model.Id);
if (newManager == null)
return null;
}
Manager.Update(model);
newManager.Update(model);
context.SaveChanges();
return Manager.GetViewModel;
return newManager.GetViewModel;
}
}
}

View File

@ -12,103 +12,48 @@ namespace CarCenterDataBaseImplement.Implemets
public PreSaleWorkViewModel? Delete(PreSaleWorkBindingModel model)
{
using var context = new CarCenterDataBase();
var element = context.PreSaleWorks
.Include(x => x.Sales)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.PreSaleWorks.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
var newPreSaleWork = context.PreSaleWorks.FirstOrDefault(x => x.Id == model.Id);
if (newPreSaleWork == null)
return null;
newPreSaleWork.UpdateSales(context, model);
context.PreSaleWorks.Remove(newPreSaleWork);
context.SaveChanges();
return newPreSaleWork.GetViewModel;
}
public PreSaleWorkViewModel? GetElement(PreSaleWorkSearchModel model)
{
if (string.IsNullOrEmpty(model.PreSaleWorkType) && !model.Id.HasValue)
{
return null;
}
using var context = new CarCenterDataBase();
return context.PreSaleWorks
.Include(x => x.Sales)
.ThenInclude(x => x.Sale)
.ThenInclude(x => x.EmployeeSales)
.ThenInclude(x => x.Employee)
.Include(x => x.Completions)
.Include(x => x.Manager)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PreSaleWorkType) && x.PreSaleWorkType == model.PreSaleWorkType) || (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
return context.PreSaleWorks.Include(p => p.Sales).ThenInclude(p => p.Sale).Include(p => p.Completions).FirstOrDefault(x => (!string.IsNullOrEmpty(model.PreSaleWorkType) && x.PreSaleWorkType.Contains(model.PreSaleWorkType)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<PreSaleWorkViewModel> GetFilteredList(PreSaleWorkSearchModel model)
{
if (string.IsNullOrEmpty(model.PreSaleWorkType) && !model.ManagerId.HasValue)
if (!model.ManagerId.HasValue && !model.SalesId.HasValue && !model.CarSalesId.HasValue)
{
return new();
}
using var context = new CarCenterDataBase();
if (model.ManagerId.HasValue)
{
return context.PreSaleWorks
.Include(x => x.Sales)
.ThenInclude(x => x.Sale)
.ThenInclude(x => x.EmployeeSales)
.ThenInclude(x => x.Employee)
.Include(x => x.Completions)
.Include(x => x.Manager)
.Where(x => x.ManagerId == model.ManagerId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return context.PreSaleWorks
.Include(x => x.Sales)
.ThenInclude(x => x.Sale)
.ThenInclude(x => x.EmployeeSales)
.ThenInclude(x => x.Employee)
.Include(x => x.Completions)
.Include(x => x.Manager)
.Where(x => x.PreSaleWorkType.Contains(model.PreSaleWorkType))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
if (model.CarSalesId.HasValue)
return context.PreSaleWorks.Include(p => p.Sales).ThenInclude(p => p.Sale).Include(p => p.Completions).Where(x => x.ManagerId == model.ManagerId).Where(x => x.Sales.FirstOrDefault(y => y.SaleId == model.CarSalesId) != null).Select(x => x.GetViewModel).ToList();
else if (model.SalesId.HasValue)
return context.PreSaleWorks.Where(p => p.CompletionsId.HasValue).Include(p => p.Completions).ThenInclude(p => p.Cars).Where(x => x.Completions.Cars.FirstOrDefault(y => y.CarId == model.CarSalesId) != null).Select(x => x.GetViewModel).ToList();
else
return context.PreSaleWorks.Include(p => p.Sales).ThenInclude(p => p.Sale).Include(p => p.Completions).Where(x => x.ManagerId == model.ManagerId).Select(x => x.GetViewModel).ToList();
}
public List<PreSaleWorkViewModel> GetFullList()
{
using var context = new CarCenterDataBase();
return context.PreSaleWorks
.Include(x => x.Sales)
.ThenInclude(x => x.Sale)
.ThenInclude(x => x.EmployeeSales)
.ThenInclude(x => x.Employee)
.Include(x => x.Completions)
.Include(x => x.Manager)
.Select(x => x.GetViewModel)
.ToList();
return context.PreSaleWorks.Include(p => p.Sales).ThenInclude(p => p.Sale).Select(x => x.GetViewModel).ToList();
}
public PreSaleWorkViewModel? Insert(PreSaleWorkBindingModel model)
{
using var context = new CarCenterDataBase();
var newPreSaleWork = PreSaleWork.Create(context,model);
var newPreSaleWork = PreSaleWork.Create(context, model);
if (newPreSaleWork == null)
{
return null;
}
context.PreSaleWorks.Add(newPreSaleWork);
context.SaveChanges();
return newPreSaleWork.GetViewModel;
@ -117,26 +62,13 @@ namespace CarCenterDataBaseImplement.Implemets
public PreSaleWorkViewModel? Update(PreSaleWorkBindingModel model)
{
using var context = new CarCenterDataBase();
using var transaction = context.Database.BeginTransaction();
try
{
var elem = context.PreSaleWorks.FirstOrDefault(rec => rec.Id == model.Id);
if (elem == null)
{
return null;
}
elem.Update(model);
context.SaveChanges();
if (model.PreSaleWorkSales != null)
elem.UpdateSales(context, model);
transaction.Commit();
return elem.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
var newPreSaleWork = context.PreSaleWorks.FirstOrDefault(x => x.Id == model.Id);
if (newPreSaleWork == null)
return null;
newPreSaleWork.Update(model);
newPreSaleWork.UpdateSales(context, model);
context.SaveChanges();
return newPreSaleWork.GetViewModel;
}
}
}

View File

@ -12,118 +12,60 @@ namespace CarCenterDataBaseImplement.Implemets
public SaleViewModel? Delete(SaleBindingModel model)
{
using var context = new CarCenterDataBase();
var element = context.Sales.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Sales.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
var newCar = context.Sales.FirstOrDefault(x => x.Id == model.Id);
if (newCar == null)
return null;
context.Sales.Remove(newCar);
context.SaveChanges();
return newCar.GetViewModel;
}
public SaleViewModel? GetElement(SaleSearchModel model)
{
if (model.SaleDate == default(DateTime) && !model.Id.HasValue)
{
return null;
}
using var context = new CarCenterDataBase();
return context.Sales
.Include(x => x.EmployeeSales)
.ThenInclude(x => x.Employee)
.Include(x => x.PreSaleWorkSale)
.ThenInclude(x => x.PreSaleWork)
.Include(x => x.Manager)
.FirstOrDefault(x => (model.SaleDate == default(DateTime) && x.SaleDate == model.SaleDate) || (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
return context.Sales.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SaleName) && x.SaleName.Equals(model.SaleName)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<SaleViewModel> GetFilteredList(SaleSearchModel model)
{
if (model.SaleDate == default(DateTime) && !model.ManagerId.HasValue)
if (!model.ManagerId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue)
{
return new();
}
using var context = new CarCenterDataBase();
if (model.DateFrom.HasValue)
return context.Sales.Where(x => x.ManagerId == model.ManagerId).Where(x => x.DateCreate <= model.DateTo && x.DateCreate >= model.DateFrom).Select(x => x.GetViewModel).ToList();
else
return context.Sales.Where(x => x.ManagerId == model.ManagerId).Select(x => x.GetViewModel).ToList();
if (model.ManagerId.HasValue)
{
return context.Sales
.Include(x => x.EmployeeSales)
.ThenInclude(x => x.Employee)
.Include(x => x.PreSaleWorkSale)
.ThenInclude(x => x.PreSaleWork)
.Include(x => x.Manager)
.Where(x => x.ManagerId == model.ManagerId)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Sales
.Include(x => x.EmployeeSales)
.ThenInclude(x => x.Employee)
.Include(x => x.PreSaleWorkSale)
.ThenInclude(x => x.PreSaleWork)
.Include(x => x.Manager)
.Where(x => x.SaleDate == model.SaleDate)
.Select(x => x.GetViewModel)
.ToList();
}
public List<SaleViewModel> GetFullList()
{
using var context = new CarCenterDataBase();
return context.Sales
.Include(x => x.EmployeeSales)
.ThenInclude(x => x.Employee)
.Include(x => x.PreSaleWorkSale)
.ThenInclude(x => x.PreSaleWork)
.Include(x => x.Manager)
.Select(x => x.GetViewModel)
.ToList();
return context.Sales.Select(x => x.GetViewModel).ToList();
}
public SaleViewModel? Insert(SaleBindingModel model)
{
using var context = new CarCenterDataBase();
var newSale = Sale.Create(model);
if (newSale == null)
{
var newCar = Sale.Create(model);
if (newCar == null)
return null;
}
context.Sales.Add(newSale);
context.Sales.Add(newCar);
context.SaveChanges();
return newSale.GetViewModel;
return newCar.GetViewModel;
}
public SaleViewModel? Update(SaleBindingModel model)
{
using var context = new CarCenterDataBase();
var Sale = context.Sales.FirstOrDefault(x => x.Id == model.Id);
if (Sale == null)
{
var newCar = context.Sales.FirstOrDefault(x => x.Id == model.Id);
if (newCar == null)
return null;
}
Sale.Update(model);
newCar.Update(model);
context.SaveChanges();
return Sale.GetViewModel;
return newCar.GetViewModel;
}
}
}

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CarCenterDataBaseImplement.Migrations
{
[DbContext(typeof(CarCenterDataBase))]
[Migration("20240527184458_InitialCreate")]
[Migration("20240528110830_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -223,7 +223,9 @@ namespace CarCenterDataBaseImplement.Migrations
b.HasIndex("AdministratorId");
b.HasIndex("EmployeeId");
b.HasIndex("EmployeeId")
.IsUnique()
.HasFilter("[EmployeeId] IS NOT NULL");
b.ToTable("Inspections");
});
@ -292,7 +294,7 @@ namespace CarCenterDataBaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CompletionsId")
b.Property<int?>("CompletionsId")
.HasColumnType("int");
b.Property<int>("ManagerId")
@ -312,7 +314,8 @@ namespace CarCenterDataBaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("CompletionsId")
.IsUnique();
.IsUnique()
.HasFilter("[CompletionsId] IS NOT NULL");
b.HasIndex("ManagerId");
@ -350,12 +353,12 @@ namespace CarCenterDataBaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<int>("ManagerId")
.HasColumnType("int");
b.Property<DateTime?>("SaleDate")
.HasColumnType("datetime2");
b.Property<string>("SaleName")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -384,7 +387,7 @@ namespace CarCenterDataBaseImplement.Migrations
modelBuilder.Entity("CarCenterDataBaseImplement.Models.Completions", b =>
{
b.HasOne("CarCenterDataBaseImplement.Models.Administrator", "Administrator")
.WithMany("Equipments")
.WithMany("Completions")
.HasForeignKey("AdministratorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -450,8 +453,8 @@ namespace CarCenterDataBaseImplement.Migrations
.IsRequired();
b.HasOne("CarCenterDataBaseImplement.Models.Employee", "Employee")
.WithMany("Inspections")
.HasForeignKey("EmployeeId");
.WithOne("Inspection")
.HasForeignKey("CarCenterDataBaseImplement.Models.Inspection", "EmployeeId");
b.Navigation("Administrator");
@ -481,9 +484,7 @@ namespace CarCenterDataBaseImplement.Migrations
{
b.HasOne("CarCenterDataBaseImplement.Models.Completions", "Completions")
.WithOne("PreSaleWork")
.HasForeignKey("CarCenterDataBaseImplement.Models.PreSaleWork", "CompletionsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("CarCenterDataBaseImplement.Models.PreSaleWork", "CompletionsId");
b.HasOne("CarCenterDataBaseImplement.Models.Manager", "Manager")
.WithMany("PreSaleWorks")
@ -530,7 +531,7 @@ namespace CarCenterDataBaseImplement.Migrations
{
b.Navigation("Cars");
b.Navigation("Equipments");
b.Navigation("Completions");
b.Navigation("Inspections");
});
@ -551,7 +552,7 @@ namespace CarCenterDataBaseImplement.Migrations
modelBuilder.Entity("CarCenterDataBaseImplement.Models.Employee", b =>
{
b.Navigation("Inspections");
b.Navigation("Inspection");
b.Navigation("Sales");
});

View File

@ -118,10 +118,10 @@ namespace CarCenterDataBaseImplement.Migrations
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ManagerId = table.Column<int>(type: "int", nullable: false),
SaleName = table.Column<string>(type: "nvarchar(max)", nullable: false),
SaleDate = table.Column<DateTime>(type: "datetime2", nullable: true),
SalePrice = table.Column<double>(type: "float", nullable: false),
ManagerId = table.Column<int>(type: "int", nullable: false)
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
SalePrice = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
@ -170,7 +170,7 @@ namespace CarCenterDataBaseImplement.Migrations
PreSaleWorkPrice = table.Column<double>(type: "float", nullable: false),
PreSaleWorkDate = table.Column<DateTime>(type: "datetime2", nullable: false),
ManagerId = table.Column<int>(type: "int", nullable: false),
CompletionsId = table.Column<int>(type: "int", nullable: false)
CompletionsId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
@ -179,14 +179,13 @@ namespace CarCenterDataBaseImplement.Migrations
name: "FK_PreSaleWorks_Completions_CompletionsId",
column: x => x.CompletionsId,
principalTable: "Completions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
principalColumn: "Id");
table.ForeignKey(
name: "FK_PreSaleWorks_Managers_ManagerId",
column: x => x.ManagerId,
principalTable: "Managers",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@ -348,13 +347,16 @@ namespace CarCenterDataBaseImplement.Migrations
migrationBuilder.CreateIndex(
name: "IX_Inspections_EmployeeId",
table: "Inspections",
column: "EmployeeId");
column: "EmployeeId",
unique: true,
filter: "[EmployeeId] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_PreSaleWorks_CompletionsId",
table: "PreSaleWorks",
column: "CompletionsId",
unique: true);
unique: true,
filter: "[CompletionsId] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_PreSaleWorks_ManagerId",

View File

@ -220,7 +220,9 @@ namespace CarCenterDataBaseImplement.Migrations
b.HasIndex("AdministratorId");
b.HasIndex("EmployeeId");
b.HasIndex("EmployeeId")
.IsUnique()
.HasFilter("[EmployeeId] IS NOT NULL");
b.ToTable("Inspections");
});
@ -289,7 +291,7 @@ namespace CarCenterDataBaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CompletionsId")
b.Property<int?>("CompletionsId")
.HasColumnType("int");
b.Property<int>("ManagerId")
@ -309,7 +311,8 @@ namespace CarCenterDataBaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("CompletionsId")
.IsUnique();
.IsUnique()
.HasFilter("[CompletionsId] IS NOT NULL");
b.HasIndex("ManagerId");
@ -347,12 +350,12 @@ namespace CarCenterDataBaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<int>("ManagerId")
.HasColumnType("int");
b.Property<DateTime?>("SaleDate")
.HasColumnType("datetime2");
b.Property<string>("SaleName")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -381,7 +384,7 @@ namespace CarCenterDataBaseImplement.Migrations
modelBuilder.Entity("CarCenterDataBaseImplement.Models.Completions", b =>
{
b.HasOne("CarCenterDataBaseImplement.Models.Administrator", "Administrator")
.WithMany("Equipments")
.WithMany("Completions")
.HasForeignKey("AdministratorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -447,8 +450,8 @@ namespace CarCenterDataBaseImplement.Migrations
.IsRequired();
b.HasOne("CarCenterDataBaseImplement.Models.Employee", "Employee")
.WithMany("Inspections")
.HasForeignKey("EmployeeId");
.WithOne("Inspection")
.HasForeignKey("CarCenterDataBaseImplement.Models.Inspection", "EmployeeId");
b.Navigation("Administrator");
@ -478,9 +481,7 @@ namespace CarCenterDataBaseImplement.Migrations
{
b.HasOne("CarCenterDataBaseImplement.Models.Completions", "Completions")
.WithOne("PreSaleWork")
.HasForeignKey("CarCenterDataBaseImplement.Models.PreSaleWork", "CompletionsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("CarCenterDataBaseImplement.Models.PreSaleWork", "CompletionsId");
b.HasOne("CarCenterDataBaseImplement.Models.Manager", "Manager")
.WithMany("PreSaleWorks")
@ -527,7 +528,7 @@ namespace CarCenterDataBaseImplement.Migrations
{
b.Navigation("Cars");
b.Navigation("Equipments");
b.Navigation("Completions");
b.Navigation("Inspections");
});
@ -548,7 +549,7 @@ namespace CarCenterDataBaseImplement.Migrations
modelBuilder.Entity("CarCenterDataBaseImplement.Models.Employee", b =>
{
b.Navigation("Inspections");
b.Navigation("Inspection");
b.Navigation("Sales");
});

View File

@ -33,7 +33,7 @@ namespace CarCenterDataBaseImplement.Models
[ForeignKey("AdministratorId")]
public virtual List<Completions> Equipments { get; set; } = new();
public virtual List<Completions> Completions { get; set; } = new();
[ForeignKey("AdministratorId")]
public virtual List<CarSales> Cars { get; set; } = new();

View File

@ -21,6 +21,10 @@ namespace CarCenterDataBaseImplement.Models
public int ManagerId { get; private set; }
public virtual Manager Manager { get; set; }
public virtual Inspection? Inspection { get; set; }
[ForeignKey("EmployeeId")]
public virtual List<EmployeeSale> Sales { get; set; } = new();
private Dictionary<int, ISaleModel> _employeeSales = null;
@ -31,21 +35,12 @@ namespace CarCenterDataBaseImplement.Models
{
if (_employeeSales == null)
{
using var context = new CarCenterDataBase();
_employeeSales = Sales
.ToDictionary(x => x.SaleId, x => (context.Sales
.FirstOrDefault(y => y.Id == x.SaleId)! as ISaleModel));
_employeeSales = Sales.ToDictionary(recDP => recDP.SaleId, recDp => recDp.Sale as ISaleModel);
}
return _employeeSales;
}
}
[ForeignKey("EmployeeId")]
public virtual List<Inspection> Inspections { get; set; } = new();
[ForeignKey("EmployeeId")]
public virtual List<EmployeeSale> Sales { get; set; } = new();
public static Employee Create(CarCenterDataBase context, EmployeeBindingModel model)
{
return new Employee()

View File

@ -9,6 +9,8 @@ namespace CarCenterDataBaseImplement.Models
{
public class PreSaleWork : IPreSaleWorkModel
{
public int Id { get; private set; }
[Required]
public string PreSaleWorkType { get; set; } = string.Empty;
@ -19,12 +21,13 @@ namespace CarCenterDataBaseImplement.Models
public DateTime? PreSaleWorkDate { get; set; }
public int ManagerId { get; private set; }
public int CompletionsId { get; private set; }
public int Id { get; private set; }
public int? CompletionsId { get; private set; }
public virtual Manager Manager { get; set; }
public virtual Completions Completions { get; set; }
public virtual Completions? Completions { get; set; }
[ForeignKey("PreSaleWorkId")]
public virtual List<PreSaleWorkSale> Sales { get; set; } = new();
private Dictionary<int, ISaleModel> _PreSaleWorkSales = null;
@ -35,19 +38,13 @@ namespace CarCenterDataBaseImplement.Models
{
if (_PreSaleWorkSales == null)
{
using var context = new CarCenterDataBase();
_PreSaleWorkSales = Sales
.ToDictionary(x => x.SaleId, x => (context.Sales
.FirstOrDefault(y => y.Id == x.SaleId)! as ISaleModel));
_PreSaleWorkSales = Sales.ToDictionary(recDP => recDP.SaleId, recDP => (recDP.Sale as ISaleModel));
}
return _PreSaleWorkSales;
}
}
[ForeignKey("PreSaleWorkId")]
public virtual List<PreSaleWorkSale> Sales { get; set; } = new();
public static PreSaleWork Create(CarCenterDataBase context, PreSaleWorkBindingModel model)
public static PreSaleWork? Create(CarCenterDataBase context, PreSaleWorkBindingModel model)
{
return new PreSaleWork()
{
@ -57,6 +54,7 @@ namespace CarCenterDataBaseImplement.Models
PreSaleWorkDate = model.PreSaleWorkDate,
ManagerId = model.ManagerId,
CompletionsId = model.CompletionsId,
Completions = model.CompletionsId.HasValue ? context.Completions.FirstOrDefault(x => x.Id == model.CompletionsId) : null,
Sales = model.PreSaleWorkSales.Select(x => new PreSaleWorkSale
{
Sale = context.Sales.First(y => y.Id == x.Key),
@ -64,12 +62,25 @@ namespace CarCenterDataBaseImplement.Models
};
}
public static PreSaleWork Create(PreSaleWorkBindingModel model)
{
return new PreSaleWork
{
Id = model.Id,
PreSaleWorkType = model.PreSaleWorkType,
PreSaleWorkPrice = model.PreSaleWorkPrice,
PreSaleWorkDate = model.PreSaleWorkDate,
ManagerId = model.ManagerId,
CompletionsId = model.CompletionsId
};
}
public void Update(PreSaleWorkBindingModel model)
{
PreSaleWorkType = model.PreSaleWorkType;
PreSaleWorkPrice = model.PreSaleWorkPrice;
PreSaleWorkDate = model.PreSaleWorkDate;
CompletionsId = model.CompletionsId == null ? CompletionsId : model.CompletionsId;
}
public PreSaleWorkViewModel GetViewModel => new()
@ -80,6 +91,7 @@ namespace CarCenterDataBaseImplement.Models
PreSaleWorkDate = PreSaleWorkDate,
ManagerId=ManagerId,
CompletionsId= CompletionsId,
CompletionName = Completions?.СompletionName,
PreSaleWorkSales = PreSaleWorkSales
};

View File

@ -12,7 +12,7 @@ namespace CarCenterDataBaseImplement.Models
[Required]
public int PreSaleWorkId { get; set; }
public virtual PreSaleWork PreSaleWork { get; set; } = new();
public virtual Sale Sale { get; set; } = new();
public virtual PreSaleWork PreSaleWork { get; set; }
public virtual Sale Sale { get; set; }
}
}

View File

@ -8,16 +8,15 @@ namespace CarCenterDataBaseImplement.Models
{
public class Sale : ISaleModel
{
public int Id { get; set; }
public int ManagerId { get; set; }
[Required]
public string SaleName { get; set; } = string.Empty;
public DateTime? SaleDate { get; set; } = DateTime.Now;
[Required]
public DateTime DateCreate { get; set; } = DateTime.Now;
[Required]
public double SalePrice { get; set; }
public int ManagerId { get; private set; }
public int Id { get; private set; }
public virtual Manager Manager { get; set; }
[ForeignKey("SaleId")]
@ -37,7 +36,7 @@ namespace CarCenterDataBaseImplement.Models
{
Id = model.Id,
SaleName = model.SaleName,
SaleDate = model.SaleDate,
DateCreate = model.DateCreate,
SalePrice = model.SalePrice,
ManagerId = model.ManagerId,
};
@ -48,7 +47,7 @@ namespace CarCenterDataBaseImplement.Models
{
Id = model.Id,
SaleName = model.SaleName,
SaleDate = model.SaleDate,
DateCreate = model.DateCreate,
SalePrice = model.SalePrice,
ManagerId = model.ManagerId,
};
@ -60,14 +59,13 @@ namespace CarCenterDataBaseImplement.Models
return;
}
SaleName = model.SaleName;
SaleDate = model.SaleDate;
SalePrice = model.SalePrice;
}
public SaleViewModel GetViewModel => new()
{
Id = Id,
SaleName = SaleName,
SaleDate = SaleDate,
DateCreate = DateCreate,
SalePrice = SalePrice,
ManagerId = ManagerId
};

View File

@ -4,6 +4,6 @@
{
string SaleName { get; }
double SalePrice { get; }
DateTime SaleDate { get; }
DateTime DateCreate { get; }
}
}

View File

@ -66,7 +66,7 @@ namespace ImplementerApp.Controllers
Id = 1,
SaleName = "Sale1",
SalePrice = 100.5,
SaleDate = DateTime.Now,
DateCreate = DateTime.Now,
ManagerId = 1,
});
Sales.Add(new SaleViewModel
@ -74,7 +74,7 @@ namespace ImplementerApp.Controllers
Id = 2,
SaleName = "Sale2",
SalePrice = 600.0,
SaleDate = DateTime.Now,
DateCreate = DateTime.Now,
ManagerId = 2,
});
return View(Sales);
@ -114,7 +114,7 @@ namespace ImplementerApp.Controllers
Id = 1,
SaleName = "Sale1",
SalePrice = 100.5,
SaleDate = DateTime.Now,
DateCreate = DateTime.Now,
ManagerId = 1,
});
Sales.Add(new SaleViewModel
@ -122,7 +122,7 @@ namespace ImplementerApp.Controllers
Id = 2,
SaleName = "Sale2",
SalePrice = 600.0,
SaleDate = DateTime.Now,
DateCreate = DateTime.Now,
ManagerId = 2,
});
return View(Sales);
@ -135,7 +135,7 @@ namespace ImplementerApp.Controllers
Id = 1,
SaleName = "Sale1",
SalePrice = 100.5,
SaleDate = DateTime.Now,
DateCreate = DateTime.Now,
ManagerId = 1,
});
Sales.Add(new SaleViewModel
@ -143,7 +143,7 @@ namespace ImplementerApp.Controllers
Id = 2,
SaleName = "Sale2",
SalePrice = 600.0,
SaleDate = DateTime.Now,
DateCreate = DateTime.Now,
ManagerId = 2,
});
return View(Sales);
@ -186,13 +186,11 @@ namespace ImplementerApp.Controllers
new SalesPeriodReportViewModel
{
SaleName = "SaleName1",
Completions = new List<string> { "Completions1", "Completions2" },
Employee = new List<string> { "Employee1", "Employee2"},
},
new SalesPeriodReportViewModel
{
SaleName = "SaleName2",
Completions = new List<string> { "Completions3", "Completions4" },
Employee = new List<string> { "Employee3", "Employee4"},
}
};

View File

@ -16,7 +16,7 @@
</div>
<div class="row">
<div class="col-4">Дата продажи:</div>
<div class="col-8"><input type="date" name="saledate" id="saledate" /></div>
<div class="col-8"><input type="date" name="DateCreate" id="DateCreate" /></div>
</div>
<div class="row">
<div class="col-8"></div>

View File

@ -58,7 +58,7 @@
@Html.DisplayFor(modelItem => item.SalePrice)
</td>
<td>
@Html.DisplayFor(modelItem => item.SaleDate)
@Html.DisplayFor(modelItem => item.DateCreate)
</td>
<td>
<a asp-action="CreateSale" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>

View File

@ -37,12 +37,7 @@
</ul>
</td>
<td>
<ul>
@foreach (var completion in sales.Completions)
{
<li>@completion</li>
}
</ul>
</td>
</tr>
}