using System.Collections.Generic;
public static void Main()
Console.WriteLine("FactoryPattern");
string json = GetJSONData();
List<MeetingPollingQuestion> ListofMeetingPollingQuestion = JsonConvert.DeserializeObject<List<MeetingPollingQuestion>>(json);
foreach (MeetingPollingQuestion MeetingPollingQuestion in ListofMeetingPollingQuestion)
switch (MeetingPollingQuestion.MeetingPollingQuestionType)
var LongAnswerTextControl = new LongAnswerText(MeetingPollingQuestion.MeetingPollingParts);
public static string GetJSONData()
string JSONData = "[{\"MeetingPollingQuestionId\":2,\"MeetingPollingQuestionType\":\"LongAnswerText\",\"MeetingPollingId\":3,\"SequenceOrder\":1,\"MeetingPollingParts\":[{\"MeetingPollingPartsId\":2,\"Type\":\"Question\",\"MeetingPollingQuestionId\":2,\"MeetingPollingPartsValues\":[{\"Type\":\"label\",\"QuestionValue\":\"This is a long question\",\"FileManagerId\":0,\"FileName\":null,\"FileData\":null,\"FileType\":null}]}]},{\"MeetingPollingQuestionId\":3,\"MeetingPollingQuestionType\":\"MultipleChoice\",\"MeetingPollingId\":3,\"SequenceOrder\":2,\"MeetingPollingParts\":[{\"MeetingPollingPartsId\":3,\"Type\":\"Question\",\"MeetingPollingQuestionId\":3,\"MeetingPollingPartsValues\":[{\"Type\":\"label\",\"QuestionValue\":\"this is a multiple choice question\",\"FileManagerId\":0,\"FileName\":null,\"FileData\":null,\"FileType\":null}]},{\"MeetingPollingPartsId\":4,\"Type\":\"Image\",\"MeetingPollingQuestionId\":3,\"MeetingPollingPartsValues\":[{\"Type\":\"Image\",\"QuestionValue\":null,\"FileManagerId\":14552,\"FileName\":null,\"FileData\":null,\"FileType\":null}]},{\"MeetingPollingPartsId\":5,\"Type\":\"Answers\",\"MeetingPollingQuestionId\":3,\"MeetingPollingPartsValues\":[{\"Type\":\"radio\",\"QuestionValue\":\"Yes\",\"FileManagerId\":0,\"FileName\":null,\"FileData\":null,\"FileType\":null},{\"Type\":\"radio\",\"QuestionValue\":\"No\",\"FileManagerId\":0,\"FileName\":null,\"FileData\":null,\"FileType\":null},{\"Type\":\"radio\",\"QuestionValue\":\"Abstain\",\"FileManagerId\":0,\"FileName\":null,\"FileData\":null,\"FileType\":null}]}]}]";
interface MeetingQuestionInterface
string Label(List<MeetingPollingParts> MeetingPollingParts);
public class LongAnswerText : MeetingQuestionInterface
public LongAnswerText(List<MeetingPollingParts> meetingPollingParts)
public string Label(List<MeetingPollingParts> MeetingPollingParts)
var selectLabel = MeetingPollingParts.Select(x => x.MeetingPollingPartsValues.Where(w => w.FileType == "Label").FirstOrDefault());
var LabelControl = selectLabel.FirstOrDefault();
return String.Format("<label for='{0}'>{1}</label>", LabelControl.QuestionValue, LabelControl.QuestionValue);
public class MeetingPollingPartsValues
public string Type { get; set; }
public string QuestionValue { get; set; }
public int FileManagerId { get; set; }
public string FileName { get; set; }
public byte[] FileData { get; set; }
public string FileType { get; set; }
public class MeetingPollingParts
public int MeetingPollingPartsId { get; set; }
public string Type { get; set; }
public int MeetingPollingQuestionId { get; set; }
public List<MeetingPollingPartsValues> MeetingPollingPartsValues { get; set; }
public class MeetingPollingQuestion
public int MeetingPollingQuestionId { get; set; }
public string MeetingPollingQuestionType { get; set; }
public int MeetingPollingId { get; set; }
public int SequenceOrder { get; set; }
public List<MeetingPollingParts> MeetingPollingParts { get; set; }