コード例 #1
0
        public async Task <ActionResult <IReadOnlyList <OrderDto> > > GetAllOrders([FromQuery] OrderSpecParams orderParams)
        {
            var spec      = new OrdersAllWithItemsAndOrderingSpecification(orderParams);
            var countSpec = new OrderWithFiltersForCountSpecification(orderParams);
            var totalItem = await _unitOfWork.Repository <Order>().CountAsync(countSpec);

            var orders = await _unitOfWork.Repository <Order>().ListAsync(spec);

            // var data = _mapper.Map<IReadOnlyList<Order>, IReadOnlyList<OrderToReturnDto>>(orders);
            return(Ok(_mapper.Map <IReadOnlyList <Order>, IReadOnlyList <OrderToReturnDto> >(orders)));
        }
コード例 #2
0
        public async Task <ActionResult <Pagination <OrderToReturnDTO> > > GetOrdersForUser([FromQuery] PaginationSpecParams paginationParams)
        {
            OrderSpecParams orderParams = _mapper.Map <OrderSpecParams>(paginationParams);

            orderParams.Email = HttpContext.User.GetEmailFromPrincipal();

            var orders = await _orderService.GetOrdersForUserAsync(orderParams);

            var data = _mapper.Map <IReadOnlyList <OrderToReturnDTO> >(orders);

            var totalCount = await _orderService.GetCountOrdersForUserAsync(orderParams);

            return(Ok(new Pagination <OrderToReturnDTO>(orderParams.PageIndex, orderParams.PageSize, totalCount, data)));
        }
コード例 #3
0
ファイル: OrdersController.cs プロジェクト: Olafyngvi/Skinet
        public async Task <ActionResult <Pagination <OrderToReturnDto> > > GetOrders(
            [FromQuery] OrderSpecParams orderParams
            )
        {
            var spec      = new OrdersWithItemsAndOrderingAdminSpecification(orderParams);
            var countSpec = new OrdersWithFiltersForCountSpecification(orderParams);

            var totalItems = await _unitOfWork.Repository <Order>().CountAsync(countSpec);

            var orders = await _unitOfWork.Repository <Order>().ListAsync(spec);

            var data = _mapper.Map <IReadOnlyList <OrderToReturnDto> >(orders);

            return(Ok(new Pagination <OrderToReturnDto>(orderParams.PageIndex,
                                                        orderParams.PageSize, totalItems, data)));
        }
コード例 #4
0
        public async Task <ActionResult <Pagination <OrderToReturnDto> > > GetAllOrders(
            [FromQuery] OrderSpecParams ordersParams)
        {
            var spec = new OrdersWithItemsAndOrderingSpecification(ordersParams);

            var countSpec = new OrdersForCountSpecification(ordersParams);

            var totalItems = await _orderService.CountAsync(spec);

            var orders = await _orderService.GetAllOrdersAsync(spec);

            var data = _mapper.Map <IReadOnlyList <Order>, IReadOnlyList <OrderToReturnDto> >(orders);

            return(Ok(new Pagination <OrderToReturnDto>(ordersParams.PageIndex,
                                                        ordersParams.pageSize, totalItems, data)));
        }
コード例 #5
0
        public async Task <IReadOnlyList <Order> > GetOrdersForApproveRejectAsync(OrderSpecParams orderSpecParams)
        {
            var spec = new OrdersWithItemsAndOrderingSpecification(orderSpecParams);

            return(await _unitOfWork.Repository <Order>().ListAsync(spec));
        }
コード例 #6
0
        public async Task <int> UpdateOrdersStatusForApproveRejectAsync(int[] orderIds, OrderStatus status, OrderSpecParams orderSpecParams)
        {
            var spec = new OrdersWithItemsAndOrderingSpecification(orderIds.ToList());

            var orderList = await _unitOfWork.Repository <Order>().ListAsync(spec);

            List <Order> listOrder = new List <Order>();

            foreach (var order in orderList)
            {
                order.Status = status;
                listOrder.Add(order);
            }
            _unitOfWork.Repository <Order>().UpdateRange(listOrder);

            // save to db
            var result = await _unitOfWork.CompleteAsync();

            return(result);
            //var specific = new OrdersWithItemsAndOrderingSpecification(orderSpecParams);
            //return await _unitOfWork.Repository<Order>().ListAsync(specific);
        }
コード例 #7
0
        public async Task <int> GetCountOrdersForUserAsync(OrderSpecParams orderSpecParams)
        {
            var countSpec = new OrdersWithItemsAndDeliveryMethodCountSpecification(orderSpecParams);

            return(await _unitOfWork.Repository <Order>().CountAsync(countSpec));
        }
コード例 #8
0
        public async Task <IReadOnlyList <Order> > GetOrdersForUserAsync(OrderSpecParams orderSpecParams)
        {
            var spec = new OrdersWithItemsAndDeliveryMethodSpecification(orderSpecParams);

            return(await _unitOfWork.Repository <Order>().ListAsync(spec));
        }
コード例 #9
0
        public async Task <ActionResult <Pagination <OrderToReturnDto> > > GetOrdersForApproveReject([FromQuery] OrderSpecParams orderParams)
        {
            var orders = await _orderService.GetOrdersForApproveRejectAsync(orderParams);

            var totalOrders = await _orderService.GetOrdersCountAsync();

            var data = _mapper.Map <IReadOnlyList <Order>, IReadOnlyList <OrderToReturnDto> >(orders);

            return(Ok(new Pagination <OrderToReturnDto>(orderParams.PageIndex,
                                                        orderParams.PageSize, totalOrders, data)));
        }