Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        protected async Task <RequestContext> LoadContext(OrderRequestBase requst)
        {
            var ctx = new RequestContext
            {
                Member = await service.GetMemberById(requst.MemberId),
                Order  = await service.GetOrder(requst.OrderId)
            };

            return(ctx);
        }