示例#1
0
        public ActionResult EditRoom(int?id)
        {
            if (id == null)
            {
                return(View("Error"));
            }

            GetRoomById_Result RoomToEdit;

            RoomToEdit = _context.GetRoomById(id).FirstOrDefault();
            if (RoomToEdit == null)
            {
                return(View("Error"));
            }

            EditRoomViewModel RoomVM = new EditRoomViewModel
            {
                ID           = RoomToEdit.ID,
                RoomNo       = RoomToEdit.RoomNo,
                IsACEquipped = RoomToEdit.IsACEquipped,
                IsDisabled   = RoomToEdit.IsDisabled,
                Price        = RoomToEdit.Price,
                RmType       = Enum.GetName(typeof(RoomType), RoomToEdit.RmType),
                NoOfBeds     = Enum.GetName(typeof(BedNo), RoomToEdit.NoOfBeds),
            };

            return(View(RoomVM));
        }
        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));
        }