Пример #1
0
        public async Task <OrdersModel> GetUserOrdersAsync(OrdersFilterModel model, long id)
        {
            var response = new OrdersModel();

            if (id == 0)
            {
                response.Errors.Add(ErrorConstants.ModelIsNull);
                return(response);
            }
            var filterModel = FilterMapper.MapOrdersFilteringModel(model);
            var orders      = await _orderRepository.GetByUserIdAsync(filterModel, id);

            if (orders == null)
            {
                response.Errors.Add(ErrorConstants.ImpossibleToFindOrder);
                return(response);
            }
            var responceOrders = new OrdersModel();

            foreach (var order in orders.Data)
            {
                var orderItemModel = OrderMapper.MapResponseModelToModelItem(order);
                responceOrders.Items.Add(orderItemModel);
            }
            responceOrders.TotalCount = orders.TotalItemsCount;
            return(responceOrders);
        }
Пример #2
0
        public override async Task OnGet(OrdersFilterModel filter, int currentPage = 1)
        {
            if (this.User.Identity.IsAuthenticated)
            {
                filter.Author = User.Identity.Name;
            }

            await base.OnGet(filter, currentPage);
        }
Пример #3
0
        public override async Task OnGet(OrdersFilterModel filter, int currentPage = 1)
        {
            this.CurrentPage = currentPage;

            var filterDelegate = new FilterBuilder(filter).CreateFilterDelegate().Compile();

            var orders = await entityService
                         .GetAll <Order>(e => e.DeliverySlip != null && e.Status != Status.Completed && filterDelegate(e));

            OrdersCache.Items = orders.Select(this.mapper.Map <OrderViewModel>).ToList();
        }
Пример #4
0
        public async Task <OrderModel> GetOrdersAsync(OrdersFilterModel ordersFilterModel)
        {
            var orders = await _orderRepository.GetOrdersAsync(ordersFilterModel);

            var resultModel = new OrderModel();

            foreach (var order in orders)
            {
                resultModel.Items.Add(order.Mapping());
            }
            return(resultModel);
        }
Пример #5
0
        public async Task <IActionResult> Test(/*OrdersFilterModel ordersFilterModel*/)
        {
            var ordersFilterModel = new OrdersFilterModel
            {
                SortBy           = SortBy.UserName,
                SortingDirection = SortingDirection.HighToLow,
                OrderStatus      = OrderStatus.Unpaid,
                PageCount        = 1,
                PageSize         = 10
            };
            var authorModel = await _orderService.GetOrdersAsync(ordersFilterModel);

            return(Ok(authorModel));
        }
 public FilterBuilder(OrdersFilterModel filter)
 {
     this.filter = filter;
     this.mapPropertyToFilter = new Dictionary <string, Func <ParameterExpression, Expression> >
     {
         { "Status", new Func <ParameterExpression, Expression>(this.StatusFilter) },
         { "From", new Func <ParameterExpression, Expression>(this.FromFilter) },
         { "To", new Func <ParameterExpression, Expression>(this.ToFilter) },
         { "Author", new Func <ParameterExpression, Expression>(this.AuthorFilter) },
         { "ProductName", new Func <ParameterExpression, Expression>(this.ProductNameFilter) },
         { "Comment", new Func <ParameterExpression, Expression>(this.CommentFilter) },
         { "PhoneNumber", new Func <ParameterExpression, Expression>(this.PhoneNumberFilter) },
         { "CustomerName", new Func <ParameterExpression, Expression>(this.CustomerNameFilter) }
     };
 }
        public virtual async Task OnGet(OrdersFilterModel filter, int currentPage = 1)
        {
            this.CurrentPage = currentPage;

            var users = await this.entityService.GetAll <User>();

            var filterDelegate = new FilterBuilder(filter).CreateFilterDelegate();

            var orders = await entityService.GetAll(filterDelegate);

            UsersCache.Items = users.Select(u => u.Name).ToList();

            OrdersCache.Items = orders.OrderByDescending(o => o.Id)
                                .Select(this.mapper.Map <OrderViewModel>)
                                .ToList();
        }
