public async Task <ActionResult> PutService([FromForm] ServiceUM service) { var serviceList = _service.GetAll(_ => _.Gallery.Images); Service serviceUpdated = serviceList.FirstOrDefault(_ => _.Id == service.Id); Image imageUpdated = serviceUpdated.Gallery.Images.First(); imageUpdated.Description = "Hình " + service.ServiceName.ToLower(); imageUpdated.ImageUrl = await _uploadFileService.UploadFile("123456798", service.File, "service", "service-detail"); imageUpdated.GalleryId = (int)service.GalleryId; _imageService.Update(imageUpdated); await _imageService.Save(); try { serviceUpdated.Id = service.Id; serviceUpdated.Description = service.Description; serviceUpdated.ServiceName = service.ServiceName; serviceUpdated.Summary = service.Summary; serviceUpdated.Price = service.Price; serviceUpdated.EstimateTime = service.EstimateTime; serviceUpdated.Status = service.Status; serviceUpdated.UpdatedDate = DateTime.Now; serviceUpdated.AccountId = (int)service.AccountId; serviceUpdated.ServiceTypeId = (int)service.ServiceTypeId; serviceUpdated.GalleryId = (int)service.GalleryId; _service.Update(serviceUpdated); await _service.Save(); } catch (Exception e) { return(BadRequest(e)); } return(NoContent()); }
public ActionResult UpdateServiec([FromBody] ServiceUM model) { if (_serviceTypeService.GetServiceType(model.ServiceTypeId) == null) { return(NotFound(400)); } if (_storeService.GetStore(model.StoreId) == null) { return(NotFound(400)); } var service = _serviceService.GetService(model.Id); if (service == null) { return(NotFound(400)); } Services UServices = model.Adapt(service); _serviceService.UpdateService(UServices); _serviceService.Save(); return(Ok(200)); }