示例#1
0
        public ResponseModel GetOrdersForParticularStatus(GetRestaurantOrdersForSpecificStatus model)
        {
            var response = new ResponseModel
            {
                Success  = false,
                Messages = new List <string>()
            };

            try
            {
                if (model == null || string.IsNullOrEmpty(model.RestaurantId) || string.IsNullOrEmpty(model.Status))
                {
                    response.Messages.Add("Data not mapped");
                    response.Data = model;
                }
                var data = OrderService.GetOrdersForRestaurant(model);
                response.Data    = data;
                response.Success = true;
                response.Messages.Add("Success");
            }
            catch (Exception excep)
            {
                response.Messages.Add("Something bad happened.");
            }
            return(response);
        }
示例#2
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);
            }
        }