public ActionResult ProcessNoMatches() { foreach (string s in Request.Form) { if (s.StartsWith("SyncIt")) { string f1IndividualID = s.Split('-')[1]; Model.F1.person p = this.NoMatches.FindF1PersonByID(f1IndividualID); if (!this.AttributeID.HasValue) { this.AttributeID = this.F1GetAttributeID("SyncMe"); } Model.F1.peopleAttribute peopleAttribute = p.attributes.FindByID(this.AttributeID.Value); if (Request.Form[s].ToString() == "1") { F1toPCO.Model.PCO.person pcop = new F1toPCO.Model.PCO.person(); this.UpdatePerson(p, ref pcop); try { Model.PCO.person createdPerson = this.PCOCreatePerson(this.SerializeEntity(pcop)); if (createdPerson != null) { peopleAttribute.comment = createdPerson.id.Value; this.F1UpdatePeopleAttribute(peopleAttribute); } } catch { this.PersonErrors.Add(p); } } else { this.F1DeletePeopleAttribute(peopleAttribute); } } } this.NoMatches.Clear(); if (this.Matches.Count > 0) { return(RedirectToAction("MultipleMatches")); } return(RedirectToAction("Success")); }
/// <summary> /// /// </summary> /// <param name="peopleAttribute"></param> /// <returns></returns> private bool F1DeletePeopleAttribute(Model.F1.peopleAttribute peopleAttribute) { var request = new RestRequest { Path = string.Format("People/{0}/Attributes/{1}", peopleAttribute.person.id, peopleAttribute.id), VersionPath = "v1", Method = WebMethod.Delete }; RestResponse response = F1Client.Request(request); if (response.StatusCode == HttpStatusCode.NoContent) { return(true); } return(false); }
/// <summary> /// /// </summary> /// <param name="peopleAttribute"></param> /// <returns></returns> private bool F1UpdatePeopleAttribute(Model.F1.peopleAttribute peopleAttribute) { var request = new RestRequest { Path = string.Format("People/{0}/Attributes/{1}", peopleAttribute.person.id, peopleAttribute.id), VersionPath = "v1", Method = WebMethod.Put, Entity = this.SerializeEntity(peopleAttribute) }; RestResponse response = F1Client.Request(request); if (response.StatusCode == HttpStatusCode.OK) { return(true); } return(false); }
public ActionResult ProcessMatches() { foreach (string f1ID in Request.Form) { Model.PCO.person createdPerson = null; Model.F1.person p = this.Matches.FindF1PersonByID(f1ID); if (!this.AttributeID.HasValue) { this.AttributeID = this.F1GetAttributeID("SyncMe"); } Model.F1.peopleAttribute peopleAttribute = p.attributes.FindByID(this.AttributeID.Value); string f1IndividualID = Request.Form[f1ID].ToString(); switch (Request.Form[f1ID].ToString()) { case "0": this.F1DeletePeopleAttribute(peopleAttribute); break; case "-1": Model.PCO.person newPCO = new Model.PCO.person(); this.UpdatePerson(p, ref newPCO); try { createdPerson = this.PCOCreatePerson(this.SerializeEntity(newPCO)); } catch { this.PersonErrors.Add(p); } if (createdPerson != null) { peopleAttribute.comment = createdPerson.id.Value; this.F1UpdatePeopleAttribute(peopleAttribute); } break; default: var pcoPerson = this.Matches.FindPCOPersonByID(Request.Form[f1ID].ToString()); this.UpdatePerson(p, ref pcoPerson); try { this.PCOUpdatePerson(this.SerializeEntity(pcoPerson), Request.Form[f1ID].ToString()); } catch { this.PersonErrors.Add(p); } peopleAttribute.comment = pcoPerson.id.Value; this.F1UpdatePeopleAttribute(peopleAttribute); break; } } this.Matches.Clear(); return(RedirectToAction("Success")); }
public ActionResult Sync() { DateTime?lastRun = null; Model.F1.people f1People = null; Model.PCO.person person = null; //Get the ID of the attribute with the name SyncMe. This is the attribute //that should be added to the people that need to be synced. this.AttributeID = this.F1GetAttributeID("SyncMe"); if (this.AttributeID != 0) { lastRun = this.GetLastRun(); if (lastRun != null) { //Get the people that have been updated since the last time we ran f1People = this.F1GetPeopleByLastUpdatedDate(lastRun.Value.ToString()); } else { //Since we've never run just get all people with the attribute f1People = this.F1GetPeopleByAttribute(this.AttributeID.Value); } //Filter out the people who don't have the SyncMe Attribute. List <Model.F1.person> filteredPeople = f1People.FindByAttributeID(this.AttributeID.Value); foreach (Model.F1.person p in filteredPeople) { //Get the comment for the attribute to see if we already now the PCOID. Model.F1.peopleAttribute peopleAttribute = p.attributes.FindByID(this.AttributeID.Value); if (peopleAttribute != null && !string.IsNullOrEmpty(peopleAttribute.comment)) { /// PCO ID FOUND /// We have the PCO ID and can update the record with confidence that it is /// the correct person. person = this.PCOGetPersonByID(Convert.ToInt32(peopleAttribute.comment)); if (person != null) { try { this.UpdatePerson(p, ref person); this.PCOUpdatePerson(this.SerializeEntity(person), peopleAttribute.comment); } catch { this.PersonErrors.Add(p); } } else { this.NoMatches.Add(new Model.MatchHelperData { F1Person = p, PCOPeople = null }); } } else { /// NO ID FOUND /// /// Didn't find a PCO ID in the attribute so we need to look up by name. Model.PCO.people people = null; people = this.PCOGetPersonByName(p.lastName + ", " + (string.IsNullOrEmpty(p.goesByName) ? p.firstName.Substring(0, 1) : p.goesByName.Substring(0, 1))); var email = p.communications.FindByCommunicationTypeName("Email"); if (email != null) { people.person = people.FindByEmailAddress(email.communicationValue); } switch (people.person.Count) { case 0: this.NoMatches.Add(new Model.MatchHelperData { F1Person = p, PCOPeople = null }); break; case 1: Model.PCO.person matchPerson = people.person.FirstOrDefault(); try { try { this.UpdatePerson(p, ref matchPerson); if (matchPerson.IsDirty) { this.PCOUpdatePerson(this.SerializeEntity(matchPerson), matchPerson.id.Value); } } catch { this.PersonErrors.Add(p); } } catch { this.PersonErrors.Add(p); } peopleAttribute.comment = matchPerson.id.Value; this.F1UpdatePeopleAttribute(peopleAttribute); break; default: this.Matches.Add(new Model.MatchHelperData { F1Person = p, PCOPeople = people }); break; } } } if (this.NoMatches.Count > 0) { return(RedirectToAction("NonMatches")); } if (this.Matches.Count > 0) { return(RedirectToAction("MultipleMatches")); } return(RedirectToAction("Success")); } else { return(View("NoAttribute")); } }