// GET: Admin/Home public ActionResult Index() { double totalEarning = 0; var book = _booksManagement.Get(d => d.ID == 7); var booksList = _booksManagement.GetAll(b => DateTime.Equals(b.ArrivalDate, DateTime.Today) && !b.IsCancelled && !b.IsCheckIn).OrderBy(m => m.BookingDate).ToList(); var allBooksList = _booksManagement.GetAll(d => !d.IsCancelled).ToList(); foreach (var item in allBooksList) { totalEarning += ((float)item.Price * (1 - item.Discount) * item.Night); } HomeViewModel model = new HomeViewModel { ContactFormsList = _contactFormsManagement.GetAll().OrderByDescending(m => m.SendedAt).Take(8).ToList(), BooksList = booksList.ToList(), CustomerCount = _customersManagement.GetAll().Count(), BookingCount = _booksManagement.GetAll().Count(), RoomCount = _roomsManagement.GetAll().Count(), TotalEarning = totalEarning, RoomTypeList = _roomTypesManagement.GetAll().ToList(), TestimonialList = _testimonialsManagement.GetAll(t => t.IsShow == true).OrderBy(t => t.OrderSort).ToList() }; return(View(model)); }
public ActionResult NewReservation(int?id) { NewReservationViewModel model = new NewReservationViewModel() { RoomList = _roomsManagement.GetAll().ToList(), RoomTypeList = _roomTypesManagement.GetAll().ToList(), CustomerList = _customersManagement.GetAll().OrderBy(c => c.Name).ToList() }; if (id == null) { model.Book = new Books(); } else { model.Book = _booksManagement.Get(d => d.ID == id); } return(View(model)); }
// GET: Admin/RoomManagement public ActionResult Index() { ShowRoomViewModel model = new ShowRoomViewModel() { RoomList = _roomsManagement.GetAll().OrderBy(r => r.ID).ToList(), BookList = _booksManagement.GetAll().OrderByDescending(b => b.ArrivalDate).ToList() }; foreach (var room in model.RoomList) { List <Books> books = _booksManagement.GetAll(b => b.RoomID == room.ID && !b.IsCancelled).OrderByDescending(b => b.ArrivalDate).Take(1).ToList(); if (books.Count > 0) { if (DateHelper.IncludeDate(books[books.Count - 1].ArrivalDate, books[books.Count - 1].DepartureDate)) { room.Books.Add(books[books.Count - 1]); } } } return(View(model)); }
public string NewBooking(HomeViewModel model) { if (model.Book.ArrivalDate < DateTime.Today) { return("Arrival Date must be greater than today."); } else if (model.Book.ArrivalDate > model.Book.DepartureDate) { return("Departure Date must be greater than Arrival Date."); } bool available = false; model.Book.BookingDate = DateTime.Now; var customer = _customersManagement.Get(c => c.Nation == model.Customer.Nation && c.NationalID == model.Customer.NationalID); var rooms = _roomsManagement.GetAll(r => r.RoomTypeID == model.RoomTypeID).ToList(); if (customer == null) { Customers newCustomer = model.Customer; if (String.IsNullOrEmpty(newCustomer.Email) || String.IsNullOrEmpty(newCustomer.Name)) { return("Your E-Mail and/or Name is empty. Try again"); } _customersManagement.Add(newCustomer); customer = _customersManagement.Get(c => c.Nation == model.Customer.Nation && c.NationalID == model.Customer.NationalID); } model.Book.CustomerID = customer.ID; model.Book.Night = (int)(model.Book.DepartureDate - model.Book.ArrivalDate).TotalDays; if (String.IsNullOrEmpty(customer.Name)) { if (!String.IsNullOrEmpty(model.Customer.Name)) { customer.Name = model.Customer.Name; _customersManagement.Update(customer); } else { return("Your Name is empty."); } } if (String.IsNullOrEmpty(customer.Email)) { if (!String.IsNullOrEmpty(model.Customer.Email)) { customer.Email = model.Customer.Email; _customersManagement.Update(customer); } else { return("Your E-Mail is empty."); } } foreach (var room in rooms) { var books = _booksManagement.GetAll(b => b.RoomID == room.ID).ToList(); if (books.Count == 0) { available = true; } foreach (var book in books) { available = DateHelper.AvailableDate(model.Book.ArrivalDate, model.Book.DepartureDate, book.ArrivalDate, book.DepartureDate); if (!available) { break; } } if (available) { model.Book.RoomID = room.ID; _booksManagement.Add(model.Book); break; } } if (!available) { return("All rooms are reserved. Please, change room type or date and try again."); } return(String.Format($"Your booking has been saved!\nRoom No: {_roomsManagement.Get(r=>r.ID == model.Book.RoomID).RoomNo}\nAll details have been sent to {customer.Email}")); }