Пример #1
0
        public static OrdersForRestaurantResponseModel GetOrdersForRestaurant(GetRestaurantOrdersForSpecificStatus model)
        {
            using (var dbContext = new DeliversEntities())
            {
                model.CurrentPage--;

                var response = new OrdersForRestaurantResponseModel();

                var orderStatus = OrderHistoryEnu.GetOrderStatus(model.Status);

                var list = dbContext.Orders
                           .Where(
                    od =>
                    od.OrderHistories.Any(str => str.Status == orderStatus.Value) &&
                    od.OrderDetails.Any(det => det.ItemDetail.ListItemId.ToString() == model.RestaurantId))
                           .ToList();

                if (list.Any())
                {
                    var take = list.Skip(model.CurrentPage * model.ItemsPerPage).
                               Take(model.ItemsPerPage).ToList();
                    if (take.Any())
                    {
                        var finals = take.Select(obj => obj.MappOrder()).ToList();
                        response.Orders = finals;
                    }
                }
                response.ItemsPerPage = model.ItemsPerPage;
                response.CurrentPage++;
                response.TotalItems = list.Count;
                return(response);
            }
        }
Пример #2
0
 public static OrderHistoryEnu GetOrderCurrentStatus(string orderid)
 {
     using (var dbContext = new DeliversEntities())
     {
         var order = dbContext.Orders.FirstOrDefault(o => o.Id.ToString() == orderid);
         if (order != null)
         {
             var orderStatus = OrderHistoryEnu.GetOrderStatus(order.Status);
             return(orderStatus);
         }
         return(null);
     }
 }
Пример #3
0
        public static DeliveredOrdersDBoyResponseModel MyOrderHistoryDBoy(OrderHistoryForDBoyRequesrModel requestModel)
        {
            using (var dbContext = new DeliversEntities())
            {
                var response = new DeliveredOrdersDBoyResponseModel();

                var orderStatus = OrderHistoryEnu.GetOrderStatus(requestModel.Status);

                var list = dbContext.Orders
                           .Where(
                    od =>
                    od.OrderHistories.Any(str => str.Status == orderStatus.Value && str.MovedBy == requestModel.UserId))
                           .ToList();

                if (list.Any())
                {
                    var finals = list.Select(obj => obj.MappOrder()).ToList();
                    response.Orders = finals;
                }
                return(response);
            }
        }
Пример #4
0
        public ResponseModel UpdateOrderStatus(ChangeOrderStatusRequesrModel model)
        {
            var response = new ResponseModel
            {
                Success  = false,
                Messages = new List <string>()
            };

            if (model == null || string.IsNullOrEmpty(model.OrderId) || string.IsNullOrEmpty(model.NewStatus) || string.IsNullOrEmpty(model.UserId))
            {
                response.Messages.Add("Data not mapped");
                response.Data = model;
            }
            else if (!CommonService.VerifyOrderStatus(model.NewStatus))
            {
                response.Messages.Add("Invalid order status");
                response.Data = model;
            }
            else
            {
                try
                {
                    var currentOrderStatus = OrderService.GetOrderCurrentStatus(model.OrderId);
                    var newOrderStatus     = OrderHistoryEnu.GetOrderStatus(model.NewStatus);

                    if (currentOrderStatus == null || newOrderStatus == null)
                    {
                        response.Success = false;
                        response.Messages.Add("Invalid orderId/Order Status.");
                        response.Data = model;
                        return(response);
                    }
                    else if (currentOrderStatus.Value == newOrderStatus.Value)
                    {
                        response.Success = false;
                        response.Messages.Add("Current status already is : " + currentOrderStatus.Value);
                        response.Data = model;
                        return(response);
                    }

                    if (newOrderStatus.Order - currentOrderStatus.Order > 1)
                    {
                        response.Success = false;
                        response.Messages.Add("Invalid order status shifting. Current status is :" + currentOrderStatus.Value);
                        response.Data = currentOrderStatus.Value + " -> " + newOrderStatus.Value;
                        return(response);
                    }

                    response.Success = OrderService.ChangeOrderStatus(model);
                    if (response.Success)
                    {
                        response.Data = "status has been changed";
                    }
                    else
                    {
                        response.Data = "Order does not exist with id " + model.OrderId;
                    }
                    response.Messages.Add("Success");
                }
                catch (Exception excep)
                {
                    response.Messages.Add("Something bad happened.");
                }
            }
            return(response);
        }
Пример #5
0
        public static UpdateOrderResponse EditOrder_Admin(OrderLocal source)
        {
            var response = new UpdateOrderResponse {
            };

            using (var dbContext = new DeliversEntities())
            {
                var dbOrder = dbContext.Orders.FirstOrDefault(o => o.Id == source.Id);
                if (dbOrder != null)
                {
                    var canEditOrder = true;
                    #region EDIT
                    if (dbOrder.Status == OrderHistoryEnu.Deliverd.Value || dbOrder.Status == OrderHistoryEnu.PickedUp.Value)
                    {
                        canEditOrder = false;
                    }

                    #region STATUS
                    if (dbOrder.Status != source.Status)
                    {
                        var dbOrderStatus      = OrderService.GetOrderCurrentStatus(source.Id.ToString());
                        var updatedOrderStatus = OrderHistoryEnu.GetOrderStatus(source.Status);

                        if (updatedOrderStatus.Order - dbOrderStatus.Order > 1)
                        {
                            response.Status = false;
                            response.Error  = "Invalid order status";
                            return(response);
                        }

                        // UPDATE STATUS
                        ChangeOrderStatus(new ChangeOrderStatusRequesrModel {
                            OrderId   = source.Id.ToString(),
                            NewStatus = source.Status,
                            UserId    = null,
                            Comments  = source.Comments
                        });
                    }

                    #endregion

                    var newHist = new OrderHistory
                    {
                        OrderId   = dbOrder.Id,
                        DateTime  = CommonService.GetSystemTime(),
                        IsCurrent = false,
                        Status    = OrderHistoryEnu.OrderEdited.Value,
                        Comments  = source.Comments
                    };
                    var isAddHis = false;
                    var comm     = "";


                    if (!string.IsNullOrEmpty(source.Address) && source.Address.ToLower() != dbOrder.Address.ToLower())
                    {
                        if (canEditOrder)
                        {
                            comm            = "address changed from '" + dbOrder.Address + "' TO '" + source.Address + "' & ";
                            dbOrder.Address = source.Address;
                            isAddHis        = true;
                        }
                        else
                        {
                            response.Status = false;
                            response.Error  = "Can not change address in current status: " + dbOrder.Status;
                            return(response);
                        }
                    }
                    if (!string.IsNullOrEmpty(source.Instructions) && source.Instructions.ToLower() != dbOrder.Instructions.ToLower())
                    {
                        dbOrder.Instructions = source.Instructions;
                    }
                    if (!string.IsNullOrEmpty(source.PickedBy) && source.PickedBy.ToLower() != dbOrder.PickedBy.ToLower())
                    {
                        dbOrder.PickedBy = source.PickedBy;
                    }
                    if (source.DeliveryCost != dbOrder.DeliveryCost)
                    {
                        if (canEditOrder)
                        {
                            comm                 = comm + "delivery cost changed from " + dbOrder.DeliveryCost + " TO " + source.DeliveryCost + ".";
                            isAddHis             = true;
                            dbOrder.DeliveryCost = source.DeliveryCost;
                        }
                        else
                        {
                            response.Status = false;
                            response.Error  = "Can not change delivery cost in current status: " + dbOrder.Status;
                            return(response);
                        }
                    }

                    if (isAddHis)
                    {
                        newHist.Comments = comm;
                        dbContext.OrderHistories.Add(newHist);
                    }

                    dbContext.SaveChanges();
                    response.Status = true;
                    response.Error  = "";
                    return(response);

                    #endregion
                }
                else
                {
                    response.Status = false;
                    response.Error  = "Invalid order Id";
                    return(response);
                }
            }
        }