финалочка

This commit is contained in:
2024-05-29 16:41:49 +04:00
parent dbf7368333
commit c966ba26ab
6 changed files with 76 additions and 124 deletions

View File

@@ -4,6 +4,7 @@ using CarCenterContracts.BindingModels;
using CarCenterContracts.BusinessLogicsContracts; using CarCenterContracts.BusinessLogicsContracts;
using CarCenterContracts.SearchModels; using CarCenterContracts.SearchModels;
using CarCenterContracts.ViewModels; using CarCenterContracts.ViewModels;
using CarCenterDataBaseImplement;
using CarCenterDataBaseImplement.Models; using CarCenterDataBaseImplement.Models;
using CarCenterDataModels.Models; using CarCenterDataModels.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -468,14 +469,6 @@ namespace CarCenterAdministratorApp.Controllers
Response.Redirect("ListInspections"); Response.Redirect("ListInspections");
} }
/*public IActionResult AddCarToEquipment()
{
return View();
}
public IActionResult AddCarToInspection()
{
return View();
}*/
public IActionResult AddEquipmentToPreSaleWork() public IActionResult AddEquipmentToPreSaleWork()
{ {
if (APIClient.Administrator == null) if (APIClient.Administrator == null)
@@ -487,24 +480,38 @@ namespace CarCenterAdministratorApp.Controllers
return View(); return View();
} }
[HttpPost] [HttpPost]
public void AddEquipmentToPreSaleWork(int preSaleWork, int equipment) public void AddEquipmentToPreSaleWork(int preSaleWork, int equipment)
{ {
if (APIClient.Administrator == null) if (APIClient.Administrator == null)
{ {
throw new Exception("Необходима авторизация"); throw new Exception("Необходима авторизация");
} }
var equipmentElem = APIClient.GetRequest<EquipmentViewModel>($"api/main/getequipmentbyid?EquipmentId={equipment}");
APIClient.PostRequest("api/main/updateequipment", new EquipmentBindingModel using var context = new CarCenterDataBase();
{ List<int> cars = context.EquipmentCars
Id = equipment, .Where(rd => rd.EquipmentId == equipment)
PreSaleWorkId = preSaleWork, .Select(rd => rd.CarId)
EquipmentName = equipmentElem.EquipmentName, .ToList();
EquipmentPrice = equipmentElem.EquipmentPrice,
AdministratorId = equipmentElem.AdministratorId, Dictionary<int, ICarModel> a = new Dictionary<int, ICarModel>();
}); foreach (int car in cars)
Response.Redirect("ListEquipments"); {
} a.Add(car, new CarSearchModel { Id = car } as ICarModel);
}
var equipmentElem = APIClient.GetRequest<EquipmentViewModel>($"api/main/getequipmentbyid?EquipmentId={equipment}");
APIClient.PostRequest("api/main/updateequipment", new EquipmentBindingModel
{
Id = equipment,
PreSaleWorkId = preSaleWork,
EquipmentName = equipmentElem.EquipmentName,
EquipmentPrice = equipmentElem.EquipmentPrice,
AdministratorId = equipmentElem.AdministratorId,
EquipmentCars = a,
});
Response.Redirect("ListEquipments");
}
/*public IActionResult ListCarsToPdfFile() /*public IActionResult ListCarsToPdfFile()
@@ -624,7 +631,7 @@ namespace CarCenterAdministratorApp.Controllers
table += $"<td></td>"; table += $"<td></td>";
table += $"<td></td>"; table += $"<td></td>";
table += "</tr>"; table += "</tr>";
/*foreach (var equipment in car.Equipments) foreach (var equipment in car.Equipments)
{ {
table += "<tr>"; table += "<tr>";
table += $"<td>{equipment.DateCreateEquipment}</td>"; table += $"<td>{equipment.DateCreateEquipment}</td>";
@@ -636,13 +643,13 @@ namespace CarCenterAdministratorApp.Controllers
foreach (var employee in car.Employees) foreach (var employee in car.Employees)
{ {
table += "<tr>"; table += "<tr>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td>{employee.EmployeeFIO}</td>"; table += $"<td>{employee.EmployeeFIO}</td>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td>{employee.EmployeeInspection}</td>";
table += "</tr>"; table += "</tr>";
} }
table += "</tbody>";*/ table += "</tbody>";
} }
table += "</table>"; table += "</table>";
table += "</div>"; table += "</div>";

View File

@@ -42,7 +42,7 @@ namespace CarCenterBusinessLogic.BusinessLogics
_saveToWord.CreateDoc(new WordInfoAdministrator _saveToWord.CreateDoc(new WordInfoAdministrator
{ {
FileName = model.FileName, FileName = model.FileName,
Title = "Список покупок по медикаментам", Title = "Список предпродажных работ по машинам",
PreSaleWorkCars = GetPreSaleWorkCars(model) PreSaleWorkCars = GetPreSaleWorkCars(model)
}); });
} }

