private Models.Survey ConvertToSurvey(OqtaneSurvey objOqtaneSurvey) { if (objOqtaneSurvey == null) { return(new Models.Survey()); } // Create new Object Models.Survey objAddSurvey = new Models.Survey(); objAddSurvey.SurveyId = objOqtaneSurvey.SurveyId; objAddSurvey.ModuleId = objOqtaneSurvey.ModuleId; objAddSurvey.SurveyName = objOqtaneSurvey.SurveyName; objAddSurvey.CreatedBy = objOqtaneSurvey.CreatedBy; objAddSurvey.CreatedOn = objOqtaneSurvey.CreatedOn; objAddSurvey.ModifiedBy = objOqtaneSurvey.ModifiedBy; objAddSurvey.ModifiedOn = objOqtaneSurvey.ModifiedOn; if (objOqtaneSurvey.UserId != null) { objAddSurvey.UserId = objOqtaneSurvey.UserId.Value; } // Create new Collection objAddSurvey.SurveyItem = new List <SurveyItem>(); foreach (OqtaneSurveyItem objOqtaneSurveyItem in objOqtaneSurvey.OqtaneSurveyItem) { // Create new Object Models.SurveyItem objAddSurveyItem = new SurveyItem(); objAddSurveyItem.Id = objOqtaneSurveyItem.Id; objAddSurveyItem.ItemLabel = objOqtaneSurveyItem.ItemLabel; objAddSurveyItem.ItemType = objOqtaneSurveyItem.ItemType; objAddSurveyItem.ItemValue = objOqtaneSurveyItem.ItemValue; objAddSurveyItem.Position = objOqtaneSurveyItem.Position; objAddSurveyItem.Required = objOqtaneSurveyItem.Required; objAddSurveyItem.SurveyChoiceId = objOqtaneSurveyItem.SurveyChoiceId; // Create new Collection objAddSurveyItem.SurveyItemOption = new List <SurveyItemOption>(); foreach (OqtaneSurveyItemOption objOqtaneSurveyItemOption in objOqtaneSurveyItem.OqtaneSurveyItemOption) { // Create new Object Models.SurveyItemOption objAddSurveyItemOption = new SurveyItemOption(); objAddSurveyItemOption.Id = objOqtaneSurveyItemOption.Id; objAddSurveyItemOption.OptionLabel = objOqtaneSurveyItemOption.OptionLabel; // Add to Collection objAddSurveyItem.SurveyItemOption.Add(objAddSurveyItemOption); } // Add to Collection objAddSurvey.SurveyItem.Add(objAddSurveyItem); } return(objAddSurvey); }
public OqtaneSurvey CreateSurvey(Models.Survey NewSurvey) { try { OqtaneSurvey objSurvey = new OqtaneSurvey(); objSurvey.SurveyId = 0; objSurvey.ModuleId = NewSurvey.ModuleId; objSurvey.SurveyName = NewSurvey.SurveyName; objSurvey.UserId = NewSurvey.UserId; objSurvey.CreatedOn = DateTime.Now; _db.OqtaneSurvey.Add(objSurvey); _db.SaveChanges(); return(objSurvey); } catch { DetachAllEntities(); throw; } }