Example #1
0
        public async Task <ActionResult <LinkBundle> > PatchLinkBundleAsync(string vanityUrl, JsonPatchDocument <LinkBundle> linkBundle)
        {
            string userHandle = _linksService.GetUserAccountEmail();

            if (string.IsNullOrEmpty(userHandle))
            {
                return(Unauthorized());
            }

            var linkBundleEntry = await _linksService.FindLinkBundleAsync(vanityUrl);

            if (linkBundleEntry == null)
            {
                return(NotFound());
            }

            if (!userHandle.Equals(linkBundleEntry.UserId, StringComparison.InvariantCultureIgnoreCase))
            {
                return(Forbid());
            }

            try
            {
                linkBundle.ApplyTo(linkBundleEntry, ModelState);

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                await _linksService.UpdateLinkBundleAsync(linkBundleEntry);
            }
            catch (Exception)
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }

            return(NoContent());
        }