// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Prospect).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProspectExists(Prospect.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // REPOPULATE DROPDOWN IF VALIDATION ERROR OCCURS ViewData["CityId"] = new SelectList(_context.City, "Id", "Name"); // Sales Office email validation var e = SalesOffice.Email; bool eAlreadyExists = await _context.SalesOffice.AnyAsync(x => x.Email == e); if (eAlreadyExists) { ModelState.AddModelError("SalesOffice.Email", "Email already exists"); } if (!ModelState.IsValid) { return(Page()); } _context.SalesOffice.Add(SalesOffice); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // City Name Validation var n = City.Name; bool nAlreadyExists = await _context.City.AnyAsync(x => x.Name == n); if (nAlreadyExists) { ModelState.AddModelError("City.Name", "City Name already exists"); } if (!ModelState.IsValid) { return(Page()); } _context.City.Add(City); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Prospect.Add(Prospect); await _context.SaveChangesAsync(); return(RedirectToPage("./ThankYou")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Prospect = await _context.Prospect.FindAsync(id); if (Prospect != null) { _context.Prospect.Remove(Prospect); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } City = await _context.City.FindAsync(id); if (City != null) { _context.City.Remove(City); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // REPOPULATE DROPDOWN IF VALIDATION ERROR OCCURS ViewData["SalesOfficeId"] = new SelectList(_context.SalesOffice, "Id", "Name"); // Agent email validation var e = Agent.Email; var currentId = Agent.Id; bool eAlreadyExists = await _context.Agent.AnyAsync(x => x.Email == e && x.Id != currentId); if (eAlreadyExists) { ModelState.AddModelError("Agent.Email", "Email already exists"); } if (!ModelState.IsValid) { return(Page()); } _context.Attach(Agent).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AgentExists(Agent.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } SalesOffice = await _context.SalesOffice.FindAsync(id); if (SalesOffice != null) { _context.SalesOffice.Remove(SalesOffice); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Dwelling = await _context.Dwelling.FindAsync(id); if (Dwelling != null) { _context.Dwelling.Remove(Dwelling); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // City Name Validation var n = City.Name; var currentId = City.Id; bool nAlreadyExists = await _context.City.AnyAsync(x => x.Name == n && x.Id != currentId); if (nAlreadyExists) { ModelState.AddModelError("City.Name", "City Name already exists"); } if (!ModelState.IsValid) { return(Page()); } _context.Attach(City).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CityExists(City.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // REPOPULATE DROPDOWN IF VALIDATION ERROR OCCURS ViewData["AgentId"] = new SelectList(_context.Agent, "Id", "FullName"); ViewData["CityId"] = new SelectList(_context.City, "Id", "Name"); ViewData["SalesOfficeId"] = new SelectList(_context.SalesOffice, "Id", "Name"); //Validation for Date of Listing to be not a future date var ListYear = Dwelling.DateOfListing.Year; var CurrentYear = DateTime.Now.Year; var ListMonth = Dwelling.DateOfListing.Month; var CurrentMonth = DateTime.Now.Month; var ListDay = Dwelling.DateOfListing.Day; var CurrentDay = DateTime.Now.Day; if (CurrentYear < ListYear) { ModelState.AddModelError("Dwelling.DateOfListing", "Date Of Listing cannot be in future"); } if (CurrentYear == ListYear && CurrentMonth < ListMonth) { ModelState.AddModelError("Dwelling.DateOfListing", "Date Of Listing cannot be in future"); } if (CurrentYear == ListYear && CurrentMonth == ListMonth && CurrentDay < ListDay) { ModelState.AddModelError("Dwelling.DateOfListing", "Date Of Listing cannot be in future"); } //Validation for Date of Listing cannot be past a year if (CurrentYear > ListYear) { if (CurrentMonth > ListMonth) { ModelState.AddModelError("Dwelling.DateOfListing", "Date Of Listing cannot be past a year"); } if (CurrentMonth == ListMonth && CurrentDay > ListDay) { ModelState.AddModelError("Dwelling.DateOfListing", "Date Of Listing cannot be past a year"); } } //Validation for Listed Price to not be less than $1000 //decimal Price = Dwelling.ExpectedPrice.Value; //if (Price < 1000) { // ModelState.AddModelError("Dwelling.ExpectedPrice", "Price of Listed Property cannot be less than $1000"); } if (!ModelState.IsValid) { return(Page()); } _context.Attach(Dwelling).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DwellingExists(Dwelling.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }