Пример #1
0
        public async Task <IActionResult> Update(RecipientUpdateInputViewModel inputViewModel)
        {
            if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName))
            {
                return(this.Redirect("/Identity/Account/AccessDenied"));
            }

            if (!this.ModelState.IsValid)
            {
                var error = new RecipientError();
                error.ErrorMessage = GlobalConstants.RecipientUpdateModelValidationMessege;
                return(this.RedirectToAction("Error", "Recipient", error));
            }

            var dtoModel = RecipientUpdateInputMapper.Map(inputViewModel);
            var isSame   = await this.recipientService.UpdateRecipientAsync(dtoModel);

            if (!isSame)
            {
                var error = new RecipientError();
                error.ErrorMessage = GlobalConstants.RecipientUpdateSameModelMessege;
                return(this.RedirectToAction("Error", "Recipient", error));
            }

            return(this.Redirect("/Recipient/Index"));
        }
Пример #2
0
        public static RecipientUpdateInputDtoModel Map(RecipientUpdateInputViewModel viewModel)
        {
            var dtoModel = new RecipientUpdateInputDtoModel
            {
                RecipientId   = viewModel.RecipientId,
                FirstName     = viewModel.FirstName,
                LastName      = viewModel.LastName,
                RecipientTown = viewModel.RecipientTown,
                Address       = viewModel.Address,
                Phone         = viewModel.Phone
            };

            return(dtoModel);
        }