コード例 #1
0
        public async Task <IActionResult> OnPostUpdateAsync()
        {
            var link = await _linksService.FindByIdAsync(Vm.LinkId);

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

            var exists = await _linksService.ExistsAsync(Vm.Name);

            if (exists && !Vm.Name.CompleteTrimAndUpper().Equals(link.UniqueNameIdentifier))
            {
                ModelState.AddModelError(string.Empty, TranslationsService.TranslateErrorByDescriber(ErrorDescriberConstants.NameDuplicate, $"The name {Vm.Name} is already taken.", Vm.Name));
                return(await OnGetAsync(link.Id));
            }

            link.Name = Vm?.Name;
            link.Url  = Vm?.Url;

            var result = await _linksService.UpdateAsync(link);

            if (result.Successfull)
            {
                return(RedirectToPage("/WebPage/UpdateLink", new { id = link.Id }));
            }

            foreach (var err in result.Errors)
            {
                ModelState.AddModelError(string.Empty, err.Message);
            }

            return(await OnGetAsync(link.Id));
        }
コード例 #2
0
        public async Task <IActionResult> OnPostVerifyNotExistsAsync()
        {
            var exists = await Service.ExistsAsync(Name);

            if (exists)
            {
                return(new JsonResult(TranslationsService.TranslateErrorByDescriber(ErrorDescriberConstants.NameDuplicate, $"The name '{Name}' is already taken.", Name)));
            }
            return(new JsonResult(true));
        }