Beispiel #1
0
        /// <summary>
        /// Saves the custom field values.
        /// </summary>
        /// <param name="issueId">The issue id.</param>
        /// <param name="fields">The fields.</param>
        /// <returns></returns>
        public static bool SaveCustomFieldValues(int issueId, List <CustomField> fields, bool isNewIssue = false)
        {
            if (issueId <= Globals.NEW_ID)
            {
                throw new ArgumentNullException("issueId");
            }
            if (fields == null)
            {
                throw (new ArgumentOutOfRangeException("fields"));
            }

            try
            {
                var issueChanges = GetCustomFieldChanges(issueId, CustomFieldManager.GetByIssueId(issueId), fields);
                DataProviderManager.Provider.SaveCustomFieldValues(issueId, fields);

                if (!isNewIssue)
                {
                    UpdateHistory(issueChanges);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(LoggingManager.GetErrorMessageResource("SaveCustomFieldValuesError"), ex);
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Clones the project.
        /// </summary>
        /// <param name="projectId">The project id.</param>
        /// <param name="projectName">Name of the project.</param>
        /// <returns></returns>
        public static int CloneProject(int projectId, string projectName)
        {
            if (projectId <= Globals.NEW_ID)
            {
                throw (new ArgumentOutOfRangeException("projectId"));
            }
            if (string.IsNullOrEmpty(projectName))
            {
                throw new ArgumentNullException("projectName");
            }

            var newProjectId = DataProviderManager.Provider.CloneProject(projectId, projectName, Security.GetUserName());

            if (newProjectId != 0)
            {
                var newProject = GetById(newProjectId);

                CustomFieldManager.UpdateCustomFieldView(newProjectId);

                try
                {
                    if (newProject.AllowAttachments && HostSettingManager.Get(HostSettingNames.AttachmentStorageType, 0) == (int)IssueAttachmentStorageTypes.FileSystem)
                    {
                        // set upload path to new Guid
                        newProject.UploadPath = Guid.NewGuid().ToString();

                        DataProviderManager.Provider.UpdateProject(newProject);

                        var fullPath = string.Concat(HostSettingManager.Get(HostSettingNames.AttachmentUploadPath), newProject.UploadPath);

                        if (fullPath.StartsWith("~"))
                        {
                            fullPath = HttpContext.Current.Server.MapPath(fullPath);
                        }

                        Directory.CreateDirectory(fullPath);
                    }
                }
                catch (Exception ex)
                {
                    if (Log.IsErrorEnabled)
                    {
                        Log.Error(string.Format(LoggingManager.GetErrorMessageResource("CreateProjectUploadFolderError"), newProject.UploadPath, projectId), ex);
                    }
                }

                HttpContext.Current.Cache.Remove("RolePermission");

                return(newProjectId);
            }

            return(0);
        }
        /// <summary>
        /// Creates the custom field views for issue
        /// </summary>
        /// <returns></returns>
        public static bool CreateCustomFieldViews()
        {
            try
            {
                var projects = DataProviderManager.Provider.GetAllProjects();

                foreach (var project in projects)
                {
                    CustomFieldManager.UpdateCustomFieldView(project.Id);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }

            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// Creates the custom field views for issue
        /// </summary>
        /// <returns></returns>
        public static bool CreateCustomFieldViews()
        {
            try
            {
                var  projects   = DataProviderManager.Provider.GetAllProjects();
                bool successful = true;
                foreach (var project in projects)
                {
                    if (!CustomFieldManager.UpdateCustomFieldView(project.Id))
                    {
                        successful = false;
                    }
                }

                return(successful);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }

            return(false);
        }
Beispiel #5
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns></returns>
        public static bool SaveOrUpdate(Project entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (string.IsNullOrEmpty(entity.Name))
            {
                throw (new ArgumentException("The project name cannot be empty or null"));
            }

            if (entity.Id > 0)
            {
                return(Update(entity));
            }

            var tempId = DataProviderManager.Provider.CreateNewProject(entity);

            if (tempId <= Globals.NEW_ID)
            {
                return(false);
            }

            entity.Id = tempId;

            CustomFieldManager.UpdateCustomFieldView(entity.Id);

            try
            {
                //create default roles for new project.
                RoleManager.CreateDefaultProjectRoles(entity.Id);
            }
            catch (Exception ex)
            {
                if (Log.IsErrorEnabled)
                {
                    Log.Error(
                        string.Format(
                            LoggingManager.GetErrorMessageResource("CouldNotCreateDefaultProjectRoles"),
                            string.Format("ProjectID= {0}", entity.Id)), ex);
                }
                return(false);
            }

            //create attachment directory
            if (entity.AttachmentStorageType == IssueAttachmentStorageTypes.FileSystem)
            {
                var uploadPath     = string.Concat("~", Globals.UPLOAD_FOLDER, entity.UploadPath);
                var fullUploadPath = HttpContext.Current.Server.MapPath(uploadPath);

                try
                {
                    // BGN-1909
                    // Better santization of Upload Paths
                    if (!Utilities.CheckUploadPath(uploadPath))
                    {
                        throw new InvalidDataException(LoggingManager.GetErrorMessageResource("UploadPathInvalid"));
                    }

                    Directory.CreateDirectory(fullUploadPath);
                }
                catch (Exception ex)
                {
                    if (Log.IsErrorEnabled)
                    {
                        Log.Error(
                            string.Format(
                                LoggingManager.GetErrorMessageResource("CouldNotCreateUploadDirectory"), fullUploadPath), ex);
                    }
                    return(false);
                }
            }

            return(true);
        }