public async Task <IActionResult> OnPostAsync() { //modifies the selected field in that database that has been changed and saves the database if (!ModelState.IsValid) { return(Page()); } _context.Attach(Pet).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { //if pet does not exist then return not found else throw an exception if (!PetExists(Pet.PetID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { //modifies the selected field in that database that has been changed and saves the database if (!ModelState.IsValid) { return(Page()); } _context.Attach(Sitter).State = EntityState.Modified; try { await _context.SaveChangesAsync(); HttpContext.Session.SetString(SessionKeySitterID, Sitter.ID.ToString());///// } catch (DbUpdateConcurrencyException) { //if sitter does not exist then return not found else throw an exception if (!SitterExists(Sitter.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } //set sitter ID to that in the session variable so that it matches the sitter ID //for their email address rather than generating a new one int SitterID = Convert.ToInt32(HttpContext.Session.GetString(SessionKeySitterID)); Sitter.ID = SitterID; //settting inital of town entered to uppercase Sitter.Town = Sitter.Town.First().ToString().ToUpper() + Sitter.Town.Substring(1); //open sitter database connection _context.Database.OpenConnection(); try { //add sitter to the database and save changes _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Sitter ON");//set identity to on _context.Sitter.Add(Sitter); await _context.SaveChangesAsync(); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Sitter OFF");//set identity off } finally { //close database connection _context.Database.CloseConnection(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { //saves the pet to the database and returns to the index page if (!ModelState.IsValid) { return(Page()); } _context.Pet.Add(Pet); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { //saves the review to the database and returns to the index page if (!ModelState.IsValid) { return(Page()); } _context.Review.Add(Review); await _context.SaveChangesAsync(); return(RedirectToPage("./CustomerReview")); }
public async Task <IActionResult> OnPostAsync() { Sitters = await _context.Sitter.ToListAsync(); Bookings = await _context.Booking.ToListAsync(); if (!ModelState.IsValid) { return(Page()); } if (!SocialMediaExists(SocialMedia.ID)) { _context.Database.OpenConnection(); try { //add customer to the database and save changes _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.SocialMedia ON");//set identity to on _context.SocialMedia.Add(SocialMedia); await _context.SaveChangesAsync(); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.SocialMedia OFF");//set identity off } finally { //close datbabase connection _context.Database.CloseConnection(); } } else { _context.Attach(SocialMedia).State = EntityState.Modified; await _context.SaveChangesAsync(); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } //select booking from the ID that matches that of the parameter passed in and delete from database and then save changes. Booking = await _context.Booking.FindAsync(id); if (Booking != null) { _context.Booking.Remove(Booking); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } //finds the pet in the database by looking for the ID passed through the parameter and removes in and saves the database Pet = await _context.Pet.FindAsync(id); if (Pet != null) { _context.Pet.Remove(Pet); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } //finds the review in the database by looking for the ID passed through the parameter and removes in and saves the database Review = await _context.Review.FindAsync(id); if (Review != null) { _context.Review.Remove(Review); await _context.SaveChangesAsync(); } return(RedirectToPage("./CustomerReview")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } //set customer ID to that in the session variable so that it matches the customers ID //for their email address rather than generating a new one int CustID = Convert.ToInt32(HttpContext.Session.GetString(SessionKeyCustomerID)); Customer.ID = CustID; //settting inital of town entered to uppercase Customer.Town = Customer.Town.First().ToString().ToUpper() + Customer.Town.Substring(1); //open customer database connection _context.Database.OpenConnection(); try { //add customer to the database and save changes _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Customer ON");//set identity to on _context.Customer.Add(Customer); await _context.SaveChangesAsync(); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Customer OFF");//set identity off } finally { //close datbabase connection _context.Database.CloseConnection(); } //if customer log in variable is not null then redirect to booking review // - - meaning customer has made a booking and needs to create an account to proceed //else return to index page - meaning customer is just logging into their account and have not made a booking if (HttpContext.Session.GetString(SessionKeyLogIn) != null) { return(RedirectToPage("../BookingReview")); } else { return(RedirectToPage("./Index")); } }