public ActionResult EditCustomField(CustomField customField)
        {
            var acResponse = new ActivityResponse();

            try
            {
                if (string.IsNullOrEmpty(customField.CustomFieldName))
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Please provide custom Field Name";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                if (string.IsNullOrEmpty(customField.CustomGroupId))
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Please select custom Group";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                if (string.IsNullOrEmpty(customField.FieldTypeId))
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Please select custom Field Type";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                //if (string.IsNullOrEmpty(customField.CustomListId))
                //{
                //    acResponse.Code = -1;
                //    acResponse.Message = "Please select custom List";
                //    return Json(acResponse, JsonRequestBehavior.AllowGet);
                //}

                //todo : try implement the commented code below for live environment
                //if (customField.FieldTypeId != "List" || customField.FieldTypeId != "Date")
                //{
                //    if (string.IsNullOrEmpty(customField.CustomFieldSize))
                //    {
                //        acResponse.Code = -1;
                //        acResponse.Message = "Please provide Custom Field Size";
                //        return Json(acResponse, JsonRequestBehavior.AllowGet);
                //    }
                //}

                _customFieldService.Update(customField);
                _unitOfWork.SaveChanges();

                acResponse.Code    = 5;
                acResponse.Message = "Custom Field was successfully updated";
                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 async Task <ActionResult> CustomFieldUpdate(MetaField metaField, List <int> Categories)
        {
            if (metaField.ID == 0)
            {
                metaField.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Added;

                _customFieldService.Insert(metaField);
            }
            else
            {
                var metaFieldExistingQuery = await _customFieldService.Query(x => x.ID == metaField.ID).Include(x => x.MetaCategories).SelectAsync();

                var metaFieldExisting = metaFieldExistingQuery.FirstOrDefault();

                metaFieldExisting.Name          = metaField.Name;
                metaFieldExisting.ControlTypeID = metaField.ControlTypeID;
                metaFieldExisting.Options       = metaField.Options;
                metaFieldExisting.Required      = metaField.Required;
                metaFieldExisting.Searchable    = metaField.Searchable;

                metaFieldExisting.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Modified;

                _customFieldService.Update(metaFieldExisting);

                // Delete existing
                foreach (var category in metaFieldExisting.MetaCategories)
                {
                    await _customFieldCategoryService.DeleteAsync(category.ID);
                }
            }

            if (Categories != null)
            {
                // Insert meta categories
                var metaCategories = Categories.Select(x => new MetaCategory()
                {
                    CategoryID  = x,
                    FieldID     = metaField.ID,
                    ObjectState = Repository.Pattern.Infrastructure.ObjectState.Added
                }).ToList();

                _customFieldCategoryService.InsertRange(metaCategories);
            }

            await _unitOfWorkAsync.SaveChangesAsync();

            return(RedirectToAction("CustomFields"));
        }
Exemple #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));
            }
        }