コード例 #1
0
        public ActionResult GetProjectCustomGroups(string projectCode)
        {
            var projectCustomGroups = _projectCustomGroupService.Query(p => p.ProjectCode == projectCode).Select().ToList();
            var pcViewList          = new List <ProjectCustomGroupViewModel>();

            if (projectCustomGroups.Any())
            {
                projectCustomGroups.ForEach(c =>
                {
                    var pcgView = new ProjectCustomGroupViewModel
                    {
                        TableId       = c.TableId,
                        ProjectCode   = c.ProjectCode,
                        CustomGroupId = c.CustomGroupId,
                        TabIndex      = c.TabIndex
                    };

                    var groups = _customGroupService.Query(l => l.CustomGroupId == c.CustomGroupId).Select().ToList();

                    if (groups.Any())
                    {
                        pcgView.CustomGroupName = groups[0].GroupName;
                        pcViewList.Add(pcgView);
                    }
                });
            }

            return(Json(pcViewList, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
        public ActionResult InstallLicense()
        {
            var acResponse = new ActivityResponse();

            try
            {
                if (Request.Files != null)
                {
                    var file = Request.Files[0];

                    if (file == null || file.ContentLength < 1)
                    {
                        acResponse.Code    = -1;
                        acResponse.Message = "The provided Site License File could not be correctly accessed. Please provide all required fields and try again later";
                        return(Json(acResponse, JsonRequestBehavior.AllowGet));
                    }

                    const string folderPath = "~/TempProject";

                    var mainPath = Server.MapPath(folderPath);

                    if (!Directory.Exists(mainPath))
                    {
                        Directory.CreateDirectory(mainPath);
                        var dInfo     = new DirectoryInfo(mainPath);
                        var dSecurity = dInfo.GetAccessControl();
                        dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
                        dInfo.SetAccessControl(dSecurity);
                    }

                    var fileName = file.FileName;

                    var existingFiles = Directory.GetFiles(mainPath);
                    if (existingFiles.Any())
                    {
                        existingFiles.ForEach(System.IO.File.Delete);
                    }

                    var path = Path.Combine(mainPath, fileName);

                    file.SaveAs(path);

                    var projectLicense = JsonConvert.DeserializeObject <ProjectLicense>(System.IO.File.ReadAllText(path));

                    var customGroups        = new List <CustomGroup>(projectLicense.CustomGroups);
                    var customFieldTypes    = new List <CustomFieldType>(projectLicense.CustomFieldTypes);
                    var customFields        = new List <CustomField>(projectLicense.CustomFields);
                    var customLists         = new List <CustomList>(projectLicense.CustomLists);
                    var customListData      = new List <CustomListData>(projectLicense.CustomListData);
                    var projectCustomGroups = new List <ProjectCustomGroup>(projectLicense.ProjectCustomGroups);
                    var projectCustomFields = new List <ProjectCustomField>(projectLicense.ProjectCustomFields);

                    if (string.IsNullOrEmpty(projectLicense?.ProjectCode) || !customFieldTypes.Any() || !customGroups.Any() || !customFields.Any() || !customLists.Any() || !customListData.Any() || !projectCustomGroups.Any() || !projectCustomFields.Any())
                    {
                        acResponse.Code    = -1;
                        acResponse.Message = "The provided Project setup File could not be correctly accessed. Please provide all required fields and try again later";
                        return(Json(acResponse, JsonRequestBehavior.AllowGet));
                    }

                    var processedProjectTableId = 0;

                    var projects = _projectService.Query(p => p.ProjectCode == projectLicense.ProjectCode).Select().ToList();
                    if (projects.Any())
                    {
                        var project = projects[0];
                        project.ProjectName        = projectLicense.ProjectName;
                        project.ProjectDescription = projectLicense.ProjectDescription;
                        project.ActivationCode     = projectLicense.ActivationCode;
                        project.OnlineMode         = projectLicense.OnlineMode;
                        project.LicenseExpiryDate  = projectLicense.LicenseExpiryDate;
                        _projectService.Update(project);
                        _unitOfWork.SaveChanges();
                        processedProjectTableId = project.TableId;
                    }
                    else
                    {
                        var project = new Project
                        {
                            ProjectName        = projectLicense.ProjectName,
                            ProjectDescription = projectLicense.ProjectDescription,
                            ProjectCode        = projectLicense.ProjectCode,
                            DateCreated        = DateTime.Now,
                            LicenceCode        = projectLicense.LicenceCode,
                            ActivationCode     = projectLicense.ActivationCode,
                            OnlineMode         = projectLicense.OnlineMode,
                            LicenseExpiryDate  = projectLicense.LicenseExpiryDate
                        };
                        _projectService.Insert(project);
                        processedProjectTableId = _unitOfWork.SaveChanges();
                    }

                    if (processedProjectTableId < 1)
                    {
                        acResponse.Code    = -1;
                        acResponse.Message = "Project Licensing failed. Please try again later of contact support.";
                        return(Json(acResponse, JsonRequestBehavior.AllowGet));
                    }
                    var oldFieldTypes = _customFieldTypeService.Queryable().ToList();
                    if (oldFieldTypes.Any())
                    {
                        customFieldTypes.ForEach(g =>
                        {
                            var fieldTypes = oldFieldTypes.Where(x => x.FieldTypeId == g.FieldTypeId).ToList();
                            if (fieldTypes.Any())
                            {
                                var f           = fieldTypes[0];
                                f.FieldTypeName = g.FieldTypeName;
                                _customFieldTypeService.Update(f);
                                _unitOfWork.SaveChanges();
                            }
                            else
                            {
                                _customFieldTypeService.Insert(g);
                                _unitOfWork.SaveChanges();
                            }
                        });
                    }
                    else
                    {
                        _customFieldTypeService.InsertRange(customFieldTypes);
                    }

                    var projectCustomGroupEntities = _projectCustomGroupService.Query(g => g.ProjectCode == projectLicense.ProjectCode).Select().ToList();
                    if (projectCustomGroupEntities.Any())
                    {
                        projectCustomGroups.ForEach(g =>
                        {
                            var group = projectCustomGroupEntities.Find(d => d.CustomGroupId == g.CustomGroupId);
                            if (!string.IsNullOrEmpty(@group?.CustomGroupId))
                            {
                                group.TabIndex = g.TabIndex;
                                _projectCustomGroupService.Update(group);
                                _unitOfWork.SaveChanges();
                            }
                            else
                            {
                                _projectCustomGroupService.Insert(g);
                                _unitOfWork.SaveChanges();
                            }
                        });
                    }
                    else
                    {
                        _projectCustomGroupService.InsertRange(projectCustomGroups);
                    }


                    var projectCustomFieldEntities = _projectCustomFieldService.Query(f => f.ProjectCode == projectLicense.ProjectCode).Select().ToList();
                    if (projectCustomFieldEntities.Any())
                    {
                        projectCustomFields.ForEach(g =>
                        {
                            var field = projectCustomFieldEntities.Find(d => d.CustomFieldId == g.CustomFieldId);
                            if (string.IsNullOrEmpty(field?.CustomFieldId))
                            {
                                _projectCustomFieldService.Insert(g);
                                _unitOfWork.SaveChanges();
                            }
                        });
                    }
                    else
                    {
                        _projectCustomFieldService.InsertRange(projectCustomFields);
                    }

                    var customGroupEntities = _customGroupService.Queryable().ToList();
                    if (customGroupEntities.Any())
                    {
                        customGroups.ForEach(g =>
                        {
                            var cGroup = customGroupEntities.Find(d => d.CustomGroupId == g.CustomGroupId);
                            if (!string.IsNullOrEmpty(cGroup?.CustomGroupId))
                            {
                                cGroup.GroupName = g.GroupName;
                                cGroup.TabIndex  = g.TabIndex;
                                _customGroupService.Update(cGroup);
                                _unitOfWork.SaveChanges();
                            }
                            else
                            {
                                g.TableId = 0;
                                _customGroupService.Insert(g);
                                _unitOfWork.SaveChanges();
                            }
                        });
                    }
                    else
                    {
                        _customGroupService.InsertRange(customGroups);
                    }

                    var customFieldEntities = _customFieldService.Queryable().ToList();
                    if (customFieldEntities.Any())
                    {
                        customFields.ForEach(g =>
                        {
                            var cField = customFieldEntities.Find(d => d.CustomFieldId == g.CustomFieldId);
                            if (!string.IsNullOrEmpty(cField?.CustomFieldId))
                            {
                                cField.CustomFieldName = g.CustomFieldName;
                                cField.TabIndex        = g.TabIndex;
                                cField.CustomFieldSize = g.CustomFieldSize;
                                cField.CustomListId    = g.CustomListId;
                                cField.ParentFieldId   = g.ParentFieldId;
                                cField.Required        = g.Required;
                                cField.FieldTypeId     = g.FieldTypeId;
                                cField.CustomGroupId   = g.CustomGroupId;
                                _customFieldService.Update(cField);
                                _unitOfWork.SaveChanges();
                            }
                            else
                            {
                                g.TableId = 0;
                                _customFieldService.Insert(g);
                                _unitOfWork.SaveChanges();
                            }
                        });
                    }
                    else
                    {
                        _customFieldService.InsertRange(customFields);
                    }

                    var customListEntities = _customListService.Queryable().ToList();
                    if (customListEntities.Any())
                    {
                        customLists.ForEach(g =>
                        {
                            var cList = customListEntities.Find(d => d.CustomListId == g.CustomListId);
                            if (!string.IsNullOrEmpty(cList?.CustomListId))
                            {
                                cList.CustomListName = g.CustomListName;
                                cList.CustomListName = g.CustomListName;
                                cList.ParentListId   = g.ParentListId;
                                _customListService.Update(cList);
                                _unitOfWork.SaveChanges();
                            }
                            else
                            {
                                g.TableId = 0;
                                _customListService.Insert(g);
                                _unitOfWork.SaveChanges();
                            }
                        });
                    }
                    else
                    {
                        _customListService.InsertRange(customLists);
                    }

                    var customListDataEntities = _customListDataService.Queryable().ToList();
                    if (customListDataEntities.Any())
                    {
                        customListData.ForEach(g =>
                        {
                            var cListData = customListDataEntities.Find(d => d.CustomListId == g.CustomListId);
                            if (!string.IsNullOrEmpty(cListData?.CustomListId))
                            {
                                cListData.CustomListId = g.CustomListId;
                                cListData.ListDataName = g.ListDataName;
                                cListData.ParentNodeId = g.ParentNodeId;
                                _customListDataService.Update(cListData);
                                _unitOfWork.SaveChanges();
                            }
                            else
                            {
                                g.TableId = 0;
                                _customListDataService.Insert(g);
                                _unitOfWork.SaveChanges();
                            }
                        });
                    }
                    else
                    {
                        _customListDataService.InsertRange(customListData);
                    }

                    _unitOfWork.SaveChanges();

                    //Necesary to initialise and construct the Identity Tables in the created database
                    var usermanager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
                    usermanager?.FindByEmail("*****@*****.**");

                    acResponse.Code    = 5;
                    acResponse.Message = "The Project License was successfully installed.";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }
                acResponse.Code    = -1;
                acResponse.Message = "The provided Site License File could not be correctly accessed. Please provide all required fields and try again later";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                ErrorLogger.LogError(e.StackTrace, e.Source, e.Message);
                acResponse.Code    = -1;
                acResponse.Message = e.Message;
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #4
0
        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));
            }
        }