Пример #1
0
        public async Task <Result <OrderOpened> > Handle(OpenOrderRequest request)
        {
            var member = await service.GetMemberById(request.ByMemberId);

            if (!CanOpenOrder(member))
            {
                return(GeneralErrors.UnauthorizedError());
            }

            var status = member.HasPermission(Permission.CanConfirmOrder)
                    ? OrderStatusId.Approved
                    : OrderStatusId.New;

            var order = new Order
            {
                LendingUnitId      = request.FromUnitId,
                Remarks            = request.Remarks,
                Status             = status,
                RequestingMemberId = member.Id,
                RequestingUnitId   = member.UnitId,
                ItemId             = request.ItemId
            };

            var createRes = await service.CreateOrder(order);

            if (!createRes.Success)
            {
                return(Errors.FailToCreateOrder(createRes.ErrorMessage));
            }

            return(new OrderOpened(createRes.Id, status));
        }
        public async Task <IActionResult> Create(Order model, string action)
        {
            if (ModelState.IsValid)
            {
                var user = _appUserParser.Parse(HttpContext.User);
                await _orderSvc.CreateOrder(model);

                //Empty basket for current user.
                await _basketSvc.CleanBasket(user);

                //Redirect to historic list.
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public async Task <IActionResult> Checkout()
        {
            var user         = _appUserParser.Parse(HttpContext.User);
            var cookieBasket = Request.Cookies["basket"];

            if (cookieBasket != null)
            {
                var backetIds = cookieBasket.Split(',').Select(int.Parse).ToList();

                backetIds.ForEach(_id => _catalogSvc.RemoveItemFromStock(_id));
                await _orderSvc.CreateOrder(user, backetIds.ToArray());

                Response.Cookies.Delete("basket");
            }

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create(Order model, string action)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = _appUserParser.Parse(HttpContext.User);
                    await _orderSvc.CreateOrder(model);

                    //Redirect to historic list.
                    return(RedirectToAction("Index"));
                }
            }
            catch (BrokenCircuitException)
            {
                ModelState.AddModelError("Error", "It was not possible to create a new order, please try later on. (Business Msg Due to Circuit-Breaker)");
            }
            return(View(model));
        }