public ActionResult ManageOrders()
        {
            var manager = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext()));

            List <GetUserOrders_Result> ResOrders;
            List <OrderToDisplay>       Orders            = new List <OrderToDisplay>();
            List <OrderToDisplay>       BookingsCancelled = new List <OrderToDisplay>();
            List <OrderToDisplay>       BookingsValid     = new List <OrderToDisplay>();
            List <OrderToDisplay>       PastOrders;
            List <OrderToDisplay>       FutureOrders;


            ResOrders = _context.GetUserOrders(User.Identity.GetUserId()).ToList();
            foreach (GetUserOrders_Result r in ResOrders)
            {
                var CurRoom = _context.GetRoomById(r.RoomId).FirstOrDefault();

                OrderToDisplay OrderVM = new OrderToDisplay
                {
                    ID          = r.ID,
                    Username    = User.Identity.GetUserName(),
                    RoomNo      = CurRoom.RoomNo,
                    FromDate    = r.FromDate,
                    ToDate      = r.ToDate,
                    IsCancelled = r.IsCancelled ? "Cancelled" : "Normal",
                    UnitPrice   = CurRoom.Price,
                    TotalCost   = r.TotalCost
                };
                if (r.IsCancelled)
                {
                    BookingsCancelled.Add(OrderVM);
                }
                else
                {
                    BookingsValid.Add(OrderVM);
                }
            }


            DateTime now         = DateTime.Now;
            DateTime DateOfToday = new DateTime(now.Year, now.Month, now.Day);

            PastOrders = BookingsValid.Where(o => ((o.ToDate <= DateOfToday) || (o.FromDate <= DateOfToday && o.ToDate >= DateOfToday))).ToList();
            HashSet <int> PastCurBookingIds = new HashSet <int>(PastOrders.Select(o => o.ID).ToList());

            FutureOrders = BookingsValid.Where(o => !PastCurBookingIds.Contains(o.ID)).ToList();

            var tables = new ManageOrderViewModel
            {
                PastOrders      = PastOrders,
                FutureOrders    = FutureOrders,
                CancelledOrders = BookingsCancelled
            };

            return(View(tables));
        }
Beispiel #2
0
        public ActionResult ManageOrders()
        {
            List <GetOrders_Result> ResOrders;
            List <OrderToDisplay>   Orders          = new List <OrderToDisplay>();
            List <OrderToDisplay>   CancelledOrders = new List <OrderToDisplay>();

            ResOrders = _context.GetOrders().ToList();
            foreach (GetOrders_Result r in ResOrders)
            {
                var CurRoom = _context.GetRoomById(r.RoomId).FirstOrDefault();

                OrderToDisplay OrderVM = new OrderToDisplay
                {
                    ID          = r.ID,
                    Username    = UserMgr.FindById(r.UserId).UserName,
                    RoomNo      = CurRoom.RoomNo,
                    FromDate    = r.FromDate,
                    ToDate      = r.ToDate,
                    IsCancelled = r.IsCancelled ? "Cancelled" : "Normal",
                    UnitPrice   = CurRoom.Price,
                    TotalCost   = r.TotalCost
                };
                if (!r.IsCancelled)
                {
                    Orders.Add(OrderVM);
                }
                else
                {
                    CancelledOrders.Add(OrderVM);
                }
            }

            var tables = new ManageOrdersViewModel
            {
                Orders          = Orders,
                CancelledOrders = CancelledOrders
            };

            return(View(tables));
        }