View File

@@ -43,16 +43,16 @@ namespace CarCenterBusinessLogic.OfficePackage
Style = "NormalTitle", Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center ParagraphAlignment = PdfParagraphAlignmentType.Center
}); });
/*foreach (var employee in car.Employees) foreach (var employee in car.Employees)
{ {
CreateRow(new PdfRowParameters CreateRow(new PdfRowParameters
{ {
Texts = new List<string> { employee.EmployeeFIO.ToString(), "", "", employee.Specialization }, Texts = new List<string> { "", "", "", employee.EmployeeFIO.ToString() },
Style = "Normal", Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center ParagraphAlignment = PdfParagraphAlignmentType.Center
}); });
}*/ }
/*foreach (var guidance in car.Equipments) foreach (var guidance in car.Equipments)
{ {
CreateRow(new PdfRowParameters CreateRow(new PdfRowParameters
{ {
@@ -60,7 +60,7 @@ namespace CarCenterBusinessLogic.OfficePackage
Style = "Normal", Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center ParagraphAlignment = PdfParagraphAlignmentType.Center
}); });
}*/ }
} }
SavePdf(info); SavePdf(info);
} }

View File

@@ -11,9 +11,9 @@ namespace CarCenterContracts.ViewModels
public string BrandCar { get; set; } = string.Empty; public string BrandCar { get; set; } = string.Empty;
public List<EmployeeViewModel> Employees { get; set; } public List<EmployeeViewModel> Employees { get; set; }
/*public List<EquipmentViewModel> Equipments { get; set; }*/ public List<EquipmentViewModel> Equipments { get; set; }
public List<InspectionViewModel> Inspections { get; set; } /*public List<InspectionViewModel> Inspections { get; set; }*/
} }
} }

View File