Пример #8
0
        public async Task <IEnumerable <OrderModelItem> > GetOrdersAsync(OrdersFilterModel ordersFilterModel)
        {
            var orders = from order in _applicationContext.Orders join orderItem in _applicationContext.OrderItems on order.Id equals orderItem.OrderId
                         join printingEdition in _applicationContext.PrintingEditions on orderItem.PrintingEditionId equals printingEdition.Id
                         select new OrderModelItem
            {
                Id          = order.Id,
                Date        = order.CreationDate,
                UserName    = _applicationContext.Users.Where(u => u.Id == order.UserId).Select(u => u.UserName).FirstOrDefault(),
                UserEmail   = _applicationContext.Users.Where(u => u.Id == order.UserId).Select(u => u.UserName).FirstOrDefault(),
                Product     = printingEdition.Type,
                Title       = printingEdition.Title,
                Qty         = orderItem.Count,
                OrderAmount = orderItem.Amount,
                Status      = printingEdition.Status
            };

            orders = await OrderBy(orders, ordersFilterModel.SortBy, ordersFilterModel.SortingDirection == SortingDirection.LowToHigh);

            orders = orders.Skip((ordersFilterModel.PageCount - 1) * ordersFilterModel.PageSize).Take(ordersFilterModel.PageSize);

            return(orders);
        }
Пример #9
0
        public async Task <IActionResult> GetByUserIdAsync(OrdersFilterModel model, long id)
        {
            var orders = await _orderService.GetUserOrdersAsync(model, id);

            return(Ok(orders));
        }
Пример #10
0
        public async Task <IActionResult> GetAllAsync(OrdersFilterModel model)
        {
            var orders = await _orderService.GetAllAsync(model);

            return(Ok(orders));
        }
