Esempio n. 1
0
        public ActionResult OrdersList()
        {
            OrdersByUser result = client.GetOrdersByUserId(GlobalVariables.currentUser.id.ToString());

            ViewBag.Orders = result.orderData;

            return(View());
        }
Esempio n. 2
0
        public OrdersByUser GetOrdersByUserId(string id)
        {
            OrdersByUser resp = new OrdersByUser();
            int          userId;

            if (int.TryParse(id, out userId))
            {
                resp.OrderData = new List <OrderData>();
                using (TablesContext context = new TablesContext())
                {
                    var orders = from o in context.Orders where o.UserId.Equals(userId) select o;
                    if (orders != null && orders.Count() > 0)
                    {
                        orders.ToList <Order>().ForEach(delegate(Order order)
                        {
                            List <Book> booksInOrder = new List <Book>();
                            OrderData current        = new OrderData
                            {
                                Id           = order.Id,
                                UserId       = order.UserId,
                                TotalPayment = order.TotalPayment,
                                Status       = order.Status
                            };

                            var books = from b in context.BooksInOrders where b.OrderId.Equals(current.Id) select b;
                            if (books != null && books.Count() > 0)
                            {
                                books.ToList <BooksInOrder>().ForEach(delegate(BooksInOrder book)
                                {
                                    booksInOrder.Add(context.Books.Find(book.BookId));
                                });
                            }
                            current.Books = booksInOrder;
                            resp.OrderData.Add(current);
                        });
                        resp.Status  = (int)Constants.STATUSES.OK;
                        resp.Message = Constants.SUCCESS;
                    }
                    else
                    {
                        resp.Status  = (int)Constants.STATUSES.ERROR;
                        resp.Message = Constants.NO_ORDERS;
                    }
                }
            }
            else
            {
                resp.Status  = (int)Constants.STATUSES.ERROR;
                resp.Message = Constants.ENTER_INT;
            }

            return(resp);
        }