public ActionResult ProposeConstituentChanges(int?id) { // If the id parameter is null, give a "bad request" error if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // The parameter wasn't null -- try and find the associated Constituent in the proposed changes table first ProposedConstituentsChanges changes = unitOfWork.Changes.Find(x => x.ConstituentID == id).FirstOrDefault(); if (changes == null) { // Nothing in the proposed changes table yet -- look them up in the main Constituents table Constituent constituent = unitOfWork.Constituents.Find(x => x.ConstituentID == id).FirstOrDefault(); // If there wasn't a match with this id, give a "not found" error if (constituent == null) { return(HttpNotFound()); } // Found a match in the main Constituents table -- return the view with the Constituent return(PartialView("_ProposeChanges", constituent)); } // If we got this far, we found a match in the proposed changes table -- copy values over to send to the view var existingConstituent = new Constituent { ConstituentID = changes.ConstituentID, PrimaryAddressee = changes.PrimaryAddressee, PreferredAddressLine1 = changes.PreferredAddressLine1, PreferredAddressLine2 = changes.PreferredAddressLine2, PreferredAddressLine3 = changes.PreferredAddressLine3, PreferredCity = changes.PreferredCity, PreferredState = changes.PreferredState, PreferredZIP = changes.PreferredZIP, PhoneNumber = changes.PhoneNumber, MobilePhoneNumber = changes.MobilePhoneNumber, AlternatePhoneNumber = changes.AlternatePhoneNumber, Deceased = changes.Deceased, DonationStatus = changes.DonationStatus, UniversityRelationship = changes.UniversityRelationship, CallPriority = changes.CallPriority }; // Return the view with the Constituent return(PartialView("_ProposeChanges", existingConstituent)); }
public ActionResult ProposeConstituentChanges(Constituent model) { // Check if the model state is valid before trying to do anything with it if (ModelState.IsValid) { // Check if this Constituent exists in the proposed changes table already var existingEntry = unitOfWork.Changes.Find(x => x.ConstituentID == model.ConstituentID).FirstOrDefault(); // If there isn't an existing entry, create a new one for the table if (existingEntry == null) { // If it's in a valid state, create a new entry in the proposed changes table var proposedChanges = new ProposedConstituentsChanges { ConstituentID = model.ConstituentID, PrimaryAddressee = model.PrimaryAddressee, PreferredAddressLine1 = model.PreferredAddressLine1, PreferredAddressLine2 = model.PreferredAddressLine2, PreferredAddressLine3 = model.PreferredAddressLine3, PreferredCity = model.PreferredCity, PreferredState = model.PreferredState, PreferredZIP = model.PreferredZIP, PhoneNumber = model.PhoneNumber, MobilePhoneNumber = model.MobilePhoneNumber, AlternatePhoneNumber = model.AlternatePhoneNumber, Deceased = model.Deceased, DonationStatus = model.DonationStatus, UniversityRelationship = model.UniversityRelationship, CallPriority = model.CallPriority }; unitOfWork.Changes.Add(proposedChanges); unitOfWork.Complete(); } // An entry existed already -- overwrite the values with the new changes else { unitOfWork.Entry(existingEntry).CurrentValues.SetValues(model); unitOfWork.Complete(); } } // If we got this far, something went wrong -- return the view with the model return(PartialView("_ProposeChanges", model)); }
public ActionResult DenyConstituentChanges(int?id) { // Find the entry associated with this Constituent in the proposed changes table ProposedConstituentsChanges proposedChanges = unitOfWork.Changes.Find(x => x.ConstituentID == id).FirstOrDefault(); // If we found an entry, delete it if (proposedChanges != null) { // Remove the entry and save the database unitOfWork.Changes.Remove(proposedChanges); unitOfWork.Complete(); // Success - return the view containing proposed changes return(RedirectToAction("ReviewProposedConstituentChanges")); } // If we get this far, something went wrong -- return the 'Error' view return(View("Error")); }
public ActionResult ApproveConstituentChanges(int?id) { // Make sure the model is in a valid state before trying to do anything with it if (id != null) { // Find the entry for this Constituent in the master Constituent table Constituent original = unitOfWork.Constituents.Find(x => x.ConstituentID == id).FirstOrDefault(); // Find the entry for this Constituent in the proposed changes table ProposedConstituentsChanges proposedChanges = unitOfWork.Changes.Find(x => x.ConstituentID == id).FirstOrDefault(); // If we found an entry, update the values if (original != null) { // Calculate their latitude and longitude if the primary address changed if (original.PreferredAddressLine1 != proposedChanges.PreferredAddressLine1) { Geolocation geo = new Geolocation(); geo.GetGeocode(proposedChanges.getFullAddress()); original.Latitude = Convert.ToDecimal(geo.Latitude); original.Longitude = Convert.ToDecimal(geo.Longitude); } // Update the original values with the changes unitOfWork.Entry(original).CurrentValues.SetValues(proposedChanges); // Remove the entry associated with this Constituent from the proposed changes table unitOfWork.Changes.Remove(proposedChanges); // Save the changes to the database unitOfWork.Complete(); // Success - return the view containing proposed changes return(RedirectToAction("ReviewProposedConstituentChanges")); } } // If we get this far, something went wrong -- return the 'Error' view return(View("Error")); }