public ActionResult GetProjectCustomLists(string projectCode) { var projectCustomGroups = _projectCustomListService.Query(p => p.ProjectCode == projectCode).Select().ToList(); var pcViewList = new List <ProjectCustomListViewModel>(); if (projectCustomGroups.Any()) { projectCustomGroups.ForEach(c => { var pclView = new ProjectCustomListViewModel { TableId = c.TableId, ProjectCode = c.ProjectCode, CustomListId = c.CustomListId }; var groups = _customListService.Query(l => l.CustomListId == c.CustomListId).Select().ToList(); if (groups.Any()) { pclView.CustomListName = groups[0].CustomListName; pcViewList.Add(pclView); } }); } return(Json(pcViewList, JsonRequestBehavior.AllowGet)); }
public ActionResult GetUserCustomDatas(string enrollmentId) { if (string.IsNullOrEmpty(enrollmentId)) { return(Json(new List <CustomData>(), JsonRequestBehavior.AllowGet)); } var customDatas = _customDataService.Query(f => f.EnrollmentId == enrollmentId).Select().ToList(); if (!customDatas.Any()) { return(Json(new List <CustomData>(), JsonRequestBehavior.AllowGet)); } var viewModels = new List <CustomDataViewModel>(); customDatas.ForEach(d => { var viewModel = new CustomDataViewModel { TableId = d.TableId, CustomDataId = d.CustomDataId, CustomFieldId = d.CustomFieldId, EnrollmentId = d.EnrollmentId, ChildCrimsCustomData = d.ChildCrimsCustomData, CrimsCustomData = d.CrimsCustomData, CustomListId = d.CustomListId, ProjectSIteId = d.ProjectSIteId }; if (!string.IsNullOrEmpty(d.CustomListId)) { var customList = _customListService.Query(f => f.CustomListId == d.CustomListId && string.IsNullOrEmpty(f.ParentListId)).Select().ToList(); if (customList.Any()) { viewModel.ParentListId = customList[0].ParentListId; var parentList = customList[0]; var childList = _customListService.Query(f => !string.IsNullOrEmpty(f.ParentListId) && f.ParentListId == parentList.CustomListId).Select().ToList(); if (childList.Any()) { viewModel.HasChildren = true; } } } viewModels.Add(viewModel); }); return(Json(viewModels, JsonRequestBehavior.AllowGet)); }
public ActionResult GetLists(JQueryDataTableParamModel param) { try { var customLists = string.IsNullOrEmpty(param.sSearch) ? _customListService.Query().Select(c => new CustomListViewModel { TableId = c.TableId, CustomListId = c.CustomListId, CustomListName = c.CustomListName, ParentListId = c.ParentListId }).OrderBy(f => f.CustomListName).Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList() : _customListService.Query().Select(c => new CustomListViewModel { TableId = c.TableId, CustomListId = c.CustomListId, CustomListName = c.CustomListName, ParentListId = c.ParentListId }).Where(s => s.CustomListName.ToLower().Contains(param.sSearch.ToLower())).OrderBy(f => f.CustomListName).Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList(); var countG = string.IsNullOrEmpty(param.sSearch) ? _customListService.Query().Select().Count() : _customListService.Query().Select().Count(s => s.CustomListName.ToLower().Contains(param.sSearch.ToLower())); if (customLists.Any()) { customLists.ForEach(c => { if (!string.IsNullOrEmpty(c.ParentListId)) { var parentList = _customListService.Query(l => l.CustomListId == c.ParentListId).Select().ToList(); if (parentList.Any()) { c.ParentListName = parentList[0].CustomListName; } } }); } var result = from c in customLists select new[] { c.CustomListId, c.CustomListName, c.ParentListName }; 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 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 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 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)); } }
public ActionResult GenerateLicense(string projectCode) { var acResponse = new ActivityResponse(); try { if (string.IsNullOrEmpty(projectCode)) { acResponse.Code = -1; acResponse.Message = "The selected Project information could not be accessed. Please try again later"; return(Json(acResponse, JsonRequestBehavior.AllowGet)); } var projects = _projectService.Query(p => p.ProjectCode == projectCode).Select().ToList(); if (!projects.Any()) { acResponse.Code = -1; acResponse.Message = "The selected Project information could not be accessed. Please try again later"; return(Json(acResponse, JsonRequestBehavior.AllowGet)); } var fieldTypes = _customFieldTypeService.Queryable().ToList(); if (!fieldTypes.Any()) { acResponse.Code = -1; acResponse.Message = "Project Custom Fields could not be retrieved. Please ensure all required setups are handled appropriately before proceeding."; return(Json(acResponse, JsonRequestBehavior.AllowGet)); } var projectCustomGroups = _projectCustomGroupService.Query(g => g.ProjectCode == projectCode).Select().ToList(); if (!projectCustomGroups.Any()) { acResponse.Code = -1; acResponse.Message = "Project Custom Groups could not be retrieved. Please ensure all required setups are handled appropriately before proceeding."; return(Json(acResponse, JsonRequestBehavior.AllowGet)); } var projectCustomFields = _projectCustomFieldService.Query(g => g.ProjectCode == projectCode).Select().ToList(); if (!projectCustomFields.Any()) { acResponse.Code = -1; acResponse.Message = "Project Custom Fields could not be retrieved. Please ensure all required setups are handled appropriately before proceeding."; return(Json(acResponse, JsonRequestBehavior.AllowGet)); } var project = projects[0]; var projectLicense = new ProjectLicense { ProjectName = project.ProjectName, ProjectDescription = project.ProjectDescription, ProjectCode = project.ProjectCode, LicenseExpiryDate = project.LicenseExpiryDate, DateCreated = project.DateCreated, ProjectCustomGroups = projectCustomGroups.ToArray(), ProjectCustomFields = projectCustomFields.ToArray() }; var customGroups = new List <CustomGroup>(); var customFields = new List <CustomField>(); var customList = new List <CustomList>(); var customListData = new List <CustomListData>(); projectCustomGroups.ForEach(c => { var groups = _customGroupService.Query(l => l.CustomGroupId == c.CustomGroupId).Select().ToList(); if (groups.Any()) { if (!customGroups.Exists(g => g.CustomGroupId == groups[0].CustomGroupId)) { customGroups.Add(groups[0]); } } }); projectCustomFields.ForEach(c => { var fields = _customFieldService.Query(l => l.CustomFieldId == c.CustomFieldId).Select().ToList(); if (!fields.Any()) { return; } var customField = fields[0]; var customLists = _customListService.Query(l => l.CustomListId == customField.CustomListId).Select().ToList(); var cGroups = _customGroupService.Query(l => l.CustomGroupId == customField.CustomGroupId).Select().ToList(); if (cGroups.Any()) { if (!customGroups.Exists(a => a.CustomGroupId == cGroups[0].CustomGroupId)) { customGroups.Add(cGroups[0]); } if (customLists.Any()) { var cListItem = customLists[0]; if (!customList.Exists(a => a.CustomListId == cListItem.CustomListId)) { customList.Add(cListItem); var list = _customListDataService.Query(d => d.CustomListId == cListItem.CustomListId).Select().ToList(); if (list.Any()) { list.ForEach(l => { if (!customListData.Exists(a => a.CustomListDataId == l.CustomListDataId)) { customListData.Add(l); } }); } } } customFields.Add(customField); } }); projectLicense.CustomFields = customFields.ToArray(); projectLicense.CustomGroups = customGroups.ToArray(); projectLicense.CustomLists = customList.ToArray(); projectLicense.CustomListData = customListData.ToArray(); projectLicense.CustomFieldTypes = fieldTypes.ToArray(); const string folderPath = "~/TempProjectSetUp"; var filePath = Server.MapPath(folderPath + "/" + projectLicense.ProjectName.Replace(" ", "-") + ".json"); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } System.IO.File.WriteAllText(filePath, JsonConvert.SerializeObject(projectLicense)); acResponse.Code = 5; acResponse.DownloadLink = GenericHelpers.MapPath(filePath); acResponse.Message = "Project License was successfully generated."; return(Json(acResponse, JsonRequestBehavior.AllowGet)); } catch (Exception e) { ErrorLogger.LogError(e.StackTrace, e.Source, e.Message); acResponse.Code = -1; acResponse.Message = "The selected Project information could not be accessed. Please try again later"; return(Json(acResponse, JsonRequestBehavior.AllowGet)); } }