public async Task <IActionResult> PutSeatBooking([FromRoute] int id, [FromBody] SeatBooking seatBooking) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != seatBooking.ID) { return(BadRequest()); } _context.Entry(seatBooking).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SeatBookingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("ID,Name")] Students students) { if (ModelState.IsValid) { students.Email = _userManager.GetUserName(User); _context.Add(students); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(students)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,maxSeats,nearlyFullSeats,plentySeats")] SiteSettings siteSettings) { if (id != siteSettings.Id) { return(NotFound()); } if (ModelState.IsValid) { try { //get the existing ID so we don't make a new row var rowid = _context.SiteSettings.Select(a => a.Id).FirstOrDefault(); siteSettings.Id = rowid; _context.Update(siteSettings); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SiteSettingsExists(siteSettings.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Create", "SeatBookings")); } return(View(siteSettings)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,isVisibleS1L,isVisibleS2L,isVisibleS3L,isVisibleS4L,isVisibleS5L,isVisibleS6L,isVisibleS7L,isVisibleS8L,isVisibleS9L,isVisibleS10L,isVisibleS11L,isVisibleS12L,isVisibleS13L,isVisibleS14L,isVisibleS15L,isVisibleS16L")] AdminData adminData) { if (id != adminData.Id) { return(NotFound()); } if (ModelState.IsValid) { try { //get the existing ID so we don't make a new row var rowid = _context.AdminData.Select(a => a.Id).FirstOrDefault(); adminData.Id = rowid; _context.Update(adminData); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdminDataExists(adminData.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Create", "SeatBookings")); // return RedirectToAction(nameof(Index)); } return(View(adminData)); }
public async Task <IActionResult> Create([Bind("ID,SeatDate,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14,S15 ")] SeatBooking seatBooking) { //Show data for the next 4 weeks ViewData["CheckFullSession"] = _sessions.GetSingleWeekStats(seatBooking.SeatDate); if (ModelState.IsValid) { //Save locally for sending to calendar in GenerateCalendarEvents _dbCallsSessionDataDTO.AllSeatBookings.Add(seatBooking); //get the user email seatBooking.StudentEmail = _userManager.GetUserName(User); //get the user name var name = _context.Students.Where(s => s.Email == seatBooking.StudentEmail).Select(s => s.Name).FirstOrDefault(); //add to the booking seatBooking.Name = name.ToString(); // get session with the same date and same email // UPDATE them if they exist //var matchSeatBooking = _context.SeatBooking.FirstOrDefault(s => s.SeatDate == seatBooking.SeatDate && s.StudentEmail == _userManager.GetUserName(User)); //if (matchSeatBooking != null) //{ // //just need the id of the saved entry // seatBooking.ID = matchSeatBooking.ID; // matchSeatBooking.ID = 10000; //need to get rid of the other id throws an error // //update the existing record // _context.Update(seatBooking); //} //else //{//create a new record // _context.Add(seatBooking); //} _context.Add(seatBooking); await _context.SaveChangesAsync(); //delete out old session booking to keep db small await DeleteOldSessionBookings(); return(RedirectToAction(nameof(Index))); } return(View(seatBooking)); }
/// <summary> /// Add users to the local DB NOTE this is mostly for Google, as it doesn't use the Register, it just logs in. /// </summary> /// <param name="Email">there will always be an email from the login</param> /// <param name="Name">There will only be a name if they login with Google. </param> /// <returns></returns> public void AddUserToStudentDB(string Email, string Name) { //check if there is a Name in the Students table string studentEmail = Email; // _userManager.GetUserName(_userManager.GetUserName(User)); string studentName = Name; //Check if they in the DB var student = _context.Students.FirstOrDefault(m => m.Email == studentEmail); //No entry if (student == null) { //No match lets add it in if we have the Student name from Google Students myStudent = new Students { Name = studentName, Email = studentEmail }; _context.Add(myStudent); _context.SaveChangesAsync(); } }