public void SendAnswer(SentPersonalData_Answers Pdata_Answer, int id) { var existingAnswer = _answers.FindOne(ans => id == ans.SurveyId); if (existingAnswer == null) { //Survey not exists return; } else { //Survey Exists var oldPage = _answers.FindOne(ans => ans.SurveyId == id).Answers.Find(ans => ans.PersonalData.Email == Pdata_Answer.PersonalData.Email).Pages.Find(page => page.PageNumber == Pdata_Answer.Pages[0].PageNumber); if (oldPage != null) { //Oldpage Exists List <Page> PageList = existingAnswer.Answers.Find(answer => answer.PersonalData.Email == Pdata_Answer.PersonalData.Email).Pages; foreach (var page in PageList) { if (page.PageNumber == Pdata_Answer.Pages[0].PageNumber) { PageList.Remove(page); break; } } existingAnswer.Answers.Find(answer => answer.PersonalData.Email == Pdata_Answer.PersonalData.Email).Pages = PageList; } existingAnswer.Answers.Find(answer => answer.PersonalData.Email == Pdata_Answer.PersonalData.Email).Pages.Add(Pdata_Answer.Pages[0]); _answers.Delete(answer => answer.SurveyId == id); _answers.Insert(existingAnswer); } }
public void SendPersonalData(SentPersonalData data, int id) { SentAnswer existingAnswer = _answers.FindOne(ans => ans.SurveyId == id); if (existingAnswer == null) { //Survey not exists SentAnswer answer = new SentAnswer() { SurveyId = id, CompletedCounter = 0, LeftCounter = 0, Answers = new List <SentPersonalData_Answers>() }; SentPersonalData_Answers PData = new SentPersonalData_Answers() { PersonalData = new SentPersonalData() { Age = data.Age, Name = data.Name, Email = data.Email, Gender = data.Gender }, Pages = new List <Page>() }; answer.Answers.Add(PData); _answers.Insert(answer); } else { //Survey Exists var existingData = existingAnswer.Answers.Find(answer => answer.PersonalData.Email == data.Email); if (existingData == null) { //Person not exists existingAnswer.Answers.Add( new SentPersonalData_Answers() { PersonalData = new SentPersonalData() { Age = data.Age, Name = data.Name, Email = data.Email, Gender = data.Gender }, Pages = new List <Page>() }); _answers.Delete(answer => answer.SurveyId == id); _answers.Insert(existingAnswer); } else { return; } } }