Esempio n. 1
0
        public async Task <IHttpActionResult> Put(UpdateImageRequestModel model)
        {
            var currentUserId = this.User.Identity.GetUserId();
            var imageAuthorId = await this.imagesService.GetImageAuthorIdById(model.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 albus = await this.albumssService.AlbumsFromCommaSeparatedValuesAndUserId(model.Albums, currentUserId);

            var changesMade = await this.imagesService.Update(
                model.Id,
                model.Title,
                model.IsPrivate,
                model.Description,
                tags,
                albus);

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

            return(this.Ok(changesMade));
        }
Esempio n. 2
0
        public async Task<IHttpActionResult> Put(UpdateImageRequestModel model)
        {
            var currentUserId = this.User.Identity.GetUserId();
            var imageAuthorId = await this.imagesService.GetImageAuthorIdById(model.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 albus = await this.albumssService.AlbumsFromCommaSeparatedValuesAndUserId(model.Albums, currentUserId);

            var changesMade = await this.imagesService.Update(
                model.Id,
                model.Title,
                model.IsPrivate,
                model.Description,
                tags,
                albus);

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

            return this.Ok(changesMade);
        }