public async Task<ActionResult> Index(Guid id)
        {
            var result = await mediator.SendAsync(new GetCancellableMovements(id));

            var model = new CancellableMovementsViewModel(result);

            return View(model);
        }
        public async Task<ActionResult> Index(Guid id, CancellableMovementsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var result = await mediator.SendAsync(new GetCancellableMovements(id));
                model = new CancellableMovementsViewModel(result);

                return View(model);
            }

            var selectedMovements = model.CancellableMovements
               .Where(m => m.IsSelected)
               .Select(p => new ImportCancelMovementData { Id = p.MovementId, Number = p.Number })
               .ToList();

            TempData[SubmittedMovementListKey] = selectedMovements;

            return RedirectToAction("Confirm");
        }
示例#3
0
        public async Task <ActionResult> Index(Guid id, CancellableMovementsViewModel model, string command)
        {
            var selectedMovements = model.CancellableMovements
                                    .Where(m => m.IsSelected)
                                    .Select(p => new ImportCancelMovementData {
                NotificationId = id, Id = p.MovementId, Number = p.Number
            })
                                    .ToList();

            TempData[SubmittedMovementListKey] = selectedMovements;

            if (command == AddCommand)
            {
                return(RedirectToAction("Add"));
            }

            var addedCancellableMovements = GetTempDataAddedCancellableMovements();

            int removeShipmentNumber;

            if (!string.IsNullOrEmpty(command) && int.TryParse(command, out removeShipmentNumber))
            {
                addedCancellableMovements.RemoveAll(x => x.Number == removeShipmentNumber);
                TempData[AddedCancellableMovementsListKey] = addedCancellableMovements;
                return(RedirectToAction("Index"));
            }

            if (!ModelState.IsValid && !addedCancellableMovements.Any())
            {
                var result = await mediator.SendAsync(new GetCancellableMovements(id));

                model = new CancellableMovementsViewModel(result);

                model.AddedMovements = addedCancellableMovements.OrderBy(x => x.Number).ToList();
                return(View(model));
            }

            return(RedirectToAction("Confirm"));
        }
示例#4
0
        public async Task <ActionResult> Index(Guid id)
        {
            var result = await mediator.SendAsync(new GetCancellableMovements(id));

            var model = new CancellableMovementsViewModel(result);

            model.AddedMovements = GetTempDataAddedCancellableMovements().Where(x => x.NotificationId == id).ToList();

            var selectedMovements = GetTempDataSelectedMovements().Where(x => x.NotificationId == id).ToList();

            TempData[SubmittedMovementListKey] = selectedMovements;

            if (selectedMovements.Count > 0)
            {
                Guid[] selectedMovementIds = selectedMovements.Select(m => m.Id).ToArray();

                foreach (var movement in model.CancellableMovements.Where(x => selectedMovementIds.Contains(x.MovementId)))
                {
                    movement.IsSelected = true;
                }
            }

            return(View(model));
        }