public string Get(string keys) { string ids_ = string.Empty; string header = string.Empty; string key1 = string.Empty; string key2 = string.Empty; if (keys.Contains(";") == true) { string[] splited = keys.Split(";"); key1 = splited[0]; key2 = splited[1]; } DictionaryHelper.d.TryGetValue(key1, out ids_); DictionaryHelper.d.TryGetValue(key2, out header); string[] finalHeader = new string[45]; if (header != null) { finalHeader = ControllerHelper.SplitedHeader(header); } string jsonstring = ""; string[] auxstring = ids_.Split("((("); string properties = auxstring[1]; string[] ids = auxstring[0].Split(","); if (ids[0].Contains("sponsorCSV")) { var sponsorcollection = sponsorManager.GetListOfSponsors(); for (int i = 1; i < ids.Length; i++) { if (properties.Contains("0")) { var sponsor = sponsorcollection.AsQueryable().Where(z => z._id == ids[i]); jsonstring = jsonstring + JsonConvert.SerializeObject(sponsor); } else { bool first = true; Sponsor sponsor = sponsorcollection.AsQueryable().Where(z => z._id == ids[i]).First(); jsonstring = jsonstring + "[{"; if (properties.Contains("1")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[0] + "\":" + "\"" + sponsor.NameOfSponsor + "\""; first = false; } if (properties.Contains("2")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[1] + "\":" + "\"" + sponsor.Sponsorship.Date + "\""; first = false; } if (properties.Contains("3")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[5] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[5], sponsor.Contract.HasContract) + "\""; first = false; } if (properties.Contains("4")) { if (!first) { jsonstring = jsonstring + ","; } var ContractDetails = sponsor.Contract.NumberOfRegistration + "," + sponsor.Contract.RegistrationDate + "," + sponsor.Contract.ExpirationDate + ","; jsonstring = jsonstring + "\"" + finalHeader[6] + "\":" + "\"" + ContractDetails + "\""; first = false; } if (properties.Contains("5")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[7] + "\":" + "\"" + sponsor.ContactInformation.PhoneNumber + "\""; first = false; } if (properties.Contains("6")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[8] + "\":" + "\"" + sponsor.ContactInformation.MailAdress + "\""; first = false; } if (properties.Contains("7")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[2] + "\":" + "\"" + sponsor.Sponsorship.MoneyAmount + "\""; first = false; } if (properties.Contains("8")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[3] + "\":" + "\"" + sponsor.Sponsorship.WhatGoods + "\""; first = false; } if (properties.Contains("9")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[4] + "\":" + "\"" + sponsor.Sponsorship.GoodsAmount + "\""; first = false; } jsonstring = jsonstring + "}]"; } } } else if (ids[0].Contains("beneficiaryCSV")) { var benefeciarycollection = beneficiaryManager.GetListOfBeneficiaries(); for (int i = 1; i < ids.Length; i++) { if (properties.Contains("0")) { var beneficiary = benefeciarycollection.AsQueryable().Where(z => z._id == ids[i]); jsonstring = jsonstring + JsonConvert.SerializeObject(beneficiary); } else { bool first = true; Beneficiary beneficiary = benefeciarycollection.AsQueryable().Where(z => z._id == ids[i]).First(); jsonstring = jsonstring + "[{"; if (properties.Contains("1")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[0] + "\":" + "\"" + beneficiary.Fullname + "\""; first = false; } if (properties.Contains("2")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[1] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[1], beneficiary.Active) + "\"";; first = false; } if (properties.Contains("3")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[2] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[2], beneficiary.Canteen) + "\""; first = false; } if (properties.Contains("Z")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[34] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[34], beneficiary.Weeklypackage) + "\""; first = false; } if (properties.Contains("4")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[3] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[3], beneficiary.HomeDelivery) + "\""; first = false; } if (properties.Contains("5")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[4] + "\":" + "\"" + beneficiary.HomeDeliveryDriver + "\""; first = false; } if (properties.Contains("6")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[5] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[5], beneficiary.HasGDPRAgreement) + "\""; first = false; } if (properties.Contains("7")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[6] + "\":" + "\"" + beneficiary.Adress + "\""; first = false; } if (properties.Contains("8")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[7] + "\":" + "\"" + beneficiary.CNP + "\""; first = false; } if (properties.Contains("9")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[8] + "\":" + "\"" + beneficiary.CI.CIinfo + "\",";; jsonstring = jsonstring + "\"" + finalHeader[9] + "\":" + "\"" + beneficiary.CI.CIEliberat + "\""; first = false; } if (properties.Contains("A")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[10] + "\":" + "\"" + beneficiary.Marca.marca + "\""; first = false; } if (properties.Contains("B")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[11] + "\":" + "\"" + beneficiary.Marca.IdInvestigation + "\""; first = false; } if (properties.Contains("C")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[12] + "\":" + "\"" + beneficiary.Marca.IdAplication + "\""; first = false; } if (properties.Contains("D")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[13] + "\":" + "\"" + beneficiary.NumberOfPortions + "\""; first = false; } if (properties.Contains("E")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[14] + "\":" + "\"" + beneficiary.LastTimeActiv.ToLongDateString() + "\""; first = false; } if (properties.Contains("F")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[15] + "\":" + "\"" + beneficiary.PersonalInfo.PhoneNumber + "\""; first = false; } if (properties.Contains("G")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[16] + "\":" + "\"" + beneficiary.PersonalInfo.BirthPlace + "\""; first = false; } if (properties.Contains("H")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[17] + "\":" + "\"" + beneficiary.PersonalInfo.Studies + "\""; first = false; } if (properties.Contains("I")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[18] + "\":" + "\"" + beneficiary.PersonalInfo.Profesion + "\""; first = false; } if (properties.Contains("J")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[19] + "\":" + "\"" + beneficiary.PersonalInfo.Ocupation + "\""; first = false; } if (properties.Contains("K")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[20] + "\":" + "\"" + beneficiary.PersonalInfo.SeniorityInWorkField + "\""; first = false; } if (properties.Contains("L")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[21] + "\":" + "\"" + beneficiary.PersonalInfo.HealthState + "\""; first = false; } if (properties.Contains("M")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[22] + "\":" + "\"" + beneficiary.PersonalInfo.Disalility + "\""; first = false; } if (properties.Contains("N")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[23] + "\":" + "\"" + beneficiary.PersonalInfo.ChronicCondition + "\""; first = false; } if (properties.Contains("O")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[24] + "\":" + "\"" + beneficiary.PersonalInfo.Addictions + "\""; first = false; } if (properties.Contains("Z")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[25] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[25], beneficiary.PersonalInfo.HealthInsurance) + "\""; first = false; } if (properties.Contains("P")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[26] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[26], beneficiary.PersonalInfo.HealthCard) + "\""; first = false; } if (properties.Contains("Q")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[27] + "\":" + "\"" + beneficiary.PersonalInfo.Married + "\""; first = false; } if (properties.Contains("R")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[28] + "\":" + "\"" + beneficiary.PersonalInfo.SpouseName + "\""; first = false; } if (properties.Contains("S")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[29] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[29], beneficiary.PersonalInfo.HasHome) + "\""; first = false; } if (properties.Contains("T")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[30] + "\":" + "\"" + beneficiary.PersonalInfo.HousingType + "\""; first = false; } if (properties.Contains("U")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[31] + "\":" + "\"" + beneficiary.PersonalInfo.Income + "\""; first = false; } if (properties.Contains("V")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[32] + "\":" + "\"" + beneficiary.PersonalInfo.Expences + "\""; first = false; } if (properties.Contains("W")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[33] + "\":" + "\"" + beneficiary.PersonalInfo.Gender + "\""; first = false; } jsonstring = jsonstring + "}]"; } } } else if (ids[0].Contains("volunteerCSV")) { var volunteerscollection = volunteerManager.GetListOfVolunteers(); for (int i = 1; i < ids.Length; i++) { if (properties.Contains("0")) { var volunteer = volunteerscollection.AsQueryable().Where(z => z._id == ids[i]); jsonstring = jsonstring + JsonConvert.SerializeObject(volunteer); } else { bool first = true; Volunteer volunteer = volunteerscollection.AsQueryable().Where(z => z._id == ids[i]).First(); jsonstring = jsonstring + "[{"; if (properties.Contains("1")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[0] + "\":" + "\"" + volunteer.Fullname + "\""; first = false; } if (properties.Contains("2")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[1] + "\":" + "\"" + volunteer.Birthdate + "\""; first = false; } if (properties.Contains("3")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[14] + "\":" + "\"" + volunteer.Address.District + "\""; jsonstring = jsonstring + ","; jsonstring = jsonstring + "\"" + finalHeader[15] + "\":" + "\"" + volunteer.Address.City + "\""; jsonstring = jsonstring + ","; jsonstring = jsonstring + "\"" + finalHeader[16] + "\":" + "\"" + volunteer.Address.Street + "\""; jsonstring = jsonstring + ","; jsonstring = jsonstring + "\"" + finalHeader[17] + "\":" + "\"" + volunteer.Address.Number + "\""; first = false; } if (properties.Contains("4")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[3] + "\":" + "\"" + volunteer.Gender + "\""; first = false; } if (properties.Contains("5")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[4] + "\":" + "\"" + volunteer.Desired_workplace + "\""; first = false; } if (properties.Contains("6")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[5] + "\":" + "\"" + volunteer.CNP + "\""; first = false; } if (properties.Contains("7")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[6] + "\":" + "\"" + volunteer.Field_of_activity + "\""; first = false; } if (properties.Contains("8")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[7] + "\":" + "\"" + volunteer.Occupation + "\""; first = false; } if (properties.Contains("9")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[18] + "\":" + "\"" + volunteer.CIseria + "\""; jsonstring = jsonstring + ","; jsonstring = jsonstring + "\"" + finalHeader[19] + "\":" + "\"" + volunteer.CINr + "\""; jsonstring = jsonstring + ","; jsonstring = jsonstring + "\"" + finalHeader[20] + "\":" + "\"" + volunteer.CIEliberat + "\""; jsonstring = jsonstring + ","; jsonstring = jsonstring + "\"" + finalHeader[21] + "\":" + "\"" + volunteer.CIeliberator + "\""; first = false; } if (properties.Contains("A")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[9] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[9], volunteer.InActivity) + "\""; first = false; } if (properties.Contains("B")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[10] + "\":" + "\"" + volunteer.HourCount + "\""; first = false; } if (properties.Contains("C")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[20] + "\":" + "\"" + volunteer.ContactInformation.PhoneNumber + "\""; jsonstring = jsonstring + ","; jsonstring = jsonstring + "\"" + finalHeader[21] + "\":" + "\"" + volunteer.ContactInformation.MailAdress + "\""; first = false; } if (properties.Contains("D")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[22] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[22], volunteer.Additionalinfo.HasDrivingLicence) + "\""; jsonstring = jsonstring + ","; jsonstring = jsonstring + "\"" + finalHeader[23] + "\":" + "\"" + ControllerHelper.GetAnswer(finalHeader[23], volunteer.Additionalinfo.HasCar) + "\""; jsonstring = jsonstring + ","; jsonstring = jsonstring + "\"" + finalHeader[24] + "\":" + "\"" + volunteer.Additionalinfo.Remark + "\""; first = false; } jsonstring = jsonstring + "}]"; } } } else if (ids[0].Contains("eventCSV")) { var eventscollection = eventManager.GetListOfEvents(); for (int i = 1; i < ids.Length; i++) { if (properties.Contains("0")) { var eventt = eventscollection.AsQueryable().Where(z => z._id == ids[i]); jsonstring = jsonstring + JsonConvert.SerializeObject(eventt); } else { bool first = true; Event eventt = eventscollection.AsQueryable().Where(z => z._id == ids[i]).First(); jsonstring = jsonstring + "[{"; if (properties.Contains("1")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[0] + "\":" + "\"" + eventt.NameOfEvent + "\""; first = false; } if (properties.Contains("2")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[1] + "\":" + "\"" + eventt.PlaceOfEvent + "\""; first = false; } if (properties.Contains("3")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[2] + "\":" + "\"" + eventt.DateOfEvent + "\""; first = false; } if (properties.Contains("4")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[3] + "\":" + "\"" + eventt.TypeOfActivities + "\""; first = false; } if (properties.Contains("5")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[4] + "\":" + "\"" + eventt.TypeOfEvent + "\""; first = false; } if (properties.Contains("6")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[5] + "\":" + "\"" + eventt.Duration + "\""; first = false; } if (properties.Contains("7")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[6] + "\":" + "\"" + eventt.AllocatedVolunteers + "\""; first = false; } if (properties.Contains("8")) { if (!first) { jsonstring = jsonstring + ","; } jsonstring = jsonstring + "\"" + finalHeader[7] + "\":" + "\"" + eventt.AllocatedSponsors + "\""; first = false; } jsonstring = jsonstring + "}]"; } } } jsonstring = jsonstring.Replace("][", ","); return(jsonstring); }
public ActionResult SynchronizeData() { string SERVER_NAME_LOCAL = Environment.GetEnvironmentVariable(Common.VolMongoConstants.SERVER_NAME_LOCAL); int SERVER_PORT_LOCAL = int.Parse(Environment.GetEnvironmentVariable(Common.VolMongoConstants.SERVER_PORT_LOCAL)); string DATABASE_NAME_LOCAL = Environment.GetEnvironmentVariable(Common.VolMongoConstants.DATABASE_NAME_LOCAL); string SERVER_NAME_COMMON = Environment.GetEnvironmentVariable(Common.VolMongoConstants.SERVER_NAME_COMMON); int SERVER_PORT_COMMON = int.Parse(Environment.GetEnvironmentVariable(Common.VolMongoConstants.SERVER_PORT_COMMON)); string DATABASE_NAME_COMMON = Environment.GetEnvironmentVariable(Common.VolMongoConstants.DATABASE_NAME_COMMON); ModifiedDocumentManager modifiedDocumentManager = new ModifiedDocumentManager(); AuxiliaryDBManager AuxiliaryDBManager = new AuxiliaryDBManager(SERVER_NAME_LOCAL, SERVER_PORT_LOCAL, DATABASE_NAME_LOCAL); EventManager eventManager = new EventManager(SERVER_NAME_LOCAL, SERVER_PORT_LOCAL, DATABASE_NAME_LOCAL); SponsorManager sponsorManager = new SponsorManager(SERVER_NAME_LOCAL, SERVER_PORT_LOCAL, DATABASE_NAME_LOCAL); VolunteerManager volunteerManager = new VolunteerManager(SERVER_NAME_LOCAL, SERVER_PORT_LOCAL, DATABASE_NAME_LOCAL); VolContractManager volContractManager = new VolContractManager(SERVER_NAME_LOCAL, SERVER_PORT_LOCAL, DATABASE_NAME_LOCAL); BeneficiaryManager beneManager = new BeneficiaryManager(SERVER_NAME_LOCAL, SERVER_PORT_LOCAL, DATABASE_NAME_LOCAL); BeneficiaryContractManager beneficiaryContractManager = new BeneficiaryContractManager(SERVER_NAME_LOCAL, SERVER_PORT_LOCAL, DATABASE_NAME_LOCAL); EventManager commonEventManager = new EventManager(SERVER_NAME_COMMON, SERVER_PORT_COMMON, DATABASE_NAME_COMMON); SponsorManager commonSponsorManager = new SponsorManager(SERVER_NAME_COMMON, SERVER_PORT_COMMON, DATABASE_NAME_COMMON); VolunteerManager commonvolunteerManager = new VolunteerManager(SERVER_NAME_COMMON, SERVER_PORT_COMMON, DATABASE_NAME_COMMON); VolContractManager commonVolContractManager = new VolContractManager(SERVER_NAME_COMMON, SERVER_PORT_COMMON, DATABASE_NAME_COMMON); BeneficiaryManager commonBeneficiaryManager = new BeneficiaryManager(SERVER_NAME_COMMON, SERVER_PORT_COMMON, DATABASE_NAME_COMMON); BeneficiaryContractManager commonBenefContractManager = new BeneficiaryContractManager(SERVER_NAME_COMMON, SERVER_PORT_COMMON, DATABASE_NAME_COMMON); List <Volunteer> volunteerslocal = volunteerManager.GetListOfVolunteers(); List <Event> eventslocal = eventManager.GetListOfEvents(); List <Beneficiary> beneficiarieslocal = beneManager.GetListOfBeneficiaries(); List <Sponsor> sponsorslocal = sponsorManager.GetListOfSponsors(); List <Volcontract> volcontractslocal = volContractManager.GetListOfVolunteersContracts(); List <Beneficiarycontract> beneficiarycontractslocal = beneficiaryContractManager.GetListOfBeneficiariesContracts(); List <Volunteer> volunteers = commonvolunteerManager.GetListOfVolunteers(); List <Event> events = commonEventManager.GetListOfEvents(); List <Beneficiary> beneficiaries = commonBeneficiaryManager.GetListOfBeneficiaries(); List <Sponsor> sponsors = commonSponsorManager.GetListOfSponsors(); List <Volcontract> volcontracts = commonVolContractManager.GetListOfVolunteersContracts(); List <Beneficiarycontract> beneficiarycontracts = commonBenefContractManager.GetListOfBeneficiariesContracts(); List <ModifiedIDs> modifiedidlist = modifiedDocumentManager.GetListOfModifications(); List <DeletedIDS> deletedlist = modifiedDocumentManager.GetListOfDeletions(); int numberOfModifictaions = modifiedidlist.Count(); int numberOfDeletions = deletedlist.Count(); string modifiedids = JsonConvert.SerializeObject(modifiedidlist); string deletedids = JsonConvert.SerializeObject(deletedlist); string commonvols = JsonConvert.SerializeObject(volunteers); string commonevents = JsonConvert.SerializeObject(events); string commonbenefieciaries = JsonConvert.SerializeObject(beneficiaries); string commonsponsors = JsonConvert.SerializeObject(sponsors); string commonvolcontracts = JsonConvert.SerializeObject(volcontracts); string commonbeneficiarycontracts = JsonConvert.SerializeObject(beneficiarycontracts); string outOfSyncDocuments = ""; for (int i = 0; i < volunteerslocal.Count(); i++) { // If the common db does not contain the volunteer and it has been created since the last fetch/push it gets added. if (!commonvols.Contains(volunteerslocal[i]._id) && modifiedids.Contains(volunteerslocal[i]._id)) { commonvolunteerManager.AddVolunteerToDB(volunteerslocal[i]); } // if the common db contains the volunteer, but it has been edited since last sync it gets updated else if (modifiedids.Contains(volunteerslocal[i]._id)) { string auxiliaryDocument = AuxiliaryDBManager.GetDocumentByID(volunteerslocal[i]._id); string currentDocument = JsonConvert.SerializeObject(commonvolunteerManager.GetOneVolunteer(volunteerslocal[i]._id)); auxiliaryDocument = auxiliaryDocument.Replace(" ", ""); currentDocument = currentDocument.Replace(" ", ""); //Checking whether or not the Document has been modified since we have last synced. if (auxiliaryDocument != currentDocument) { outOfSyncDocuments += volunteerslocal[i].Fullname + ", "; } commonvolunteerManager.UpdateAVolunteer(volunteerslocal[i], volunteerslocal[i]._id); } } for (int i = 0; i < volunteers.Count(); i++) { // if the document has been deleted it will get deleted from the common db aswell. // the document will not be re-added unless someone has modified the document with this ID. if (deletedids.Contains(volunteers[i]._id)) { commonvolunteerManager.DeleteAVolunteer(volunteers[i]._id); } } for (int i = 0; i < eventslocal.Count(); i++) { if (!commonevents.Contains(eventslocal[i]._id) && modifiedids.Contains(eventslocal[i]._id)) { commonEventManager.AddEventToDB(eventslocal[i]); } else if (modifiedids.Contains(eventslocal[i]._id)) { string auxiliaryDocument = AuxiliaryDBManager.GetDocumentByID(eventslocal[i]._id); string currentDocument = JsonConvert.SerializeObject(commonEventManager.GetOneEvent(eventslocal[i]._id)); auxiliaryDocument = auxiliaryDocument.Replace(" ", ""); currentDocument = currentDocument.Replace(" ", ""); if (auxiliaryDocument != currentDocument) { outOfSyncDocuments += eventslocal[i].NameOfEvent + ", "; } commonEventManager.UpdateAnEvent(eventslocal[i], eventslocal[i]._id); } } for (int i = 0; i < events.Count(); i++) { if (deletedids.Contains(events[i]._id)) { commonEventManager.DeleteAnEvent(events[i]._id); } } for (int i = 0; i < beneficiarieslocal.Count(); i++) { if (!commonbenefieciaries.Contains(beneficiarieslocal[i]._id) && modifiedids.Contains(beneficiarieslocal[i]._id)) { commonBeneficiaryManager.AddBeneficiaryToDB(beneficiarieslocal[i]); } else if (modifiedids.Contains(beneficiarieslocal[i]._id)) { string auxiliaryDocument = AuxiliaryDBManager.GetDocumentByID(beneficiarieslocal[i]._id); string currentDocument = JsonConvert.SerializeObject(commonBeneficiaryManager.GetOneBeneficiary(beneficiarieslocal[i]._id)); auxiliaryDocument = auxiliaryDocument.Replace(" ", ""); currentDocument = currentDocument.Replace(" ", ""); if (auxiliaryDocument != currentDocument) { outOfSyncDocuments += beneficiarieslocal[i].Fullname + ", "; } commonBeneficiaryManager.UpdateABeneficiary(beneficiarieslocal[i], beneficiarieslocal[i]._id); } } for (int i = 0; i < beneficiaries.Count(); i++) { if (deletedids.Contains(beneficiaries[i]._id)) { commonBeneficiaryManager.DeleteBeneficiary(beneficiaries[i]._id); } } for (int i = 0; i < sponsorslocal.Count(); i++) { if (!commonsponsors.Contains(sponsorslocal[i]._id) && modifiedids.Contains(sponsorslocal[i]._id)) { commonSponsorManager.AddSponsorToDB(sponsorslocal[i]); } else if (modifiedids.Contains(sponsorslocal[i]._id)) { string auxiliaryDocument = AuxiliaryDBManager.GetDocumentByID(sponsorslocal[i]._id); string currentDocument = JsonConvert.SerializeObject(commonSponsorManager.GetOneSponsor(sponsorslocal[i]._id)); auxiliaryDocument = auxiliaryDocument.Replace(" ", ""); currentDocument = currentDocument.Replace(" ", ""); if (auxiliaryDocument != currentDocument) { outOfSyncDocuments += sponsorslocal[i].NameOfSponsor + ", "; } commonSponsorManager.UpdateSponsor(sponsorslocal[i], sponsorslocal[i]._id); } } for (int i = 0; i < sponsors.Count(); i++) { if (deletedids.Contains(sponsors[i]._id)) { commonSponsorManager.DeleteSponsor(sponsors[i]._id); } } for (int i = 0; i < volcontractslocal.Count(); i++) { if (!commonvolcontracts.Contains(volcontractslocal[i]._id) && modifiedids.Contains(volcontractslocal[i]._id)) { commonVolContractManager.AddVolunteerContractToDB(volcontractslocal[i]); } else if (modifiedids.Contains(volcontractslocal[i]._id)) { commonVolContractManager.UpdateVolunteerContract(volcontractslocal[i], volcontractslocal[i]._id); } } for (int i = 0; i < volcontracts.Count(); i++) { if (deletedids.Contains(volcontracts[i]._id)) { commonVolContractManager.DeleteAVolContract(volcontracts[i]._id); } } for (int i = 0; i < beneficiarycontractslocal.Count(); i++) { if (!commonbeneficiarycontracts.Contains(beneficiarycontractslocal[i]._id) && modifiedids.Contains(beneficiarycontractslocal[i]._id)) { commonBenefContractManager.AddBeneficiaryContractToDB(beneficiarycontractslocal[i]); } else if (modifiedids.Contains(beneficiarycontractslocal[i]._id)) { commonBenefContractManager.UpdateBeneficiaryContract(beneficiarycontractslocal[i], beneficiarycontractslocal[i]._id); } } for (int i = 0; i < beneficiarycontracts.Count(); i++) { if (deletedids.Contains(beneficiarycontracts[i]._id)) { commonBenefContractManager.DeleteBeneficiaryContract(beneficiarycontracts[i]._id); } } modifiedDocumentManager.DeleteAuxiliaryDatabases(); volunteers = commonvolunteerManager.GetListOfVolunteers(); events = commonEventManager.GetListOfEvents(); beneficiaries = commonBeneficiaryManager.GetListOfBeneficiaries(); sponsors = commonSponsorManager.GetListOfSponsors(); volcontracts = commonVolContractManager.GetListOfVolunteersContracts(); beneficiarycontracts = commonBenefContractManager.GetListOfBeneficiariesContracts(); string volstring = JsonConvert.SerializeObject(volunteers); string eventstring = JsonConvert.SerializeObject(events); string benefieciarystring = JsonConvert.SerializeObject(beneficiaries); string sponsorstring = JsonConvert.SerializeObject(sponsors); string volcontractstring = JsonConvert.SerializeObject(volcontracts); string benefcontractstring = JsonConvert.SerializeObject(beneficiarycontracts); string localvols = JsonConvert.SerializeObject(volunteerslocal); string localevents = JsonConvert.SerializeObject(eventslocal); string localbenefieciaries = JsonConvert.SerializeObject(beneficiarieslocal); string localsponsors = JsonConvert.SerializeObject(sponsorslocal); string localvolcontrcarts = JsonConvert.SerializeObject(volcontractslocal); string localbeneficiarycontrcarts = JsonConvert.SerializeObject(beneficiarycontractslocal); for (int i = 0; i < volunteers.Count(); i++) { if (!(localvols.Contains(volunteers[i]._id))) { volunteerManager.AddVolunteerToDB(volunteers[i]); } else if (!modifiedids.Contains(volunteers[i]._id)) { volunteerManager.UpdateAVolunteer(volunteers[i], volunteers[i]._id); } } for (int i = 0; i < volunteerslocal.Count(); i++) { if (!volstring.Contains(volunteerslocal[i]._id)) { volunteerManager.DeleteAVolunteer(volunteerslocal[i]._id); } } for (int i = 0; i < events.Count(); i++) { if (!(localevents.Contains(events[i]._id))) { eventManager.AddEventToDB(events[i]); } else if (!modifiedids.Contains(events[i]._id)) { eventManager.UpdateAnEvent(events[i], events[i]._id); } } for (int i = 0; i < eventslocal.Count(); i++) { if (!eventstring.Contains(eventslocal[i]._id)) { eventManager.DeleteAnEvent(eventslocal[i]._id); } } for (int i = 0; i < beneficiaries.Count(); i++) { if (!(localbenefieciaries.Contains(beneficiaries[i]._id))) { beneManager.AddBeneficiaryToDB(beneficiaries[i]); } else if (!modifiedids.Contains(beneficiaries[i]._id)) { beneManager.UpdateABeneficiary(beneficiaries[i], beneficiaries[i]._id); } } for (int i = 0; i < beneficiarieslocal.Count(); i++) { if (!benefieciarystring.Contains(beneficiarieslocal[i]._id)) { beneManager.DeleteBeneficiary(beneficiarieslocal[i]._id); } } for (int i = 0; i < sponsors.Count(); i++) { if (!(localsponsors.Contains(sponsors[i]._id))) { sponsorManager.AddSponsorToDB(sponsors[i]); } else if (!modifiedids.Contains(sponsors[i]._id)) { sponsorManager.UpdateSponsor(sponsors[i], sponsors[i]._id); } } for (int i = 0; i < sponsorslocal.Count(); i++) { if (!sponsorstring.Contains(sponsorslocal[i]._id)) { sponsorManager.DeleteSponsor(sponsorslocal[i]._id); } } for (int i = 0; i < volcontracts.Count(); i++) { if (!(localvolcontrcarts.Contains(volcontracts[i]._id))) { volContractManager.AddVolunteerContractToDB(volcontracts[i]); } else if (!modifiedids.Contains(volcontracts[i]._id)) { volContractManager.UpdateVolunteerContract(volcontracts[i], volcontracts[i]._id); } } for (int i = 0; i < volcontractslocal.Count(); i++) { if (!volcontractstring.Contains(volcontractslocal[i]._id)) { volContractManager.DeleteAVolContract(volcontractslocal[i]._id); } } for (int i = 0; i < beneficiarycontracts.Count(); i++) { if (!(localbeneficiarycontrcarts.Contains(beneficiarycontracts[i]._id))) { beneficiaryContractManager.AddBeneficiaryContractToDB(beneficiarycontracts[i]); } else if (!modifiedids.Contains(beneficiarycontracts[i]._id)) { beneficiaryContractManager.UpdateBeneficiaryContract(beneficiarycontracts[i], beneficiarycontracts[i]._id); } } for (int i = 0; i < beneficiarycontractslocal.Count(); i++) { if (!benefcontractstring.Contains(beneficiarycontractslocal[i]._id)) { beneficiaryContractManager.DeleteBeneficiaryContract(beneficiarycontractslocal[i]._id); } } modifiedDocumentManager.DeleteAuxiliaryDatabases(); AuxiliaryDBManager.DropAuxiliaryDatabase(); return(RedirectToAction("SynchronizationResults", "DatabaseManagement", new { numberOfModifictaions, numberOfDeletions, outOfSyncDocuments })); }
public ActionResult FileUpload(IFormFile Files) { try { List <Beneficiary> beneficiaries = beneficiaryManager.GetListOfBeneficiaries(); int docsimported = 0; if (UniversalFunctions.File_is_not_empty(Files)) { string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", Files.FileName); UniversalFunctions.CreateFileStream(Files, path); List <string[]> beneficiaryasstring = CSVImportParser.GetListFromCSV(path); if (CSVImportParser.DefaultBeneficiaryCSVFormat(path)) { for (int i = 0; i < beneficiaryasstring.Count; i++) { Beneficiary beneficiary = new Beneficiary(); beneficiary = BeneficiaryFunctions.GetBeneficiaryFromString(beneficiaryasstring[i]); if (BeneficiaryFunctions.DoesNotExist(beneficiaries, beneficiary)) { docsimported++; beneficiaryManager.AddBeneficiaryToDB(beneficiary); } } } else { for (int i = 0; i < beneficiaryasstring.Count; i++) { Beneficiary beneficiary = new Beneficiary(); beneficiary = BeneficiaryFunctions.GetBeneficiaryFromOtherString(beneficiaryasstring[i]); if (BeneficiaryFunctions.DoesNotExist(beneficiaries, beneficiary)) { docsimported++; beneficiaryManager.AddBeneficiaryToDB(beneficiary); } } } List <Beneficiary> beneficiarycollection = beneficiaryManager.GetListOfBeneficiaries(); List <Beneficiarycontract> beneficiaryContractCollection = beneficiaryContractManager.GetListOfBeneficiariesContracts(); List <Beneficiarycontract> beneficiaryContracts = BeneficiaryFunctions.GetBeneficiaryContractsFromCsv(beneficiaryasstring, beneficiarycollection, beneficiaryContractCollection); foreach (Beneficiarycontract bc in beneficiaryContracts) { bc._id = Guid.NewGuid().ToString(); beneficiaryContractManager.AddBeneficiaryContractToDB(bc); } UniversalFunctions.RemoveTempFile(path); return(RedirectToAction("ImportUpdate", "Home", new { docsimported })); } else { return(View()); } } catch { return(RedirectToAction("IncorrectFile", "Home")); } }