public IActionResult DeleteIncident(string id) { using (mypidbContext db = new mypidbContext()) { IncidentData deleteMe = db.IncidentData.Where(x => x.IncidentId == id).FirstOrDefault(); db.IncidentData.Remove(deleteMe); db.SaveChanges(); return(RedirectToAction("EmpTable")); } }
public IActionResult EditComment(string id, IncidentData updatedIncident) { using (mypidbContext db = new mypidbContext()) { IncidentData incident = db.IncidentData.Where(x => x.IncidentId == id).FirstOrDefault(); if (incident != null) { incident.AdminComments = updatedIncident.AdminComments; db.SaveChanges(); } } return(RedirectToAction("EmpTable")); }
public ActionResult Register(HomeAccount account) { Console.WriteLine("User input data, from register"); Console.WriteLine("Username: "******"Password: "******"Email: " + account.EmailAddress); Console.WriteLine("First Name: " + account.FirstName); Console.WriteLine("Last Name: " + account.LastName); Console.WriteLine("Address: " + account.HomeAccountAddress); Console.WriteLine("PIN: " + account.AccountPin); Console.WriteLine("Phone Number: " + account.PhoneNumber); if (account.AccountPin == 0) { ViewBag.Message = "Unable to register, PIN must be a numerical value"; } else if (account.PhoneNumber == 0 || account.PhoneNumber.ToString().Length != 10) { ViewBag.Message = "Unable to register, phone number must be valid"; } else if (!isValidEmail(account.EmailAddress)) { ViewBag.Message = "Unable to register, invalid email address"; } else { try { using (mypidbContext db = new mypidbContext()) { db.HomeAccount.Add(account); db.SaveChanges(); } ViewBag.Message = account.EmailAddress + " successfully registered"; } catch { ViewBag.Message = "Unable to register user, please try again."; } } return(View()); }