public ActionResult GetCustomDataGroupAndFields(string baseDataId) { var genObj = new GenericObjectModel { CustomGroupViewModels = new List <CustomGroupViewModel>() }; try { var baseDataList = _baseDataService.Query(b => b.EnrollmentId == baseDataId).Select().ToList(); if (!baseDataList.Any()) { return(Json(genObj, JsonRequestBehavior.AllowGet)); } var baseData = baseDataList[0]; genObj.Name = baseData.Firstname + " " + baseData.Surname; genObj.ProjectSiteId = baseData.ProjectSiteId; genObj.EnrollmentId = baseData.EnrollmentId; genObj.ProjectPrimaryCode = baseData.ProjectPrimaryCode; var customGroups = new List <CustomGroupViewModel>(); var enrolledCustomDataList = _customDataService.Query(q => q.EnrollmentId == baseDataId).Select().ToList(); if (!enrolledCustomDataList.Any()) { return(Json(genObj, JsonRequestBehavior.AllowGet)); } enrolledCustomDataList.ForEach(r => { var customFields = _customFieldService.Query(g => g.CustomFieldId == r.CustomFieldId).Select().ToList(); if (customFields.Any()) { var cFieldView = customFields[0]; var customFieldTypes = _customFieldTypeService.Query(f => f.FieldTypeId == cFieldView.FieldTypeId).Select().ToList(); if (!customFieldTypes.Any()) { return; } var groupF = customGroups.Find(t => t.CustomGroupId == cFieldView.CustomGroupId); if (groupF == null || groupF.TableId < 1) { var fieldCustomGroups = _customGroupService.Query(o => o.CustomGroupId == cFieldView.CustomGroupId).Select().ToList(); if (!fieldCustomGroups.Any()) { return; } var g = fieldCustomGroups[0]; groupF = new CustomGroupViewModel { TableId = g.TableId, CustomGroupId = g.CustomGroupId, GroupName = g.GroupName, TabIndex = g.TabIndex, CustomFieldViewModels = new List <GenericViewModel>() }; } var customFieldType = customFieldTypes[0]; var customFieldViewModel = new GenericViewModel { FieldTypeName = customFieldTypes[0].FieldTypeName }; if (!string.IsNullOrEmpty(r.CustomListId)) { var customList = _customListService.Query(s => s.CustomListId == r.CustomListId && string.IsNullOrEmpty(s.ParentListId)).Select().ToList(); if (customList.Any()) { var list = customList[0]; customFieldViewModel.CustomListId = r.CustomListId; var l1Data = _customListDataService.Query(s => s.CustomListDataId == r.CrimsCustomData).Select().ToList(); if (l1Data.Any()) { customFieldViewModel.CustomListDataName = l1Data[0].ListDataName; } var childList = _customListService.Query(s => s.ParentListId == list.CustomListId).Select().ToList(); if (childList.Any()) { customFieldViewModel.HasChildren = true; } customFieldViewModel.TableId = r.TableId; customFieldViewModel.TabIndex = cFieldView.TabIndex; customFieldViewModel.CustomFieldId = r.CustomFieldId; customFieldViewModel.CustomFieldName = cFieldView.CustomFieldName; customFieldViewModel.CustomListId = cFieldView.CustomListId; customFieldViewModel.CustomListName = list.CustomListName; customFieldViewModel.CustomGroupId = cFieldView.CustomGroupId; customFieldViewModel.FieldTypeId = cFieldView.FieldTypeId; customFieldViewModel.FieldTypeName = customFieldType.FieldTypeName; customFieldViewModel.CrimsCustomData = r.CrimsCustomData; customFieldViewModel.EnrollmentId = r.EnrollmentId; customFieldViewModel.CustomDataId = r.CustomDataId; } } else { customFieldViewModel = new GenericViewModel { TableId = r.TableId, CustomFieldId = r.CustomFieldId, CustomFieldName = cFieldView.CustomFieldName, CustomListId = cFieldView.CustomListId, TabIndex = cFieldView.TabIndex, CustomGroupId = cFieldView.CustomGroupId, FieldTypeId = cFieldView.FieldTypeId, CustomFieldType = customFieldType, FieldTypeName = customFieldType.FieldTypeName, CrimsCustomData = r.CrimsCustomData, EnrollmentId = r.EnrollmentId, CustomDataId = r.CustomDataId, }; } if (customGroups.Exists(t => t.CustomGroupId == groupF.CustomGroupId)) { groupF.CustomFieldViewModels.Add(customFieldViewModel); } else { groupF.CustomFieldViewModels.Add(customFieldViewModel); customGroups.Add(groupF); } } }); customGroups.ForEach(g => { if (g.CustomFieldViewModels != null && g.CustomFieldViewModels.Any()) { g.CustomFieldViewModels = g.CustomFieldViewModels.OrderBy(f => f.TabIndex).ToList(); } }); customGroups = customGroups.OrderBy(m => m.TabIndex).ToList(); genObj.CustomGroupViewModels = customGroups; return(Json(genObj, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new GenericObjectModel(), JsonRequestBehavior.AllowGet)); } }
public ActionResult GetFields(JQueryDataTableParamModel param) { try { var customFields = string.IsNullOrEmpty(param.sSearch) ? _customFieldService.Query().Select().OrderBy(f => f.CustomFieldName).Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList() : _customFieldService.Query().Select().Where(s => s.CustomFieldName.ToLower().Contains(param.sSearch.ToLower())).OrderBy(f => f.CustomFieldName).Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList(); var countG = string.IsNullOrEmpty(param.sSearch) ? _customFieldService.Query().Select().Count() : _customFieldService.Query().Select().Count(s => s.CustomFieldName.ToLower().Contains(param.sSearch.ToLower())); var cField = new List <CustomFieldViewModel>(); if (customFields.Any()) { customFields.ForEach(c => { var cFieldView = new CustomFieldViewModel { TableId = c.TableId, CustomListId = c.CustomListId, CustomFieldName = c.CustomFieldName, CustomFieldId = c.CustomFieldId, CustomGroupId = c.CustomGroupId, FieldTypeId = c.FieldTypeId, CustomFieldSize = c.CustomFieldSize, TabIndex = c.TabIndex, Required = c.Required }; var customList = _customListService.Query(l => l.CustomListId == c.CustomListId).Select().ToList(); if (customList.Any()) { cFieldView.CustomListName = customList[0].CustomListName; } var customGroups = _customGroupService.Query(l => l.CustomGroupId == c.CustomGroupId).Select().ToList(); if (customGroups.Any()) { cFieldView.CustomGroupName = customGroups[0].GroupName; } var customFieldTypes = _customFieldTypeService.Query(l => l.FieldTypeId == c.FieldTypeId).Select().ToList(); if (customFieldTypes.Any()) { cFieldView.FieldTypeName = customFieldTypes[0].FieldTypeName; } cField.Add(cFieldView); }); } var result = from c in cField select new[] { c.CustomFieldId, c.CustomFieldName, c.FieldTypeName, c.CustomListName, c.CustomGroupName, c.CustomFieldSize, c.TabIndex.ToString() }; return(Json(new { param.sEcho, iTotalRecords = countG, iTotalDisplayRecords = countG, aaData = result }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { param.sEcho, iTotalRecords = 0, iTotalDisplayRecords = 0, aaData = new List <string>() }, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetCustomDataGroupFields_New(string baseDataId) { var genObj = new GenericObjectModel { CustomGroupViewModels = new List <CustomGroupViewModel>() }; try { var currentProject = GetProjectInSession(); if (string.IsNullOrEmpty(currentProject?.ProjectCode)) { return(Json(new List <CustomGroupViewModel>(), JsonRequestBehavior.AllowGet)); } var projectCustomGroups = _projectCustomGroupService.Query(g => g.ProjectCode == currentProject.ProjectCode).Select().ToList(); if (!projectCustomGroups.Any()) { return(Json(new List <CustomGroupViewModel>(), JsonRequestBehavior.AllowGet)); } var baseDataList = _baseDataService.Query(b => b.EnrollmentId == baseDataId).Select().ToList(); if (!baseDataList.Any()) { return(Json(genObj, JsonRequestBehavior.AllowGet)); } var baseData = baseDataList[0]; genObj.Name = baseData.Firstname + " " + baseData.Surname; genObj.ProjectSiteId = baseData.ProjectSiteId; genObj.EnrollmentId = baseData.EnrollmentId; genObj.ProjectPrimaryCode = baseData.ProjectPrimaryCode; genObj.FormPath = baseData.FormPath; var customGroups = new List <CustomGroupViewModel>(); projectCustomGroups.ForEach(t => { var newGroups = _customGroupService.Query(d => d.CustomGroupId == t.CustomGroupId).Select(g => new CustomGroupViewModel { TableId = g.TableId, CustomGroupId = g.CustomGroupId, GroupName = g.GroupName, TabIndex = g.TabIndex }).ToList(); if (newGroups.Any()) { customGroups.Add(newGroups[0]); } }); if (!customGroups.Any()) { return(Json(genObj, JsonRequestBehavior.AllowGet)); } customGroups.ForEach(c => { c.CustomFieldViewModels = new List <GenericViewModel>(); var customFields = _customFieldService.Query(g => g.CustomGroupId == c.CustomGroupId).Select().ToList(); if (customFields.Any()) { customFields.ForEach(cFieldView => { var customFieldTypes = _customFieldTypeService.Query(f => f.FieldTypeId == cFieldView.FieldTypeId).Select().ToList(); if (!customFieldTypes.Any()) { return; } var customFieldType = customFieldTypes[0]; var customFieldViewModel = new GenericViewModel { CustomList = new CustomListViewModel(), CustomFieldType = new CustomFieldType() }; if (customFieldType.FieldTypeName == "List") { var customList = _customListService.Query(s => s.CustomListId == cFieldView.CustomListId && string.IsNullOrEmpty(s.ParentListId)).Select().ToList(); if (customList.Any()) { var list = customList[0]; var l1 = new CustomListViewModel { CustomListName = list.CustomListName, CustomListId = list.CustomListId, HasChildren = false, ParentListId = list.ParentListId, CustomListDatas = new List <CustomListData>() }; //var l1Data = _customListDataService.Query(s => s.CustomListId == l1.CustomListId).Select().ToList(); //if (l1Data.Any()) //{ // l1.CustomListDatas = l1Data; //} var childList = _customListService.Query(s => s.ParentListId == list.CustomListId).Select().ToList(); if (childList.Any()) { l1.HasChildren = true; } customFieldViewModel.TableId = cFieldView.TableId; customFieldViewModel.CustomFieldId = cFieldView.CustomFieldId; customFieldViewModel.CustomFieldName = cFieldView.CustomFieldName; customFieldViewModel.CustomFieldSize = cFieldView.CustomFieldSize; customFieldViewModel.CustomListId = cFieldView.CustomListId; customFieldViewModel.ParentFieldId = cFieldView.ParentFieldId; customFieldViewModel.CustomGroupId = cFieldView.CustomGroupId; customFieldViewModel.FieldTypeId = cFieldView.FieldTypeId; customFieldViewModel.TabIndex = cFieldView.TabIndex; customFieldViewModel.Required = cFieldView.Required; customFieldViewModel.CustomFieldType = customFieldType; customFieldViewModel.CustomList = l1; } } else { customFieldViewModel = new GenericViewModel { TableId = cFieldView.TableId, CustomFieldId = cFieldView.CustomFieldId, CustomFieldName = cFieldView.CustomFieldName, CustomFieldSize = cFieldView.CustomFieldSize, ParentFieldId = cFieldView.ParentFieldId, CustomListId = cFieldView.CustomListId, CustomGroupId = cFieldView.CustomGroupId, FieldTypeId = cFieldView.FieldTypeId, TabIndex = cFieldView.TabIndex, Required = cFieldView.Required, CustomFieldType = customFieldType }; } c.CustomFieldViewModels.Add(customFieldViewModel); }); } genObj.CustomGroupViewModels.Add(c); }); genObj.CustomGroupViewModels.ForEach(g => { g.CustomFieldViewModels = g.CustomFieldViewModels.OrderBy(f => f.TabIndex).ToList(); }); var ordered = genObj.CustomGroupViewModels.OrderBy(m => m.TabIndex).ToList(); return(Json(ordered, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new List <CustomGroupViewModel>(), JsonRequestBehavior.AllowGet)); } }