Exemplo n.º 1
0
        public async Task <ActionResult> Index(Guid id, bool?backToOverview = null)
        {
            var model = new MeansOfTransportViewModel();

            var currentMeans =
                await mediator.SendAsync(new GetMeansOfTransportByNotificationId(id));

            if (currentMeans.Count != 0)
            {
                model.SelectedMeans = string.Join("-", currentMeans.Select(EnumHelper.GetShortName));
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Index(Guid id, MeansOfTransportViewModel model, bool?backToOverview = null)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                var currentMeans = await mediator.SendAsync(new GetMeansOfTransportByNotificationId(id));

                var meansList = model.SelectedMeans.Split('-')
                                .Select(MeansOfTransportHelper.GetTransportMethodFromToken)
                                .ToList();

                await this.auditService.AddAuditEntry(this.mediator,
                                                      id,
                                                      User.GetUserId(),
                                                      currentMeans.Count == 0?NotificationAuditType.Added : NotificationAuditType.Updated,
                                                      NotificationAuditScreenType.MeansOfTransport);

                await mediator.SendAsync(new SetMeansOfTransportForNotification(id, meansList));
            }
            catch (ApiBadRequestException ex)
            {
                this.HandleBadRequest(ex);

                if (ModelState.IsValid)
                {
                    throw;
                }
            }

            if (backToOverview.GetValueOrDefault())
            {
                return(RedirectToAction("Index", "Home", new { id }));
            }

            return(RedirectToAction("Index", "PackagingTypes", new { id }));
        }