public ActionResult Create([Bind(Include = "ID,BoardContPosition, BoardContWorkAddy, BoardContWorkPhone, BoardContCellPhone,BoardContFaxNum,BoardContPartnerName")] BoardContact boardContact, string selectedUsers) { try { if (selectedUsers != null) { var userToAdd = db.Users.Find(selectedUsers); boardContact.AppUser = userToAdd; // } if (ModelState.IsValid) { db.BoardContacts.Add(boardContact); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(boardContact)); }
public ActionResult DeleteConfirmed(int id) { BoardContact boardContact = db.BoardContacts.Find(id); db.BoardContacts.Remove(boardContact); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create() { BoardContact boardContact = new BoardContact(); boardContact.AppUser = new ApplicationUser(); PopulateAssignedUsers(boardContact); return(View()); }
public ActionResult Edit([Bind(Include = "ID,BoardContPosition,BoardContWorkAddy,BoardContWorkPhone,BoardContCellPhone,BoardContFaxNum,BoardContPartnerName")] BoardContact boardcontact) { if (ModelState.IsValid) { db.Entry(boardcontact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(boardcontact)); }
public ActionResult Index(int?id) { BoardContact bc = new BoardContact(); StaffContact sc = new StaffContact(); PopulateAssignedUsers(bc); ViewData["Contact"] = db.BoardContacts.ToList(); ViewData["StaffContact"] = db.StaffContacts.ToList(); ViewData["ContactID"] = id; BoardContact contact = db.BoardContacts.Find(id); return(View(contact)); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BoardContact boardContact = db.BoardContacts.Find(id); if (boardContact == null) { return(HttpNotFound()); } return(View(boardContact)); }
// public void PopulateJobDescriptions(BoardContact contact) // { // var jobDescriptions = db.JobDescriptions; // var aJobs = new HashSet<int>(contact.JobDescriptions.Select(r => r.ID)); // var viewModel = new List<JobDescVM>(); // foreach (var job in jobDescriptions) // { // viewModel.Add(new JobDescVM // { // JobID = job.ID, // JobName = job.JobTitle, // JobDesc = job.JobDescpt, // JobAssigned = aJobs.Contains(job.ID) // }); // } // ViewBag.JobDescriptions = viewModel; // } // private void UpdateJobDescriptions(string[] selectedJobs, BoardContact ContactToUpdate) // { // if (selectedJobs == null) // { // ContactToUpdate.JobDescriptions = new List<JobDescription>(); // return; // } // var selectedJobsHS = new HashSet<string>(selectedJobs); // var meetingJobs = new HashSet<int>(ContactToUpdate.JobDescriptions.Select(c => c.ID)); // foreach (var jobs in db.JobDescriptions) // { // if (selectedJobsHS.Contains(jobs.ID.ToString())) // { // if (!meetingJobs.Contains(jobs.ID)) // { // ContactToUpdate.JobDescriptions.Add(jobs); // } // } // else // { // if (meetingJobs.Contains(jobs.ID)) // { // ContactToUpdate.JobDescriptions.Remove(jobs); // } // } // } // } public void PopulateAssignedUsers(BoardContact boardCont) { var allUsers = db.Users; var veiwModel = new List <UserVM>(); foreach (var m in allUsers) { veiwModel.Add(new UserVM { UserID = m.Id, UserFName = m.UserFName, UserLName = m.UserLName, UserFullName = m.UserFName + " " + m.UserLName + ", " + m.UserName }); } ViewBag.User = veiwModel; }