// [Route]
        public ActionResult Manage(string options, string search)
        {
            string hotelName = HotelName.GetHotelName(User.Identity.GetUserName());
            var    all       = db.Customer.Where(x => x.HotelName == hotelName).ToList();

            if (options == "1")
            {
                all = db.Customer.Where(x => x.Name.StartsWith(search) && x.HotelName == hotelName || search == null).ToList();
            }
            else if (options == "2")
            {
                all = db.Customer.Where(x => x.Surname.StartsWith(search) && x.HotelName == hotelName || search == null).ToList();
            }
            else if (options == "3")
            {
                all = db.Customer.Where(x => x.Date_from.ToString() == search && x.HotelName == hotelName || search == null).ToList();
            }
            else if (options == "4")
            {
                all = db.Customer.Where(x => x.Date_to.ToString() == search && x.HotelName == hotelName || search == null).ToList();
            }
            else if (options == "5")
            {
                all = db.Customer.Where(x => x.Room.ToString() == search && x.HotelName == hotelName || search == null).ToList();
            }

            ManageViewModel vm = new ManageViewModel()
            {
                Tuples = all
            };

            return(View(vm));
        }
Exemplo n.º 2
0
 public ActionResult Add(Customer customer)
 {
     customer.HotelName = HotelName.GetHotelName(User.Identity.GetUserName());
     ViewBag.Number     = 0;
     if (customer.Date_from.CompareTo(customer.Date_to) == 1)
     {
         ViewBag.Message = "Invalid date! The starting date cannot be later than the ending date.";
         return(View("Add", customer));
     }
     else
     {
         if (!CheckAndAdd.CheckDays(customer.Date_from, customer.Date_to, customer.Room, customer.HotelName))
         {
             ViewBag.Message = "The chosen date is already resereved for this room.";
             return(View("Add", customer));
         }
         else
         {
             if (!ModelState.IsValid)
             {
                 return(View("Add", customer));
             }
             else
             {
                 db.Customer.Add(customer);
                 db.SaveChanges();
                 ViewBag.Message = "Reservation has been added successfully!";
                 ViewBag.Number  = 1;
                 return(View("Add"));
             }
         }
     }
 }
        public ActionResult Edit(int id)
        {
            var    customer  = db.Customer.Single(x => x.CustomerId == id);
            string hotelName = HotelName.GetHotelName(User.Identity.GetUserName());

            if (customer.HotelName == hotelName)
            {
                return(View(customer));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult Delete(int id)
        {
            string hotelName = HotelName.GetHotelName(User.Identity.GetUserName());
            var    customer  = db.Customer.Single(x => x.CustomerId == id);

            if (customer.HotelName == hotelName)
            {
                HSSContext db = new HSSContext();
                var        x  = db.Customer.First(u => u.CustomerId == id);
                db.Customer.Remove(x);
                db.SaveChanges();
                return(View());
            }
            else
            {
                return(RedirectToAction("Manage"));
            }
        }