Esempio n. 1
0
        public async Task <IActionResult> Edit(Guid?id, CancellationToken cancellationToken)
        {
            var userId = this.GetUserId();

            StandingOrderViewModel model = null;

            if (id.HasValue)
            {
                model = await mediator.Send(new StandingOrderRequest(id.Value, userId), cancellationToken);
            }

            if (model == null)
            {
                var type = this.GetRequestValue("type");

                model = new StandingOrderViewModel
                {
                    Type        = type,
                    Installment = DateTime.UtcNow.AddDays(1)
                };
            }

            await CreateViewDataAsync(userId, cancellationToken);

            ViewBag.ReturnUrl = this.GetReturnUrl();

            return(View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(StandingOrderViewModel model, CancellationToken cancellationToken)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var userId    = this.GetUserId();
            var returnUrl = this.GetReturnUrl();

            if (ModelState.IsValid)
            {
                var request = mapper.Map <StandingOrderEditRequest>(model);
                request.UserId = userId;

                await mediator.Send(request, cancellationToken);

                if (string.IsNullOrEmpty(returnUrl))
                {
                    return(RedirectToAction(nameof(List)));
                }
                else
                {
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        throw new InvalidOperationException("Boo !");
                    }
                }
            }

            await CreateViewDataAsync(userId, cancellationToken);

            return(View(model));
        }