финалочка

This commit is contained in:
Nastya_Kozlova 2024-05-29 16:41:49 +04:00
parent dbf7368333
commit c966ba26ab
6 changed files with 76 additions and 124 deletions
CarCenter
CarCenterAdministratorApp/Controllers
CarCenterBusinessLogic
CarCenterContracts/ViewModels
CarCenterDataBaseImplement

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

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

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

@ -11,9 +11,9 @@ namespace CarCenterContracts.ViewModels
public string BrandCar { get; set; } = string.Empty;
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; }*/
}
}

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

@ -14,23 +14,22 @@ namespace CarCenterDataBaseImplement.Models
{
public class Equipment : IEquipmentModel
{
public int Id { get; private set; }
[Required]
public string EquipmentName { get; set; } = string.Empty;
[Required]
public double EquipmentPrice { get; set; }
public DateTime DateCreateEquipment { get; set; } = DateTime.Now;
public int AdministratorId { 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 PreSaleWork? PreSaleWork { get; set; }
[ForeignKey("EquipmentId")]
public virtual List<EquipmentCar> Cars { get; set; }
public virtual List<EquipmentCar> Cars { get; set; } = new();
private Dictionary<int, ICarModel> _equipmentCars = null;
/*[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)
{
return new Equipment()
@ -106,9 +72,10 @@ namespace CarCenterDataBaseImplement.Models
Id = model.Id,
EquipmentName = model.EquipmentName,
EquipmentPrice = model.EquipmentPrice,
DateCreateEquipment = model.DateCreateEquipment,
AdministratorId = model.AdministratorId,
PreSaleWorkId = model.PreSaleWorkId,
DateCreateEquipment = model.DateCreateEquipment,
Cars = model.EquipmentCars.Select(x => new EquipmentCar
{
@ -132,7 +99,8 @@ namespace CarCenterDataBaseImplement.Models
AdministratorId = AdministratorId,
PreSaleWorkId = PreSaleWorkId,
EquipmentPrice = EquipmentPrice,
EquipmentCars = EquipmentCars
EquipmentCars = EquipmentCars,
DateCreateEquipment = DateCreateEquipment,
};
public void UpdateCars(CarCenterDataBase context, EquipmentBindingModel model)
@ -170,35 +138,5 @@ namespace CarCenterDataBaseImplement.Models
}
_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;
}*/
}
}