Пример #11
0
        public async Task <ResponseModel <List <Models.Response.OrderResponseModel> > > GetFilteredAsync(OrdersFilterModel model)
        {
            var sqlQuery         = new StringBuilder(@"SELECT userOrder.Id, userOrder.CreationDate, userOrder.Name, userOrder.Email,
                item.ProductType, item.ProductTitle, item.Count, item.Amount 
                FROM ( 
                SELECT Orders.Id, Orders.CreationDate, AspNetUsers.FirstName + ' ' + AspNetUsers.LastName AS Name, AspNetUsers.Email ");
            var orderFilterQuery = new StringBuilder(@"
                FROM Orders INNER JOIN AspNetUsers ON Orders.UserId = AspNetUsers.Id WHERE Orders.IsRemoved = 0 ");

            if (!string.IsNullOrWhiteSpace(model.SearchString))
            {
                orderFilterQuery.Append($@"AND AspNetUsers.FirstName LIKE '%{model.SearchString}%' OR AspNetUsers.LastName LIKE '%{model.SearchString}%'
                    OR AspNetUsers.Email LIKE '%{model.SearchString}%' ");
            }
            sqlQuery.Append(orderFilterQuery);
            sqlQuery.Append($"ORDER BY Orders.{model.FilteredColumnType} ");
            if (model.SortType == Common.Enums.Filter.Enums.AscendingDescendingSort.Descending)
            {
                sqlQuery.Append("DESC ");
            }
            sqlQuery.Append($@"OFFSET (@pageCount - 1) * @pageSize ROWS FETCH NEXT @pageSize ROWS ONLY
                ) AS userOrder INNER JOIN ( 
                SELECT OrderItems.OrderId, PrintingEditions.Type AS ProductType, PrintingEditions.Title AS ProductTitle,
                OrderItems.Count, OrderItems.Amount 
                FROM OrderItems
                INNER JOIN PrintingEditions ON PrintingEditions.Id = OrderItems.PrintingEditionId
                ) AS item ON userOrder.Id = item.OrderId;
                SELECT COUNT(Orders.Id) ");
            sqlQuery.Append(orderFilterQuery);
            using (var connection = new SqlConnection(_connectionString))
            {
                using (var multi = await connection.QueryMultipleAsync(sqlQuery.ToString(), new
                {
                    pageCount = model.PageCount,
                    pageSize = model.PageSize
                }))
                {
                    var dapperResponse = await multi.ReadAsync <Models.DapperResponse.OrderResponseModel>();

                    var count = await multi.ReadFirstAsync <int>();

                    var grouppedResponse = dapperResponse.GroupBy(x => x.Id).ToList();
                    var response         = CreateResponseModel(grouppedResponse);
                    var result           = new ResponseModel <List <Models.Response.OrderResponseModel> >(response, count);
                    return(result);
                }
            }
        }
Пример #12
0
        public async Task <ResponseModel <List <Models.Response.OrderResponseModel> > > GetByUserIdAsync(OrdersFilterModel model, long id)
        {
            var sqlQuery = new StringBuilder($@"SELECT userOrder.Id, userOrder.CreationDate, item.ProductType, item.ProductTitle, item.Count, item.Amount
                FROM ( 
                SELECT Orders.Id, Orders.CreationDate
                FROM Orders
                INNER JOIN AspNetUsers ON Orders.UserId = AspNetUsers.Id
                WHERE Orders.IsRemoved = 0 AND Orders.UserId = @id
                ORDER BY Orders.{model.FilteredColumnType} ");

            if (model.SortType == Common.Enums.Filter.Enums.AscendingDescendingSort.Descending)
            {
                sqlQuery.Append("DESC ");
            }
            sqlQuery.Append(@"OFFSET (@pageCount - 1) * @pageSize ROWS FETCH NEXT @pageSize ROWS ONLY
                ) AS userOrder 
                INNER JOIN (
                SELECT OrderItems.OrderId, PrintingEditions.Type AS ProductType, PrintingEditions.Title AS ProductTitle,
                OrderItems.Count, OrderItems.Amount
                FROM OrderItems
                INNER JOIN PrintingEditions ON PrintingEditions.Id = OrderItems.PrintingEditionId 
                ) AS item ON userOrder.Id = item.OrderId; SELECT COUNT(Orders.Id) FROM Orders WHERE Orders.UserId = @id ");
            using (var connection = new SqlConnection(_connectionString))
            {
                using (var multi = await connection.QueryMultipleAsync(sqlQuery.ToString(), new
                {
                    id = id,
                    pageCount = model.PageCount,
                    pageSize = model.PageSize
                }))
                {
                    var dapperResponse = await multi.ReadAsync <Models.DapperResponse.OrderResponseModel>();

                    var count = await multi.ReadFirstAsync <int>();

                    var grouppedResponse = dapperResponse.GroupBy(x => x.Id).ToList();
                    var response         = CreateResponseModel(grouppedResponse);
                    var result           = new ResponseModel <List <Models.Response.OrderResponseModel> >(response, count);
                    return(result);
                }
            }
        }
Пример #13
0
        public override async Task OnGet(OrdersFilterModel filter, int currentPage = 1)
        {
            filter.Status = Status.Refused;

            await base.OnGet(filter, currentPage);
        }
Пример #14
0
        public async Task <ResponseModel <List <OrderResponseModel> > > GetFilteredAsync(OrdersFilterModel model)
        {
            var orderItems = GetQuery();
            var substring  = model.SearchString.Split(" ");

            if (model.SearchString != null)
            {
                orderItems = orderItems.Where(x => x.Orders.User.Email.Contains(substring[0]) ||
                                              x.Orders.User.FirstName.Contains(model.SearchString) ||
                                              x.Orders.User.LastName.Contains(substring[0]));
            }
            var sortedOrders = orderItems.AsEnumerable().SortByProperty(typeof(OrderItem).GetProperty(model.FilteredColumnType.ToString()).Name, model.SortType);
            var orders       = GetOrders(sortedOrders).ToList();
            var resultModel  = orders.Skip((model.PageCount - 1) * model.PageSize).Take(model.PageSize).ToList();
            var count        = orders.Count();
            var result       = new ResponseModel <List <OrderResponseModel> >(resultModel, count);

            return(result);
        }
Пример #15
0
        public async Task <ResponseModel <List <OrderResponseModel> > > GetByUserIdAsync(OrdersFilterModel model, long id)
        {
            var orderItems = GetQuery()
                             .Where(x => x.Orders.UserId == id);
            var sortedOrders = orderItems.AsEnumerable().SortByProperty(model.FilteredColumnType.ToString(), model.SortType);
            var orders       = GetOrders(sortedOrders).ToList();
            var count        = orders.Count();
            var resultModel  = orders.Skip((model.PageCount - 1) * model.PageSize).Take(model.PageSize).ToList();
            var result       = new ResponseModel <List <OrderResponseModel> >(resultModel, count);

            return(result);
        }