Exemplo n.º 1
0
        public async Task <IActionResult> Create([FromBody] ShortLinkModel shortLink)
        {
            if (!shortLink.ValidateIdent())
            {
                return(BadRequest(ErrorModel.BadRequest("invalid short ident")));
            }

            if (!CheckShortIdent(shortLink))
            {
                return(BadRequest(ErrorModel.BadRequest("short ident already in use")));
            }

            if (!await shortLink.ValidateURI())
            {
                return(BadRequest(ErrorModel.BadRequest("invalid root link")));
            }

            shortLink.Sanitize(asNew: true);

            Db.ShortLinks.Add(shortLink);
            await Db.SaveChangesAsync();

            return(Created(shortLink.GUID.ToString(), shortLink));
        }