public IActionResult Reservation() { //Getting a list of sittings from the db List <Sitting> s = _reservationServices.GetListSitting(); //checking UserID var UserID = _userManager.GetUserId(HttpContext.User); //If the UserID is not null, in other words if the user is logged in. if (UserID != null) { //We assign the User based on their Id to the "user" variable var user = _context.Users.Where(r => r.Id == UserID).FirstOrDefault(); //putting the data in the "m" viewmodel ReservationCreateModel m = new ReservationCreateModel { //customer details FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, PhoneNumber = user.PhoneNumber, //sittings details AllSittings = s }; //Return the view with the data from the view model. return(View(m)); } else { //Otherwise we only return the sittings ReservationCreateModel model = new ReservationCreateModel { AllSittings = s }; return(View(model)); } }
public IActionResult Index() { var Sittings = _services.GetListSitting(); ReportViewModel model = new ReportViewModel() { //for Sittings AllSittings = Sittings, SittingID = Sittings[0].SittingID }; try { List <Sitting> s = _services.GetListSitting(); List <Reservation> Rs = _services.GetAllReservation(); int cs = 0; foreach (Reservation r in Rs) { Table_Reservation td = _services.GetTable_ReservationById(r.ReservationID); if (td != null) { Table t = _services.GetTableByID(td.TableID); //area if (t.Area == "Main Room") { model.MainRoom++; } if (t.Area == "Balcony") { model.Balcony++; } if (t.Area == "Outside") { model.OutSide++; } } cs = cs + r.NumberOfGuests; //source if (r.Source == "WebSite") { model.Website++; } if (r.Source == "Mobile") { model.Mobile++; } if (r.Source == "Walk in") { model.InPErson++; } //sitting if (r.SittingID == s[0].SittingID) { model.Breakfast++; } if (r.SittingID == s[1].SittingID) { model.Lunch++; } if (r.SittingID == s[2].SittingID) { model.Dinner++; } } model.Reservations = Rs.Count(); model.Clients = cs; return(View(model)); } catch { return(RedirectToAction("Error", "Home")); } }