public WorkingPoint AddWorkingPoint(WorkingPoint WorkingPoint) { VehicleServiceCompany CurrentService = ServiceBookContext.VehicleServiceCompany.FirstOrDefault(x => x.ID == WorkingPoint.VSCID); WorkingPoint workingpoint = ServiceBookContext.WorkingPoint.FirstOrDefault(x => x.City == WorkingPoint.City && x.Country == WorkingPoint.Country && x.Street == WorkingPoint.Street && x.Nr == WorkingPoint.Nr); if (workingpoint != null) { if (workingpoint.Flag == 0) { return(null); } else { workingpoint.VehicleServiceCompany = CurrentService; workingpoint.Flag = 0; ServiceBookContext.SaveChanges(); WorkingPoint = workingpoint; } } else { WorkingPoint.VehicleServiceCompany = CurrentService; WorkingPoint.Flag = 0; ServiceBookContext.WorkingPoint.Add(WorkingPoint); ServiceBookContext.SaveChanges(); } return(WorkingPoint); }
public int EditServiceCompany(VehicleServiceCompany VehicleServiceCompany) { VehicleServiceCompany vehicleServiceCompany = ServiceBookContext.VehicleServiceCompany.FirstOrDefault(x => x.ServiceName == VehicleServiceCompany.ServiceName); if (vehicleServiceCompany == null) { vehicleServiceCompany = ServiceBookContext.VehicleServiceCompany.FirstOrDefault(x => x.ID == VehicleServiceCompany.ID); vehicleServiceCompany.ServiceName = VehicleServiceCompany.ServiceName; ServiceBookContext.SaveChanges(); return(1); } return(0); }
public ServiceIntervention AddIntervention(ServiceIntervention ServiceIntervention) { WorkingPoint WorkingPoint=ServiceBookContext.WorkingPoint.FirstOrDefault(x => x.ID == ServiceIntervention.WP); ServiceIntervention serviceIntervention = WorkingPoint.ServiceInterventions.FirstOrDefault(x => x.Name == ServiceIntervention.Name); if (serviceIntervention == null) { ServiceIntervention.WorkingPoint = WorkingPoint; ServiceIntervention.Currency = new Currency(); ServiceIntervention.Currency.Name = "Euro"; ServiceIntervention.Flag = 0; ServiceBookContext.ServiceIntervention.Add(ServiceIntervention); ServiceBookContext.SaveChanges(); return ServiceIntervention; } else return null; }
public Employee AddEmployee(Employee Employee) { WorkingPoint WorkingPoint = ServiceBookContext.WorkingPoint.FirstOrDefault(x => x.ID == Employee.WPID); Employee employee = WorkingPoint.Employees.FirstOrDefault(x => x.PhoneNumber == Employee.PhoneNumber); if (employee == null) { Employee.Flag = 0; WorkingPoint.Employees.Add(Employee); ServiceBookContext.SaveChanges(); return(Employee); } else { return(null); } }
public VehicleOwner AddReview(int ID, string Review, int Rate) { Service Service = ServiceBookContext.Service.FirstOrDefault(x => x.ID == ID); if (Service.Review == null) { Service.Review = new Review(); Service.Review.Rate = Rate; Service.Review.Service = Service; } Service.Review.Description += "\n" + Review; ServiceBookContext.SaveChanges(); VehicleOwner VehicleOwner = Service.Vehicle.VehicleOwner; return(VehicleOwner); }
public void DeletVehicleServiceCompany(string uid, VehicleServiceCompany VehicleServiceCompany) { VehicleServiceCompanyOwner CurrentOwner = ServiceBookContext.VehicleServiceCompanyOwner.FirstOrDefault(x => x.UID == uid); CCO deletVehicleServiceCompany = ServiceBookContext.CCO.FirstOrDefault(x => x.COID == CurrentOwner.ID && x.CID == VehicleServiceCompany.ID); if (deletVehicleServiceCompany.VehicleServiceCompany != null) { if (deletVehicleServiceCompany.VehicleServiceCompany.WorkingPoints != null) { foreach (var workingPoint in deletVehicleServiceCompany.VehicleServiceCompany.WorkingPoints) { WorkingPointRepository.DeletWorkingPoint(workingPoint); } } } ServiceBookContext.CCO.Remove(deletVehicleServiceCompany); ServiceBookContext.SaveChanges(); }
public double SaveRepaire(Service Service) { Service service = ServiceBookContext.Service.FirstOrDefault(x => x.ID == Service.ID); if (service != null) { if (service.SSI != null) { foreach (var ssi in service.SSI.ToList()) { ServiceBookContext.SSI.Remove(ssi); } } } if (service != null) { if (service.SE != null) { foreach (var se in service.SE.ToList()) { ServiceBookContext.SE.Remove(se); } } } double price = 0; service.NextVisitKm = Service.NextVisitKm; service.NextVisitDate = Service.NextVisitDate; service.CurrentKm = Service.CurrentKm; service.ServiceDate = DateTime.Now; if (Service.SSI != null) { foreach (var ssi in Service.SSI) { ssi.Service = service; ServiceIntervention serviceIntervention = ServiceBookContext.ServiceIntervention.FirstOrDefault(x => x.ID == ssi.ServiceIntervention.ID); if (serviceIntervention != null) { ssi.ServiceIntervention = serviceIntervention; price += ssi.ServiceIntervention.Price; ServiceBookContext.SSI.Add(ssi); } } } service.Price = price; if (Service.SE != null) { foreach (var se in Service.SE) { se.Service = service; Employee Employee = ServiceBookContext.Employee.FirstOrDefault(x => x.ID == se.Employee.ID); if (Employee != null) { se.Employee = Employee; ServiceBookContext.SE.Add(se); } } } ServiceBookContext.SaveChanges(); return(price); }
public void SaveChanges() { dbContext.SaveChanges(); }