/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public JsonResult DeleteEmail(int id) { Project_Email email = db.Project_Email.Find(id); db.Project_Email.Remove(email); db.SaveChanges(); var results = new List <int>() { 1 }.ToList(); //1 is good return(Json(results, JsonRequestBehavior.AllowGet)); }
public JsonResult AddEmails(string emailList, int id) { //every line of the json reads every number try { string[] emails = emailList.Split('\n'); string[] distinctEmails = emails.Distinct().ToArray(); //get the list of emails already in the db List <Project_Email> eList = db.Project_Email.Where(x => x.project_id == id).ToList(); foreach (string email in distinctEmails) { if (new EmailAddressAttribute().IsValid(email)) { //checks if this is a valid email address if (!CheckEmailExists(eList, email)) { //the email is not added Project_Email newEmail = new Project_Email(); newEmail.project_id = id; newEmail.email = email; db.Project_Email.Add(newEmail); } } } db.SaveChanges(); var results = new List <int>() { 1 }.ToList(); //1 is good return(Json(results, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var results = new List <int>() { 0 }.ToList(); //0 is bad return(Json(results, JsonRequestBehavior.AllowGet)); } }