// GET public ActionResult VisitorActions(int id) { // [email protected] VisitorActionsViewModel visitorActionsViewModel = new VisitorActionsViewModel() { Parishes = new Parish(), ContactList = new ContactList(), Donations = new Donation() }; ViewBag.ParishID = id; return(View(visitorActionsViewModel)); }
public ActionResult VisitorActions(VisitorActionsViewModel visitorActionsViewModel, string SignUp, string Comment) { Parish thisParish = new Parish(); People thisPerson = new People(); // [email protected] // Comment: if the Parish is Receiving comments, prepend to the Comments field if (Comment != "") { // TODO - add the HiddenFor to the control based on thisParish.RecieveComments thisParish = db.Parishes.Where(p => p.ID == visitorActionsViewModel.Parishes.ID).First(); if (thisParish.RecieveComments) { // Get the sender's first name: string thisUserID = User.Identity.GetUserId(); thisPerson = db.Peoples.Where(w => w.ApplicationUserId == thisUserID).First(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("=========================\n"); stringBuilder.Append(thisPerson.FirstName); stringBuilder.Append(" "); stringBuilder.Append(thisPerson.LastName); stringBuilder.Append(" says:\n"); stringBuilder.Append(Comment); stringBuilder.Append("\n"); stringBuilder.Append(thisParish.Comments ?? ""); //stringBuilder.Append(asdf); //thisParish.Comments = // "=========================\n" + // thisPerson.FirstName + " " + thisPerson.LastName + " says:\n" + // Comment + "\n" + // thisParish.Comments ?? ""; thisParish.Comments = stringBuilder.ToString(); db.SaveChanges(); } } if (SignUp.ToUpper() == "Y") { // search the ContactList table for a record with the parishID & user's ID; // if the record is not there, add it // if the parish or the user is null, get them if (thisParish.ID == 0) { thisParish = db.Parishes.Where(p => p.ID == visitorActionsViewModel.Parishes.ID).First(); } if (thisPerson.ID == 0) { string thisUserID = User.Identity.GetUserId(); thisPerson = db.Peoples.Where(w => w.ApplicationUserId == thisUserID).First(); } // Search int count = db.ContactLists.Where(c => c.ParishId == thisParish.ID && c.PeopleId == thisPerson.ID).Count(); if (count == 0) { ContactList contactList = new ContactList(); contactList.ParishId = thisParish.ID; contactList.PeopleId = thisPerson.ID; db.ContactLists.Add(contactList); db.SaveChanges(); } } return(RedirectToAction("Index")); }