public async Task <NotificationActionResult <PhotoViewDTO> > Update(UpdatePhotoDTO updatePhotoDTO) { await _photoService.UpdatePhotoAsync(updatePhotoDTO); PhotoViewDTO updatedPhoto = await _photoService.GetPhotoOrDefaultAsync(updatePhotoDTO.Id); return(this.Notify(updatedPhoto).As(NotificationType.Success).WithMessage("Updated successfully")); }
/// <summary> /// Update a photo. /// </summary> /// <param name="updatePhotoDTO">Details to be updated.</param> /// <param name="id">Id of the photo to be updated.</param> /// <returns>Returns updated photo or an appropriate error message.</returns> public async Task <PhotoDTO> UpdateAsync(UpdatePhotoDTO updatePhotoDTO, Guid id) { var photo = await FindPhotoAsync(id); photo.Title = updatePhotoDTO.Title ?? photo.Title; photo.Description = updatePhotoDTO.Description ?? photo.Description; photo.PhotoUrl = updatePhotoDTO.PhotoUrl ?? photo.PhotoUrl; photo.ModifiedOn = DateTime.UtcNow; await this.dbContext.SaveChangesAsync(); return(new PhotoDTO(photo)); }
public async Task <IActionResult> UpdateAsync([FromBody] UpdatePhotoDTO updateModel, Guid id) { try { var photo = await this.photoService.UpdateAsync(updateModel, id); return(Ok(photo)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> Edit(Guid id, EditPhotoViewModel model) { if (ModelState.IsValid) { try { var updateDTO = new UpdatePhotoDTO() { Title = model.Title, Description = model.Description }; var photo = await this.photoService.UpdateAsync(updateDTO, id); return(RedirectToAction(nameof(Index))); } catch (Exception e) { toastNotification.AddErrorToastMessage(e.Message, new NotyOptions()); var path = Request.Path.Value.ToString() + model.Id; return(Redirect(path)); } } return(View(model)); }
public Task UpdatePhotoAsync(UpdatePhotoDTO updatePhotoDTO) { return(_elasticService.UpdatePhotoAsync(updatePhotoDTO.Id, updatePhotoDTO)); }