/// <summary> /// To update Feedback records status to pending delete, which are removed from payload /// </summary> /// <param name="answersToDelete"></param> private void UpdateFeedbackAsPendingDelete(IEnumerable answersToDelete) { trace.Trace("Processing UpdateFeedbackAsPendingDelete - start"); var deleteAnswers = answersToDelete.GetEnumerator(); while (deleteAnswers.MoveNext()) { KeyValuePair <Guid, string> answerToDelete = (KeyValuePair <Guid, string>)deleteAnswers.Current; if (answerToDelete.Key == Guid.Empty) { continue; } var feedbackEntity = new Entity(EntityName.SurveyResponseFeedback, answerToDelete.Key); feedbackEntity.Attributes[Attributes.SurveyResponseFeedback.StateCode] = new OptionSetValue(1); feedbackEntity.Attributes[Attributes.SurveyResponseFeedback.StatusCode] = new OptionSetValue(950000000); CommonXrm.UpdateEntity(feedbackEntity, payloadSurvey.CrmService); } trace.Trace("Processing UpdateFeedbackAsPendingDelete - end"); }
/// <summary> /// To Create OR Update Survey and Survey Feedback records /// </summary> /// <param name="surveyId"></param> /// <param name="surveyResponse"></param> /// <param name="answers"></param> /// <param name="existingFeedback"></param> private void UpdateSurveyFeedback(Guid surveyId, Entity surveyResponse, List <Answer> answers, Dictionary <Guid, string> existingFeedback) { trace.Trace("Processing UpdateSurveyFeedback - start"); surveyResponse.Id = surveyId; CommonXrm.UpdateEntity(surveyResponse, payloadSurvey.CrmService); if (answers == null || answers.Count == 0) { UpdateAllFeedbackAsPendingDelete(existingFeedback); return; } if (existingFeedback != null && existingFeedback.Count > 0) { List <Answer> answersToCreate = answers.Where(a => !existingFeedback.Any(f => f.Value == a.Id.ToString())).ToList(); IEnumerable answersToDelete = existingFeedback.Where(f => !answers.Any(a => a.Id.ToString() == f.Value)); UpdateFeedbackAsPendingDelete(answersToDelete); CreateFeedback(answersToCreate, surveyId); } else { CreateFeedback(answers, surveyId); } trace.Trace("Processing UpdateSurveyFeedback - end"); }