Ejemplo n.º 1
0
        public async Task <IActionResult> Delete(RecipientDeleteViewModel deleteViewModel)
        {
            if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName))
            {
                return(this.Redirect("/Identity/Account/AccessDenied"));
            }

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

            var dtoModel = RecipientDeleteViewMapper.Map(deleteViewModel);
            var isDelete = await this.recipientService.DeleteRecipientAsync(dtoModel);

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

            return(this.Redirect("/Recipient/Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Find(RecipientFindInputViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/Recipient/Find"));
            }

            var recipientId = await this.recipientService.FindRecipientAsync(model.Phone);

            if (recipientId == 0)
            {
                var error = new RecipientError();
                error.ErrorMessage = GlobalConstants.RecipientFindErrorMessage;
                return(this.RedirectToAction("Error", "Recipient", error));
            }

            return(this.RedirectToAction("Create", "Order", new { recipientId = recipientId }));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(RecipientParamsViewModel paramsRecipient)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/Recipient/Home"));
            }

            bool ifExists = await this.recipientService.IfRecipientExistsAsync(paramsRecipient.Phone);

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

            var recipientId = await this.recipientService.CreateRecipientAsync(paramsRecipient);

            return(this.RedirectToAction("Create", "Order", new { recipientId = recipientId }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Update(RecipientUpdateOutputViewModel outputViewModel)
        {
            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       = RecipientUpdateOutputViewMapper.Map(outputViewModel);
            var paramsDtoModel = await this.recipientService.GetRecipientParamsForUpdateAsync(dtoModel);

            var paramsViewModel = RecipientUpdateParamsMapper.Map(paramsDtoModel);

            return(this.View(paramsViewModel));
        }
Ejemplo n.º 5
0
 public IActionResult Error(RecipientError recipientError)
 {
     return(this.View(recipientError));
 }