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);
        }
Exemplo n.º 2
0
        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"));
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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");
            }
        }