Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
        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));
            }
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
 public Task UpdatePhotoAsync(UpdatePhotoDTO updatePhotoDTO)
 {
     return(_elasticService.UpdatePhotoAsync(updatePhotoDTO.Id, updatePhotoDTO));
 }