public async Task <SingleCar> UpdateCarAsync(SingleCar car) { if (!await _context.Cars.AnyAsync(c => c.VehicleIdentification == car.VehicleIdentification).ConfigureAwait(false)) { // car doesn't exist. We need to add the car not update the car return(await AddCarAsync(car, true).ConfigureAwait(false)); } var model = await _context.Models.SingleOrDefaultAsync(m => m.ModelName == car.Model).ConfigureAwait(false) ?? await AddModel(car.Model, car.Make).ConfigureAwait(false); var updatedCar = _mapper.Map <Car>(car); updatedCar.Model = model; updatedCar.LastUpdated = DateTime.UtcNow; _context.Cars.Attach(updatedCar); var entry = _context.Entry(updatedCar); entry.State = EntityState.Modified; entry.Property(nameof(Car.ScannedDate)).IsModified = false; entry.Property(nameof(Car.LastScanned)).IsModified = false; updatedCar.Photos = await _photoService.UploadPictures(car.Pictures.Where(c => !c.IsDeleted)).ConfigureAwait(false); await _photoService.UpdateDeletedPhotos(car.Pictures.Where(c => c.IsDeleted)).ConfigureAwait(false); await _context.SaveChangesAsync().ConfigureAwait(false); return(car); }
public ActionResult Save(Guid?id, WorkOrder input) { using (var context = new WorkOrderContext()) { context.Entry(input).State = System.Data.EntityState.Modified; context.SaveChanges(); return(RedirectToAction("Index")); } }
public async Task UpdateWorkOrder(SingleWorkOrder workOrder) { if (workOrder.Id is null) { await AddWorkOrder(workOrder).ConfigureAwait(false); return; } var wo = _mapper.Map <WorkOrder>(workOrder); _context.WorkOrders.Attach(wo); var entry = _context.Entry(wo); entry.State = EntityState.Modified; entry.Property(nameof(WorkOrder.DateAdded)).IsModified = false; wo.UserAdded = await GetUser().ConfigureAwait(false); wo.LastUpdated = DateTime.UtcNow; wo.Photos = await _photoService.UploadPictures(workOrder.Pictures.Where(p => !p.IsDeleted)).ConfigureAwait(false); await _photoService.UpdateDeletedPhotos(workOrder.Pictures.Where(p => p.IsDeleted)).ConfigureAwait(false); await _context.SaveChangesAsync().ConfigureAwait(false); }
public ActionResult Save(Guid? id, WorkOrder input) { using (var context = new WorkOrderContext()) { context.Entry(input).State = System.Data.EntityState.Modified; context.SaveChanges(); return RedirectToAction("Index"); } }