示例#1
0
        public async Task <IWrappedResponse> Get()
        {
            var user = _userRepo.FindAll()
                       .ProjectTo <User>(Mapper.ConfigurationProvider)
                       .SingleOrDefault();

            var isNotDplEmployee = AuthData.GetUserRole() != Common.Enumerations.UserRole.DplEmployee;

            if (!isNotDplEmployee)
            {
                user.Role = Common.Enumerations.UserRole.DplEmployee;
            }

            var customersServiceResponse = (IWrappedResponse <IEnumerable <Customer> >) await _customersService.GetAll();

            var customers = isNotDplEmployee ? customersServiceResponse.Data : new Customer[] { };
            var postingAccountsServiceResponse = (IWrappedResponse <IEnumerable <PostingAccount> >) await _postingAccountsService.GetAll();

            var postingAccounts = isNotDplEmployee ? postingAccountsServiceResponse.Data : new PostingAccount[] { };
            var permssions      = isNotDplEmployee ? await _permissionsService.GetPermissions() : new UserPermission[]
            {
            };

            user.Customers       = customers;
            user.PostingAccounts = postingAccounts;
            user.Permissions     = permssions;

            return(Ok(user));
        }
示例#2
0
        public async Task <IWrappedResponse> GetByCustomerId(int customerId)
        {
            var user = _userRepo.FindAll()
                       .ProjectTo <User>(Mapper.ConfigurationProvider)
                       .SingleOrDefault();

            user.Role = AuthData.GetUserRole();

            var customerResult = (IWrappedResponse <Customer>) await _customersService.GetById(customerId);

            if (customerResult.ResultType == ResultType.NotFound)
            {
                return(NotFound <User>(customerId));
            }

            var customers = new[] { customerResult.Data };
            var postingAccountsServiceResponse = (IWrappedResponse <IEnumerable <PostingAccount> >) await _postingAccountsService.GetByCustomerId(customerId);

            var postingAccounts = postingAccountsServiceResponse.Data;
            var permissions     = Array.Empty <UserPermission>();

            user.Customers       = customers;
            user.PostingAccounts = postingAccounts;
            user.Permissions     = permissions;

            return(Ok(user));
        }
        public async Task <IWrappedResponse <OrderGroup> > Cancel(int id, OrderGroupCancelRequest request)
        {
            #region security

            // TODO add security

            #endregion

            var orderGroup = _olmaOrderGroupRepo.FindByCondition(og => og.Id == id)
                             .Include(o => o.Orders)
                             .FirstOrDefault();

            if (orderGroup == null)
            {
                return(new WrappedResponse <OrderGroup>
                {
                    ResultType = ResultType.NotFound,
                    Data = null,
                    Errors = new[] { string.Empty }
                });
            }

            var rulesResult = RulesEvaluator.Create()
                              .StopEvaluateOnFirstInvalidRule()
                              .Eval(new Rules.OrderGroup.Cancel.MainRule(orderGroup))
                              .Evaluate();

            if (!rulesResult.IsSuccess)
            {
                // return Bad Request Error403
                // TODO Result erzeugen

                return(new WrappedResponse <OrderGroup>()
                {
                    ResultType = ResultType.BadRequest,
                    State = ((RuleWithStateResult)rulesResult).State
                });
            }

            var isDplEmployee = AuthData.GetUserRole() != UserRole.DplEmployee;

            var cancellableStates = new[] { OrderStatus.Pending, OrderStatus.Confirmed, OrderStatus.PartiallyMatched, OrderStatus.Matched };
            if (isDplEmployee)
            {
                cancellableStates = cancellableStates.Append(OrderStatus.CancellationRequested).ToArray();
            }

            var cancellableOrders = orderGroup.Orders
                                    .Where(i => cancellableStates.Contains(i.Status));

            var status = isDplEmployee ? OrderStatus.CancellationRequested : OrderStatus.Cancelled;

            foreach (var orderGroupOrder in cancellableOrders)
            {
                orderGroupOrder.Status = status;
            }

            _olmaOrderGroupRepo.Save();

            // TODO Armine send service bus message
            // note When dpl employee has pefromed cancellation, LMS should just execute it with no check (state of order is already cancelled tehn)
            // When non dpl employee perfroms this check then status is cancellation requested and lms decides if this can be perfomed automatically
            // or if dpl employee intervention is required

            var result = Mapper.Map <Olma.OrderGroup, OrderGroup>(orderGroup);

            return(new WrappedResponse <OrderGroup>
            {
                ResultType = ResultType.Updated,
                Data = result
            });
        }