예제 #1
0
        public ActionResult EditOrder(EditOrderViewModel model)
        {
            GetOrderById_Result CurOrder = new HotelConnection().GetOrderById(model.ID).FirstOrDefault();

            if (ModelState.IsValid)
            {
                List <int>    UnAvailableRooms   = _context.GetOrders().Where(order => ((order.ID != model.ID) && !order.IsCancelled && !(order.FromDate >= model.ToDate || order.ToDate <= model.FromDate))).Select(r => r.RoomId).ToList();
                HashSet <int> UnAvailableRoomIds = new HashSet <int>(UnAvailableRooms);

                if (UnAvailableRoomIds.Contains(model.RoomId))
                {
                    ModelState.AddModelError("", "Room not available at designated date range!");
                    return(View(model));
                }
                else
                {
                    _context.UpdateExistingOrder(model.ID, model.UserId, model.RoomId, model.FromDate, model.ToDate, model.IsCancelled, model.TotalCost);
                }

                return(RedirectToAction("ManageOrders"));
            }
            PopulateUserDropDownList(CurOrder.UserId);
            PopulateRoomDropDownList(CurOrder.RoomId);
            return(View(model));
        }