@@ -139,15 +139,22 @@ namespace CarCenterDataBaseImplement.Implements
} }
using var context = new CarCenterDataBase(); using var context = new CarCenterDataBase();
return context.Cars return context.Cars
.Where(car => model.carsIds == null || model.carsIds.Contains(car.Id)) .Where(car => model.carsIds.Contains(car.Id))
.Select(car => new ReportPreSaleWorkCarViewModel() .Select(car => new ReportPreSaleWorkCarViewModel
{ {
BrandCar = car.BrandCar, BrandCar = car.BrandCar,
/*PreSaleWorks = context.PreSaleWorks.Include(preSaleWork => preSaleWork.Equipments).ThenInclude(equipment => equipment.Cars) PreSaleWorks = context.PreSaleWorks
.Where(preSaleWork => preSaleWork.Equipments != null && preSaleWork.Equipments.Cars.Any(m => m.CarId == car.Id)) .Include(preSaleWork => preSaleWork.Equipments)
.Select(preSaleWork => preSaleWork.GetViewModel).ToList()*/ .ThenInclude(equipment => equipment.Cars)
}).ToList(); .Where(preSaleWork => preSaleWork.Equipments
} .SelectMany(equipment => equipment.Cars)
.Any(rd => rd.CarId == car.Id))
.Select(preSaleWork => preSaleWork.GetViewModel)
.ToList()
})
.ToList();
}
public List<ReportEquipmentsEmployeesViewModel> GetReportEquipmentsEmployees(ReportEquipmentsEmployeesSearchModel model) public List<ReportEquipmentsEmployeesViewModel> GetReportEquipmentsEmployees(ReportEquipmentsEmployeesSearchModel model)
{ {
@@ -156,16 +163,16 @@ namespace CarCenterDataBaseImplement.Implements
.Select(car => new ReportEquipmentsEmployeesViewModel() .Select(car => new ReportEquipmentsEmployeesViewModel()
{ {
BrandCar = car.BrandCar, BrandCar = car.BrandCar,
/* Inspections = context.Inspections Equipments = context.Equipments
.Where(equipment => equipment.InspectionDate <= model.DateTo && .Where(equipment => equipment.DateCreateEquipment <= model.DateTo &&
equipment.InspectionDate >= model.DateFrom && equipment.Cars.Any(m => m.CarId == car.Id)) equipment.DateCreateEquipment >= model.DateFrom && equipment.Cars.Any(m => m.CarId == car.Id))
.Select(equipment => equipment.GetViewModel) .Select(equipment => equipment.GetViewModel)
.ToList(),*/ .ToList(),
/* Employees = context.Inspections Employees = context.Inspections
.Include(service => service.Employee) .Include(service => service.Employee)
.Where(service => service.Employee != null && service.Cars.Any(m => m.CarId == car.Id)) .Where(service => service.Employee != null && service.Cars.Any(m => m.CarId == car.Id))
.Select(service => service.Employee.GetViewModel) .Select(service => service.Employee.GetViewModel)
.ToList(),*/ .ToList(),
}) })
.ToList(); .ToList();
return per; return per;

View File

@@ -14,23 +14,22 @@ namespace CarCenterDataBaseImplement.Models
{ {
public class Equipment : IEquipmentModel public class Equipment : IEquipmentModel
{ {
public int Id { get; private set; }
[Required] [Required]
public string EquipmentName { get; set; } = string.Empty; public string EquipmentName { get; set; } = string.Empty;
[Required] [Required]
public double EquipmentPrice { get; set; } public double EquipmentPrice { get; set; }
public DateTime DateCreateEquipment { get; set; } = DateTime.Now;
public int AdministratorId { get; private set; } public int AdministratorId { get; private set; }
public int? PreSaleWorkId { get; private set; } public int? PreSaleWorkId { get; private set; }
public int Id { get; private set; }
public DateTime DateCreateEquipment { get; private set; }
public virtual Administrator Administrator { get; set; } public virtual Administrator Administrator { get; set; }
public virtual PreSaleWork? PreSaleWork { get; set; } public virtual PreSaleWork? PreSaleWork { get; set; }
[ForeignKey("EquipmentId")] [ForeignKey("EquipmentId")]
public virtual List<EquipmentCar> Cars { get; set; } public virtual List<EquipmentCar> Cars { get; set; } = new();
private Dictionary<int, ICarModel> _equipmentCars = null; private Dictionary<int, ICarModel> _equipmentCars = null;
/*[NotMapped] /*[NotMapped]
@@ -66,39 +65,6 @@ namespace CarCenterDataBaseImplement.Models
} }
} }
/*public Dictionary<int, ICarModel> EquipmentCars
{
get
{
if (_equipmentCars == null)
{
if (Cars == null)
{
throw new InvalidOperationException("Cars collection is null.");
}
foreach (var car in Cars)
{
if (car == null)
{
throw new InvalidOperationException("One of the items in Cars collection is null.");
}
if (car.CarId == null)
{
throw new InvalidOperationException("One of the cars has a null CarId.");
}
if (car.Car == null)
{
throw new InvalidOperationException("One of the cars has a null Car property.");
}
}
_equipmentCars = Cars.ToDictionary(x => x.CarId, x => (x.Car as ICarModel));
}
return _equipmentCars;
}
}*/
public static Equipment Create(CarCenterDataBase context, EquipmentBindingModel model) public static Equipment Create(CarCenterDataBase context, EquipmentBindingModel model)
{ {
return new Equipment() return new Equipment()
@@ -106,9 +72,10 @@ namespace CarCenterDataBaseImplement.Models
Id = model.Id, Id = model.Id,
EquipmentName = model.EquipmentName, EquipmentName = model.EquipmentName,
EquipmentPrice = model.EquipmentPrice, EquipmentPrice = model.EquipmentPrice,
DateCreateEquipment = model.DateCreateEquipment,
AdministratorId = model.AdministratorId, AdministratorId = model.AdministratorId,
PreSaleWorkId = model.PreSaleWorkId, PreSaleWorkId = model.PreSaleWorkId,
DateCreateEquipment = model.DateCreateEquipment,
Cars = model.EquipmentCars.Select(x => new EquipmentCar Cars = model.EquipmentCars.Select(x => new EquipmentCar
{ {
@@ -132,7 +99,8 @@ namespace CarCenterDataBaseImplement.Models
AdministratorId = AdministratorId, AdministratorId = AdministratorId,
PreSaleWorkId = PreSaleWorkId, PreSaleWorkId = PreSaleWorkId,
EquipmentPrice = EquipmentPrice, EquipmentPrice = EquipmentPrice,
EquipmentCars = EquipmentCars EquipmentCars = EquipmentCars,
DateCreateEquipment = DateCreateEquipment,
}; };
public void UpdateCars(CarCenterDataBase context, EquipmentBindingModel model) public void UpdateCars(CarCenterDataBase context, EquipmentBindingModel model)
@@ -170,35 +138,5 @@ namespace CarCenterDataBaseImplement.Models
} }
_equipmentCars = null; _equipmentCars = null;
} }
/*public void UpdateCars(CarCenterDataBase context, EquipmentBindingModel model)
{
var equipmentCars = context.EquipmentCars.Where(rec => rec.EquipmentId == model.Id).ToList();
if (equipmentCars != null && equipmentCars.Count > 0)
{
context.EquipmentCars.RemoveRange(equipmentCars.Where(rec => !model.EquipmentCars.ContainsKey(rec.CarId)));
context.SaveChanges();
foreach (var updateCar in equipmentCars)
{
model.EquipmentCars.Remove(updateCar.CarId);
}
context.SaveChanges();
}
var equipment = context.Equipments.First(x => x.Id == Id);
foreach (var ec in model.EquipmentCars)
{
context.EquipmentCars.Add(new EquipmentCar
{
Equipment = equipment,
Car = context.Cars.First(x => x.Id == ec.Key),
});
context.SaveChanges();
}
_equipmentCars = null;
}*/
} }
} }