Ejemplo n.º 1
0
        public IActionResult Register(URLRegisterViewModel urlToRegister)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var exists = UrlService.GetURLByShortURL(urlToRegister.ShortUrl) is not null;

            if (exists)
            {
                ModelState.AddModelError("ShortUrl", "Short URL is already taken");
                return(View());
            }
            var domainModel = ModelHelper.GetURLDomainModel(urlToRegister);

            UrlService.AddURL(domainModel);
            var registerSuccessModel = ModelHelper
                                       .GetURLRegistrationSuccessfulViewModel(urlToRegister, HttpContext);

            return(View("RegisterSuccess", registerSuccessModel));
        }