public async Task <ActionResult <LinkBundle> > PostLinkBundleAsync(LinkBundle linkBundle) { if (linkBundle.Links.Count() == 0) { var problemDetails = new ProblemDetails() { Title = "Payload is invalid", Detail = "No links are provided", Status = StatusCodes.Status400BadRequest, Type = "/linkylink/clientissue", Instance = Request.Path }; return(new BadRequestObjectResult(problemDetails)); } string userHandle = _linksService.GetUserAccountEmail(); linkBundle.UserId = userHandle; ValidateVanityUrl(linkBundle); string vanity_regex = @"^([\w\d-])+(/([\w\d-])+)*$"; Match match = Regex.Match(linkBundle.VanityUrl, vanity_regex, RegexOptions.IgnoreCase); if (!match.Success) { return(new BadRequestResult()); } try { await _linksService.CreateLinkBundleAsync(linkBundle); } catch (DbUpdateException) { if (await _linksService.LinkBundleExistsAsync(linkBundle.Id)) { return(Conflict()); } else { throw; } } catch (Exception) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } return(CreatedAtAction("GetLinkBundle", new { vanityUrl = linkBundle.VanityUrl }, linkBundle)); }
public async Task <ActionResult <LinkBundle> > PostLinkBundleAsync(LinkBundle linkBundle) { if (linkBundle.Links.Count() == 0) { return(BadRequest("Invalid Payload. No Links are provided with LinkBundle.")); } string userHandle = _linksService.GetUserAccountEmail(); linkBundle.UserId = userHandle; ValidateVanityUrl(linkBundle); string vanity_regex = @"^([\w\d-])+(/([\w\d-])+)*$"; Match match = Regex.Match(linkBundle.VanityUrl, vanity_regex, RegexOptions.IgnoreCase); if (!match.Success) { return(BadRequest("Invalid Payload. Vanity Url name is invalid.")); } try { await _linksService.CreateLinkBundleAsync(linkBundle); } catch (DbUpdateException) { if (await _linksService.LinkBundleExistsAsync(linkBundle.Id)) { return(Conflict()); } else { throw; } } catch (Exception) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } return(CreatedAtAction("GetLinkBundle", new { vanityUrl = linkBundle.VanityUrl }, linkBundle)); }