// GET: ProjectCustomListData
        public ActionResult Index()
        {
            var projectCustomListData = _projectCustomListDataService.Queryable().ToList();
            var cListData             = new List <ProjectCustomListDataViewModel>();

            if (projectCustomListData.Any())
            {
                projectCustomListData.ForEach(c =>
                {
                    var cListDataView = new ProjectCustomListDataViewModel
                    {
                        TableId          = c.TableId,
                        ProjectCode      = c.ProjectCode,
                        CustomListDataId = c.CustomListDataId
                    };

                    var parentList = _customListDataService.Query(l => l.CustomListDataId == c.CustomListDataId).Select().ToList();
                    if (parentList.Any())
                    {
                        cListDataView.CustomListDataName = parentList[0].ListDataName;
                    }
                    cListData.Add(cListDataView);
                });
            }

            return(View(cListData));
        }
        public ActionResult GetCustomLists(string customListId)
        {
            try
            {
                var customList = _customListService.Query(s => s.CustomListId == customListId).Select().ToList();

                if (customList.Any())
                {
                    var p = customList[0];

                    var l1 = new CustomListViewModel
                    {
                        CustomListName  = p.CustomListName,
                        CustomListId    = p.CustomListId,
                        ParentListId    = p.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 == p.CustomListId).Select().ToList();

                    if (childList.Any())
                    {
                        l1.HasChildren = true;
                    }

                    return(Json(l1, JsonRequestBehavior.AllowGet));
                }
                return(Json(new List <CustomGroupViewModel>(), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new List <CustomGroupViewModel>(), JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult DeleteCustomList(string customListId)
        {
            var acResponse = new ActivityResponse();

            try
            {
                if (string.IsNullOrEmpty(customListId))
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Invalid selection.";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                var customListDatas = _customListDataService.Query(c => c.CustomListId == customListId).Select().ToList();
                if (customListDatas.Any())
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "This Item cannot be deleted. It has dependent data.";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                var customLists = _customListService.Query(c => c.CustomListId == customListId).Select().ToList();
                if (!customLists.Any())
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "This Item could not be deleted. Please try again later.";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                var customList = customLists[0];
                _customListService.Delete(customList);
                _unitOfWork.SaveChanges();

                acResponse.Code    = 5;
                acResponse.Message = "Custom List was successfully deleted.";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                acResponse.Code    = -1;
                acResponse.Message = "An unknown error was encountered. Please try again.";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult ProcessCustomListData(List <CustomListDataViewModel> listDataList)
        {
            var acResponse = new ActivityResponse {
                ListDataList = listDataList, SaveMessages = new List <string>()
            };

            try
            {
                if (!listDataList.Any())
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "An unknown error was encountered. Please try again later";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                if (listDataList.Any(p => string.IsNullOrEmpty(p.CustomListId) || string.IsNullOrEmpty(p.ListDataName)))
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Please provide all required fields and try again";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                listDataList.ForEach(p =>
                {
                    if (string.IsNullOrEmpty(p.CustomListDataId) || p.CustomListDataId == "0")
                    {
                        var pcFields = _customListDataService.Query(o => o.ListDataName == p.ListDataName && o.CustomListId == p.CustomListId).Select().ToList();
                        if (!pcFields.Any())
                        {
                            var data = new CustomListData
                            {
                                CustomListDataId = Guid.NewGuid().ToString(),
                                CustomListId     = p.CustomListId,
                                ListDataName     = p.ListDataName
                            };

                            if (!string.IsNullOrEmpty(p.ParentNodeId))
                            {
                                data.ParentNodeId = p.ParentNodeId;
                            }
                            else if (!string.IsNullOrEmpty(p.ParentData))
                            {
                                var pNodeData = _customListDataService.Query(o => o.ListDataName.ToLower() == p.ParentData.ToLower()).Select().ToList();
                                if (pNodeData.Any())
                                {
                                    data.ParentNodeId = pNodeData[0].CustomListDataId;
                                }
                            }

                            _customListDataService.Insert(data);
                            _unitOfWork.SaveChanges();
                        }
                    }
                    else
                    {
                        //Checks if CustomListData Name Exists if the CustomListDataId is not null/empty
                        var dupDatas = _customListDataService.Query(o => o.ListDataName == p.ListDataName && o.CustomListId == p.CustomListId && o.CustomListDataId != p.CustomListDataId).Select().ToList();
                        if (!dupDatas.Any())
                        {
                            var dataListToUpdate = _customListDataService.Query(o => o.CustomListDataId == p.CustomListDataId).Select().ToList();
                            if (dataListToUpdate.Any())
                            {
                                var dataToUpdate = dataListToUpdate[0];
                                if (!string.IsNullOrEmpty(p.ParentNodeId))
                                {
                                    dataToUpdate.ParentNodeId = p.ParentNodeId;
                                }
                                else if (!string.IsNullOrEmpty(p.ParentData))
                                {
                                    var pNodeData = _customListDataService.Query(o => o.ListDataName.ToLower() == p.ParentData.ToLower()).Select().ToList();
                                    if (pNodeData.Any())
                                    {
                                        dataToUpdate.ParentNodeId = pNodeData[0].CustomListDataId;
                                    }
                                }

                                dataToUpdate.ListDataName = p.ListDataName;
                                dataToUpdate.CustomListId = p.CustomListId;
                                _customListDataService.Update(dataToUpdate);
                                _unitOfWork.SaveChanges();
                            }
                        }
                    }
                });

                acResponse.Code    = 5;
                acResponse.Message = "Process was successfully completed";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                acResponse.Code    = -1;
                acResponse.Message = "An unknown error was encountered. Please try again.";
                ErrorLogger.LogError(e.StackTrace, e.Source, e.Message);
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #5
0
        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 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));
            }
        }