Exemple #1
0
        public async Task <IHttpActionResult> Put(int id, UpdateAlbumRequestModel model)
        {
            var currentUserId = this.User.Identity.GetUserId();
            var imageAuthorId = await this.albumsService.GetAlbumCreatorIdById(id);

            var isCurrenUserAlbum = currentUserId == imageAuthorId;

            if (!isCurrenUserAlbum)
            {
                return(this.Unauthorized(AuthenticationHeaderValue.
                                         Parse(string.Format(ErrorMessages.UnoutorizedAccess, EntityName))));
            }

            var tags = await this.tagsService.TagsFromCommaSeparatedValues(model.Tags);

            var images = await this.imagesService.ImagesFromCommaSeparatedIds(model.ImagesIds);

            var changesMade = await this.albumsService.Update(
                id,
                model.Name,
                model.IsPrivate,
                tags,
                images);

            if (changesMade == GlobalConstants.ItemNotFoundReturnValue)
            {
                return(this.NotFound());
            }

            return(this.Ok(changesMade));
        }
Exemple #2
0
        public async Task <IActionResult> Put(int artistId, int id, UpdateAlbumRequestModel model)
        {
            var album = await this.context.Album.FindAsync(id);

            if (album == null)
            {
                return(this.NotFound());
            }

            album.UpdateWith(model);

            this.context.Album.Update(album);
            await this.context.SaveChangesAsync();

            return(this.NoContent());
        }
Exemple #3
0
 public static void UpdateWith(this Album album, UpdateAlbumRequestModel model)
 {
     album.Title = model.Title;
 }