public async Task <string> CompleteTheOrderByCarIdAsync(string carId) { try { this.ValidateNullOrEmptyString(carId); var carFromDb = await this.carRepository .All() .Include(car => car.Services) .FirstOrDefaultAsync(car => car.Id == carId); var serviceResult = await this.serviceIntervention.FinishServiceByIdAsync(carFromDb.ServiceId); if (serviceResult == default(int)) { return(null); } var newService = new ServiceIntervention(); carFromDb.IsFinished = false; carFromDb.Description = default; carFromDb.ServiceId = newService.Id; carFromDb.Services.Add(newService); await this.carRepository.SavaChangesAsync(); return(carFromDb.CustomerId); } catch { return(null); } }
public async Task <ActionResult> Create([Bind(Include = "ServiceInterventionId,ModuleId,InterventionStart,InterventionEnd,ReceiptsFiscalCountStart,ReceiptsFiscalCountEnd,FiscalDailyReportStart,FiscalDailyReportEnd,ResettingRamCountStart,ResettingRamCountEnd,ReceiptsCountAllStart,ReceiptsCountAllEnd,ProblemsDescrtiption,SealCount,SealCondition,RepairedComponents,FiscalDocPrinted,WhyCantRepairAtCustomer,PlaceOfRepair,ConfirmationOfReceipt,ServiceBookPageNumber")] ServiceIntervention serviceIntervention) { if (ModelState.IsValid) { db.ServiceInterventions.Add(serviceIntervention); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ModuleId = new SelectList(db.Modules, "ModuleId", "UniqueNumber", serviceIntervention.ModuleId); return(View(serviceIntervention)); }
public async Task <int> CreateAsync ( string customerId, string vin, string registrationPLate, string manufactirerId, string modelName, int kilometers, int yearOfManufacture, string engineModel, int engineHorsePower, string fuelTypeId, string transmissionId) { if (await this.carRepository.All().AnyAsync(car => car.Vin == vin || car.RegistrationPlate == registrationPLate)) { return(CarConstants.ExistingVinOrRegistrationPlateIntValue); } try { var modelId = (await this.modelServices.GetByNameAsync(modelName)).Id; var service = new ServiceIntervention(); var car = new Car { CustomerId = customerId, Vin = vin, RegistrationPlate = registrationPLate, MakeId = manufactirerId, ModelId = modelId, Кilometers = kilometers, YearOfManufacturing = yearOfManufacture, EngineModel = engineModel, EngineHorsePower = engineHorsePower, FuelTypeId = fuelTypeId, TransmissionId = transmissionId, ServiceId = service.Id, }; car.Services.Add(service); this.ValidateEntityState(car); return(await this.carRepository.CreateAsync(car)); } catch { return(default(int)); } }
// GET: /ServiceInterventions/Create public ActionResult Create(int?deviceId) { var module = db.Modules.Include(d => d.Device.DevicesFolder).Where(d => d.DeviceId == deviceId).Where(m => m.Active == true).FirstOrDefault(); if (module == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ServiceIntervention newService = new ServiceIntervention(); newService.ModuleId = module.ModuleId; return(View(newService)); }
// GET: /ServiceInterventions/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ServiceIntervention serviceIntervention = await db.ServiceInterventions.FindAsync(id); if (serviceIntervention == null) { return(HttpNotFound()); } ViewBag.ModuleId = new SelectList(db.Modules, "ModuleId", "UniqueNumber", serviceIntervention.ModuleId); return(View(serviceIntervention)); }
// GET: /ServiceInterventions/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ServiceIntervention serviceIntervention = await db.ServiceInterventions.FindAsync(id); if (serviceIntervention == null) { return(HttpNotFound()); } return(View(serviceIntervention)); }
public ServiceIntervention EditServiceIntervention(ServiceIntervention ServiceIntervention) { ServiceIntervention EditServiceIntervention = ServiceBookContext.ServiceIntervention.FirstOrDefault(x => x.ID == ServiceIntervention.ID); ServiceIntervention edit = EditServiceIntervention.WorkingPoint.ServiceInterventions.FirstOrDefault(x => x.Name == ServiceIntervention.Name); if (edit==null || edit.ID==EditServiceIntervention.ID ) { EditServiceIntervention.Name = ServiceIntervention.Name; EditServiceIntervention.Price = ServiceIntervention.Price; ServiceBookContext.SaveChanges(); return EditServiceIntervention; } else { return null; } }
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 async Task <ActionResult> DeleteConfirmed(int id) { ServiceIntervention serviceIntervention = await db.ServiceInterventions.FindAsync(id); db.ServiceInterventions.Remove(serviceIntervention); try { await db.SaveChangesAsync(); } catch (DbUpdateException /*ex*/) { string errorMessage = ""; errorMessage = "Nie można usunąć rekordu, ponieważ jest powiązany z innymi rekordami w bazie danych"; ModelState.AddModelError(String.Empty, errorMessage); return(PartialView(serviceIntervention)); } return(Json(new { url = Url.Action("Index", "ServiceInterventions"), success = true })); }
public void DeletServiceIntervention(ServiceIntervention ServiceIntervention) { ServiceIntervention DeletServiceIntervention = ServiceBookContext.ServiceIntervention.FirstOrDefault(x => x.ID == ServiceIntervention.ID); DeletServiceIntervention.Flag = 1; 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); }
private static void SeedCars(GMDbContext dbContext) { var random = new Random(); var customerIds = dbContext.Customers .OrderBy(customer => customer.FullName) .Select(customer => customer.Id) .Take(SeedConstants.CountOfCustomersToSeedWithCars) .ToList(); var fuelTypes = dbContext.FuelTypes .Select(type => type.Id) .ToList(); var transmissionTypes = dbContext.TransmissionTypes .Select(type => type.Id) .ToList(); var manufactuters = dbContext.VehicleManufacturers .ToList();; var models = dbContext.VehicleModels .ToList(); var vins = GetCarVins(); var registrationPlates = GetCarRegistrationPlates(); var horsePowerValues = GetCarEngineHorsePowerValues(); var yearsOfManufacturing = GetCarYearsOfManufacturing(); var engineModels = GetCarEnginModels(); var kilometValues = GetCarKilometersValues(); var cars = new List <Car>(); var services = new List <ServiceIntervention>(); foreach (var customerId in customerIds) { for (int i = 0; i < 20; i++) { var manufacturer = manufactuters[random.Next(0, manufactuters.Count - 1)]; var manufacturerModels = models .Where(m => m.ManufactirerId == manufacturer.Id) .ToList(); if (!manufacturerModels.Any()) { continue; } var model = manufacturerModels[random.Next(0, manufacturerModels.Count - 1)]; var fuelTypeId = fuelTypes[random.Next(0, fuelTypes.Count)]; var transmissionId = transmissionTypes[random.Next(0, transmissionTypes.Count - 1)]; var registrationPLate = registrationPlates[random.Next(0, registrationPlates.Count - 1)]; var yearOfManufacturing = yearsOfManufacturing[random.Next(0, yearsOfManufacturing.Count - 1)]; var vin = vins[random.Next(0, vins.Count - 1)]; var horsePoerValue = horsePowerValues[random.Next(0, horsePowerValues.Count - 1)]; var engineModel = engineModels[random.Next(0, engineModels.Count - 1)]; var kilometerVaue = kilometValues[random.Next(0, kilometValues.Count - 1)]; var service = new ServiceIntervention(); var car = new Car { CustomerId = customerId, Vin = vin, RegistrationPlate = registrationPLate, MakeId = manufacturer.Id, ModelId = model.Id, FuelTypeId = fuelTypeId, TransmissionId = transmissionId, YearOfManufacturing = yearOfManufacturing, EngineHorsePower = horsePoerValue, EngineModel = engineModel, Кilometers = kilometerVaue, ServiceId = service.Id }; service.CarId = car.Id; cars.Add(car); services.Add(service); } } dbContext.ServiceInterventions.AddRange(services); dbContext.Cars.AddRange(cars); dbContext.SaveChanges(); }