public ActionResult NewCustomer(int?id) { NewCustomerViewModel model = new NewCustomerViewModel(); model.GenderList = EnumHelpers.ConvertEnumToList(typeof(Genders)); List <string> CountryList = new List <string>(); CultureInfo[] CInfoList = CultureInfo.GetCultures(CultureTypes.SpecificCultures); foreach (CultureInfo CInfo in CInfoList) { RegionInfo R = new RegionInfo(CInfo.LCID); if (!(CountryList.Contains(R.EnglishName))) { CountryList.Add(R.EnglishName); } } CountryList.Sort(); ViewBag.CountryList = CountryList; if (id == null) { model.Customer = new Customers(); } else { model.Customer = _customersManagement.Get(d => d.ID == id); model.BookList = _booksManagement.GetAll(b => b.CustomerID == id && !b.IsCancelled).OrderBy(b => b.ArrivalDate).ToList(); } 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}")); }