public ActionResult CreateNewContactForVolunteer(EmergencyContact model) { model.contactName = stringToTitleCase(model.contactName); model.createDate = DateTime.Now; db.EmergencyContacts.Add(model); db.SaveChanges(); return RedirectToAction("Edit/" + model.volunteerId, "Volunteer"); }
public EmergencyContact CreateContactForNewVolunteer(VolunteerContactModel model) { EmergencyContact contact = new EmergencyContact(); contact.volunteerId = model.volunteerId; contact.contactName = stringToTitleCase(model.contactName); contact.relationship = model.relationship; contact.emergencyPhone = model.emergencyPhone; contact.comment = model.comment; contact.createDate = DateTime.Now; db.EmergencyContacts.Add(contact); db.SaveChanges(); return db.EmergencyContacts.Where(e => e.volunteerId == contact.volunteerId).FirstOrDefault(); }
private void CreateContact(VolunteerContactModel model) { if (model != null) { EmergencyContact target = new EmergencyContact(); if (db.EmergencyContacts.Where(m => m.contactId == model.contactId).FirstOrDefault() == null) { target.volunteerId = model.volunteerId; target.contactName = model.contactName; target.relationship = model.relationship; target.emergencyPhone = model.emergencyPhone; target.comment = model.comment; db.EmergencyContacts.Add(target); db.SaveChanges(); } } }
public ActionResult Contact_Create([DataSourceRequest] DataSourceRequest request, VolunteerContactModel model) { int id = 0; var session = HttpContext.Session; if (session != null) { if (session["VolunteerId"] != null) { id = int.Parse(session["VolunteerId"].ToString()); } } if (model != null) { EmergencyContact target = new EmergencyContact(); if (db.EmergencyContacts.Where(m => m.contactId == model.contactId).FirstOrDefault() == null) { target.volunteerId = id; target.contactName = model.contactName; target.relationship = model.relationship; target.emergencyPhone = model.emergencyPhone; target.comment = model.comment; db.EmergencyContacts.Add(target); db.SaveChanges(); } } return Json(ModelState.ToDataSourceResult()); }
private void InsertOrUpateEmergencyContact(SmsCsvModel item) { var v = db.Volunteers.Where(model => model.constituentCode == item.constituentCode); if (v.FirstOrDefault() != null) { Volunteer volunteer = v.FirstOrDefault(); var contact = db.EmergencyContacts.Where(l => l.volunteerId == volunteer.volunteerId); if (contact.FirstOrDefault() == null) { // insert into database EmergencyContact newContact = new EmergencyContact(); newContact.volunteerId = volunteer.volunteerId; newContact.contactName = convertNullToString(item.contactName); newContact.relationship = convertNullToString(item.relationship); newContact.emergencyPhone = convertNullToString(item.emergencyPhone); newContact.comment = convertNullToString(item.comment); DateTime dateTime = parseStringToDateTime(item.dateGiven); newContact.createDate = dateTime; db.EmergencyContacts.Add(newContact); db.SaveChanges(); } else { // update into database EmergencyContact existContact = contact.FirstOrDefault(); existContact.volunteerId = volunteer.volunteerId; existContact.contactName = convertNullToString(item.contactName); existContact.relationship = convertNullToString(item.relationship); existContact.emergencyPhone = convertNullToString(item.emergencyPhone); existContact.comment = convertNullToString(item.comment); DateTime dateTime = parseStringToDateTime(item.dateGiven); existContact.createDate = dateTime; db.Entry(existContact).State = EntityState.Modified; db.SaveChanges(); } } }