Beispiel #1
0
        public async Task <IActionResult> AddAsync(RedirectMetadata model)
        {
            if (!ModelState.IsValid)
            {
                model.ErrorMessage = "Invalid options, confirm form validation";
                return(View("Add", model));
            }

            var redirect = model.ToRedirect();

            var success = await _redirectService.TryCreateAsync(redirect);

            if (success)
            {
                return(RedirectToAction("List", new { highlightId = redirect.RedirectId }));
            }

            if (redirect.RedirectId == -1)
            {
                model.ErrorMessage = "A link with that name already exists.";
                return(View("Add", model));
            }

            model.ErrorMessage = "Unknown problem happened. Try again?";
            return(View("Add", model));
        }
        public void RedirectFromMetadataRedirectWorks()
        {
            var model = new RedirectMetadata()
            {
                Name        = "Name",
                Description = "Description",
                Target      = "https://target.com"
            };

            var redirect = model.ToRedirect();

            Assert.AreEqual("Name", redirect.Name);
            Assert.AreEqual("Description", redirect.Description);
            Assert.AreEqual("https://target.com", redirect.Target);
        }