Esempio n. 1
0
        public async Task <IActionResult> History()
        {
            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var user   = await this.userService.GetUserByIdAsync(userId);

            var ordersViewModel = new List <OfferInCheckoutViewModel>();

            var orders = await this.orderService.GetOrdersHistoryForUser(userId);

            orders
            .OrderByDescending(x => x.CreatedOn)
            .ToList()
            .ForEach(delegate(Order order)
            {
                ordersViewModel.Add(new OfferInCheckoutViewModel()
                {
                    Id       = order.OfferId,
                    Name     = order.OfferName,
                    ImageUrl = order.OfferPicUrl,
                    Price    = order.OfferPrice,
                    SoldBy   = order.SellerId,
                    BoughtBy = order.UserId,
                });
            });

            var viewModel = new OrdersHistoryViewModel()
            {
                Orders        = ordersViewModel,
                CurrentUserId = userId,
            };

            return(this.View(viewModel));
        }
        public ActionResult OrdersHistory(int?id, string sortOrder, string searchString, string selectedOrderType, string selectedOrderStatus, string currentFilter, int?page)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var viewModel = new OrdersHistoryViewModel();

            OrdersHistoryViewModel.GetCustomer(_context, id, viewModel);

            if (viewModel == null)
            {
                return(HttpNotFound());
            }

            ViewBag.Customer                  = viewModel.Customer;
            ViewBag.OrderNumberSortParam      = String.IsNullOrEmpty(sortOrder) ? "orderNumber_desc" : "";
            ViewBag.OrderDateSortParam        = sortOrder == "orderDate_asc" ? "orderDate_desc" : "orderDate_asc";
            ViewBag.OrderStatusSortParam      = sortOrder == "orderStatus_asc" ? "orderStatus_desc" : "orderStatus_asc";
            ViewBag.OrderTypeSortParam        = sortOrder == "orderType_asc" ? "orderType_desc" : "orderType_asc";
            ViewBag.OrderPaidOffSortParam     = sortOrder == "orderPaidOff_asc" ? "orderPaidOff_desc" : "orderPaidOff_asc";
            ViewBag.OrderPaymentDateSortParam = sortOrder == "orderPaymentDate_asc" ? "orderPaymentDate_desc" : "orderPaymentDate_asc";
            ViewBag.OrderPaymentSortParam     = sortOrder == "orderPayment_asc" ? "orderPayment_desc" : "orderPayment_asc";

            List <OrderType> myOrderType = Enum.GetValues(typeof(OrderType)).Cast <OrderType>().ToList();

            ViewBag.OrderType = new SelectList(myOrderType);

            List <OrderStatus> myOrderStatus = Enum.GetValues(typeof(OrderStatus)).Cast <OrderStatus>().ToList();

            ViewBag.OrderStatus = new SelectList(myOrderStatus);

            ViewBag.OrderCurrentSort = sortOrder;

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.OrderCurrentFilter = searchString;

            ViewBag.Type   = selectedOrderType;
            ViewBag.Status = selectedOrderStatus;

            int pageSize   = 6;
            int pageNumber = page ?? 1;

            OrdersHistoryViewModel.SearchingOrders(_context, viewModel, searchString, selectedOrderType, selectedOrderStatus);
            OrdersHistoryViewModel.SortingOrders(_context, viewModel, sortOrder);

            return(View(viewModel.Customer.Orders.ToPagedList(pageNumber, pageSize)));
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> GetOrdersHistory(int UserId, int SignInType, bool IsCurrentOrder, int PageSize, int PageNo)
        {
            try
            {
                using (DunkeyContext ctx = new DunkeyContext())
                {
                    OrdersHistoryViewModel orderHistory = new OrdersHistoryViewModel();

                    if (SignInType == (int)RolesCode.User)
                    {
                        if (IsCurrentOrder)
                        {
                            orderHistory.Count = ctx.Orders.Count(x => x.User_ID == UserId && x.IsDeleted == false && x.Status != (int)OrderStatuses.Completed);
                        }
                        else
                        {
                            orderHistory.Count = ctx.Orders.Count(x => x.User_ID == UserId && x.IsDeleted == false && x.Status == (int)OrderStatuses.Completed);
                        }
                    }
                    else
                    {
                        if (IsCurrentOrder)
                        {
                            orderHistory.Count = ctx.Orders.Count(x => x.DeliveryMan_Id == UserId && x.IsDeleted == false && x.Status != (int)OrderStatuses.Completed);
                        }
                        else
                        {
                            orderHistory.Count = ctx.Orders.Count(x => x.DeliveryMan_Id == UserId && x.IsDeleted == false && x.Status == (int)OrderStatuses.Completed);
                        }
                    }

                    if (orderHistory.Count == 0)
                    {
                        return(Ok(new CustomResponse <OrdersHistoryViewModel> {
                            Message = Global.ResponseMessages.Success, StatusCode = (int)HttpStatusCode.OK, Result = orderHistory
                        }));
                    }

                    #region OrderQuery
                    string orderQuery = String.Empty;
                    if (SignInType == (int)RolesCode.User)
                    {
                        orderQuery = @"SELECT *, Users.FullName as UserFullName FROM Orders join Users on Users.ID = Orders.User_ID where Orders.User_Id = " + UserId + @" and Orders.IsDeleted = 0  ORDER BY Orders.id OFFSET " + PageNo * PageSize + " ROWS FETCH NEXT " + PageSize + " ROWS ONLY;";
                    }
                    else
                    {
                        orderQuery = @"SELECT *, Users.FullName as UserFullName FROM Orders 
						join Users on Users.ID = Orders.User_ID
						where Orders.DeliveryMan_Id = "                         + UserId + @" and Orders.IsDeleted = 0  
						ORDER BY Orders.id OFFSET "                         + PageNo * PageSize + " ROWS FETCH NEXT " + PageSize + " ROWS ONLY;";
                    }

                    #endregion

                    orderHistory.orders = ctx.Database.SqlQuery <OrderVM>(orderQuery).ToList();

                    var orderIds = string.Join(",", orderHistory.orders.Select(x => x.Id.ToString()));

                    #region StoreOrderQuery
                    var storeOrderQuery = @"
						select
						StoreOrders.*,
						Stores.BusinessName as StoreName,
						Stores.ImageUrl from StoreOrders 
						join Stores on Stores.Id = StoreOrders.Store_Id
						where 
						Order_Id in ("                         + orderIds + @")
						"                        ;
                    #endregion

                    var storeOrders = ctx.Database.SqlQuery <StoreOrderViewModel>(storeOrderQuery).ToList();

                    var storeOrderIds = string.Join(",", storeOrders.Select(x => x.Id.ToString()));

                    #region OrderItemsQuery

                    var orderItemsQuery = @"SELECT
  CASE
    WHEN ISNULL(Order_Items.Product_Id, 0) <> 0 THEN Products.Id
    WHEN ISNULL(Order_Items.Package_Id, 0) <> 0 THEN Packages.Id
    WHEN ISNULL(Order_Items.Offer_Product_Id, 0) <> 0 THEN Offer_Products.Id
    WHEN ISNULL(Order_Items.Offer_Package_Id, 0) <> 0 THEN Offer_Packages.Id
  END AS ItemId,
  Order_Items.Name AS Name,
  Order_Items.Price AS Price,
  CASE
    WHEN ISNULL(Order_Items.Product_Id, 0) <> 0 THEN Products.Image
    WHEN ISNULL(Order_Items.Package_Id, 0) <> 0 THEN Packages.ImageUrl
    WHEN ISNULL(Order_Items.Offer_Product_Id, 0) <> 0 THEN Offer_Products.ImageUrl
    WHEN ISNULL(Order_Items.Offer_Package_Id, 0) <> 0 THEN Offer_Packages.ImageUrl
  END AS ImageUrl,
  Order_Items.Id,
  Order_Items.Qty,

  Order_Items.StoreOrder_Id
FROM Order_Items
LEFT JOIN products
  ON products.Id = Order_Items.Product_Id
LEFT JOIN Packages
  ON Packages.Id = Order_Items.Package_Id
LEFT JOIN Offer_Products
  ON Offer_Products.Id = Order_Items.Offer_Product_Id
LEFT JOIN Offer_Packages
  ON Offer_Packages.Id = Order_Items.Offer_Package_Id
WHERE StoreOrder_Id IN (" + storeOrderIds + ")";
                    #endregion

                    var orderItems = ctx.Database.SqlQuery <OrderItemViewModel>(orderItemsQuery).ToList();

                    foreach (var orderItem in orderItems)
                    {
                        storeOrders.FirstOrDefault(x => x.Id == orderItem.StoreOrder_Id).OrderItems.Add(orderItem);
                    }

                    foreach (var storeOrder in storeOrders)
                    {
                        orderHistory.orders.FirstOrDefault(x => x.Id == storeOrder.Order_Id).StoreOrders.Add(storeOrder);
                    }

                    return(Ok(new CustomResponse <OrdersHistoryViewModel> {
                        Message = Global.ResponseMessages.Success, StatusCode = (int)HttpStatusCode.OK, Result = orderHistory
                    }));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(DunkeyDelivery.Utility.LogError(ex)));
            }
        }