Ejemplo n.º 1
0
        public async Task <ActionResult> Edit(EditCarrierViewModel model, bool?backToOverview = null)
        {
            if (!ModelState.IsValid)
            {
                await this.BindCountryList(mediator);

                return(View(model));
            }

            try
            {
                var request = model.ToRequest();

                await mediator.SendAsync(request);

                await this.auditService.AddAuditEntry(this.mediator,
                                                      model.NotificationId,
                                                      User.GetUserId(),
                                                      NotificationAuditType.Updated,
                                                      NotificationAuditScreenType.IntendedCarrier);

                if (model.IsAddedToAddressBook)
                {
                    await mediator.SendAsync(addCarrierAddressBookMap.Map(model));
                }

                return(RedirectToAction("List", "Carrier",
                                        new { id = model.NotificationId, backToOverview }));
            }
            catch (ApiBadRequestException ex)
            {
                this.HandleBadRequest(ex);

                if (ModelState.IsValid)
                {
                    throw;
                }
            }
            await this.BindCountryList(mediator);

            return(View(model));
        }
        public async Task<ActionResult> Edit(EditCarrierViewModel model, bool? backToOverview = null)
        {
            if (!ModelState.IsValid)
            {
                await this.BindCountryList(mediator);
                return View(model);
            }

            try
            {
                var request = model.ToRequest();

                await mediator.SendAsync(request);

                if (model.IsAddedToAddressBook)
                {
                    await mediator.SendAsync(addCarrierAddressBookMap.Map(model));
                }

                return RedirectToAction("List", "Carrier",
                    new { id = model.NotificationId, backToOverview });
            }
            catch (ApiBadRequestException ex)
            {
                this.HandleBadRequest(ex);

                if (ModelState.IsValid)
                {
                    throw;
                }
            }
            await this.BindCountryList(mediator);
            return View(model);
        }