示例#1
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                try
                {
                    IList<string> segments = Request.GetFriendlyUrlSegments();
                    ProjectId = Int32.Parse(segments[0]);
                }
                catch
                {
                    ProjectId = Request.QueryString.Get("pid", 0);
                }

                // If don't know project or issue then redirect to something missing page
                if (ProjectId == 0)
                    ErrorRedirector.TransferToSomethingMissingPage(Page);

                CurrentProject = ProjectManager.GetById(ProjectId);
                litProject.Text = CurrentProject.Name;
                litProjectCode.Text = CurrentProject.Code;

                if (CurrentProject == null)
                {
                    ErrorRedirector.TransferToNotFoundPage(Page);
                    return;
                }

                //security check: add issue
                if (!UserManager.HasPermission(ProjectId, Common.Permission.AddIssue.ToString()))
                {
                    ErrorRedirector.TransferToLoginPage(Page);
                }

                BindOptions();
                BindDefaultValues();

                //check users role permission for adding an attachment
                if (!Page.User.Identity.IsAuthenticated || !UserManager.HasPermission(ProjectId, Common.Permission.AddAttachment.ToString()))
                {
                    pnlAddAttachment.Visible = false;
                }
                else if (HostSettingManager.Get(HostSettingNames.AllowAttachments, false) && CurrentProject.AllowAttachments)
                {
                    pnlAddAttachment.Visible = true;
                }
            }

            //need to rebind these on every postback because of dynamic controls
            ctlCustomFields.DataSource = CustomFieldManager.GetByProjectId(ProjectId);
            ctlCustomFields.DataBind();

            // The ExpandIssuePaths method is called to handle
            // the SiteMapResolve event.
            SiteMap.SiteMapResolve += ExpandIssuePaths;
        }
示例#2
0
        public void TestCreateNewProject()
        {
            Project p = new Project()
            {
               Name = "New Project Name",
               Disabled = false,
               Description = "This is a unit test project"

            };
        }
示例#3
0
        /// <summary>
        /// Updates the project.
        /// </summary>
        /// <param name="projectToUpdate">The project to update.</param>
        /// <returns></returns>
        public override bool UpdateProject(Project projectToUpdate)
        {
            if (projectToUpdate == null) throw (new ArgumentNullException("projectToUpdate"));
            if (projectToUpdate.Id <= 0) throw (new ArgumentOutOfRangeException("projectToUpdate"));

            using (var sqlCmd = new SqlCommand())
            {
                AddParamToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
                AddParamToSqlCmd(sqlCmd, "@ProjectId", SqlDbType.Int, 0, ParameterDirection.Input, projectToUpdate.Id);
                AddParamToSqlCmd(sqlCmd, "@AllowAttachments", SqlDbType.Bit, 0, ParameterDirection.Input, projectToUpdate.AllowAttachments);
                AddParamToSqlCmd(sqlCmd, "@ProjectDisabled", SqlDbType.Bit, 0, ParameterDirection.Input, projectToUpdate.Disabled);
                AddParamToSqlCmd(sqlCmd, "@ProjectName", SqlDbType.NText, 256, ParameterDirection.Input, projectToUpdate.Name);
                AddParamToSqlCmd(sqlCmd, "@ProjectDescription", SqlDbType.NText, 1000, ParameterDirection.Input, projectToUpdate.Description);
                AddParamToSqlCmd(sqlCmd, "@ProjectManagerUserName", SqlDbType.NVarChar, 0, ParameterDirection.Input, projectToUpdate.ManagerUserName);
                AddParamToSqlCmd(sqlCmd, "@ProjectAccessType", SqlDbType.Int, 0, ParameterDirection.Input, projectToUpdate.AccessType);
                AddParamToSqlCmd(sqlCmd, "@AttachmentUploadPath", SqlDbType.NVarChar, 80, ParameterDirection.Input, projectToUpdate.UploadPath);
                AddParamToSqlCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 80, ParameterDirection.Input, projectToUpdate.Code);
                AddParamToSqlCmd(sqlCmd, "@SvnRepositoryUrl", SqlDbType.NVarChar, 0, ParameterDirection.Input, projectToUpdate.SvnRepositoryUrl);
                AddParamToSqlCmd(sqlCmd, "@AllowIssueVoting", SqlDbType.Bit, 0, ParameterDirection.Input, projectToUpdate.AllowIssueVoting);
                if (projectToUpdate.Image == null)
                {
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileContent", SqlDbType.Binary, 0, ParameterDirection.Input, DBNull.Value);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileName", SqlDbType.NVarChar, 150, ParameterDirection.Input, DBNull.Value);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageContentType", SqlDbType.NVarChar, 50, ParameterDirection.Input, DBNull.Value);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileSize", SqlDbType.BigInt, 0, ParameterDirection.Input, DBNull.Value);
                }
                else
                {
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileContent", SqlDbType.Binary, 0, ParameterDirection.Input, projectToUpdate.Image.ImageContent);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileName", SqlDbType.NVarChar, 150, ParameterDirection.Input, projectToUpdate.Image.ImageFileName);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageContentType", SqlDbType.NVarChar, 50, ParameterDirection.Input, projectToUpdate.Image.ImageContentType);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileSize", SqlDbType.BigInt, 0, ParameterDirection.Input, projectToUpdate.Image.ImageFileLength);
                }

                SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_PROJECT_UPDATE);
                ExecuteScalarCmd(sqlCmd);
                var returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
                return (returnValue == 0);   
            }
        }
示例#4
0
        /// <summary>
        /// Creates the new project.
        /// </summary>
        /// <param name="newProject">The new project.</param>
        /// <returns></returns>
        public override int CreateNewProject(Project newProject)
        {
            // Validate Parameters
            if (newProject == null) throw (new ArgumentNullException("newProject"));

            using (var sqlCmd = new SqlCommand())
            {
                AddParamToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
                AddParamToSqlCmd(sqlCmd, "@AllowAttachments", SqlDbType.Bit, 0, ParameterDirection.Input, newProject.AllowAttachments);
                AddParamToSqlCmd(sqlCmd, "@ProjectName", SqlDbType.NText, 256, ParameterDirection.Input, newProject.Name);
                AddParamToSqlCmd(sqlCmd, "@ProjectDescription", SqlDbType.NText, 1000, ParameterDirection.Input, newProject.Description);
                AddParamToSqlCmd(sqlCmd, "@ProjectManagerUserName", SqlDbType.NVarChar, 0, ParameterDirection.Input, newProject.ManagerUserName);
                AddParamToSqlCmd(sqlCmd, "@ProjectCreatorUserName", SqlDbType.NText, 255, ParameterDirection.Input, newProject.CreatorUserName);
                AddParamToSqlCmd(sqlCmd, "@ProjectAccessType", SqlDbType.Int, 0, ParameterDirection.Input, newProject.AccessType);
                AddParamToSqlCmd(sqlCmd, "@AttachmentUploadPath", SqlDbType.NVarChar, 80, ParameterDirection.Input, newProject.UploadPath);
                AddParamToSqlCmd(sqlCmd, "@ProjectCode", SqlDbType.NVarChar, 80, ParameterDirection.Input, newProject.Code);
                AddParamToSqlCmd(sqlCmd, "@SvnRepositoryUrl", SqlDbType.NVarChar, 0, ParameterDirection.Input, newProject.SvnRepositoryUrl);
                AddParamToSqlCmd(sqlCmd, "@AllowIssueVoting", SqlDbType.Bit, 0, ParameterDirection.Input, newProject.AllowIssueVoting);
                if (newProject.Image != null)
                {
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileContent", SqlDbType.Binary, 0, ParameterDirection.Input, newProject.Image.ImageContent);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileName", SqlDbType.NVarChar, 150, ParameterDirection.Input, newProject.Image.ImageFileName);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageContentType", SqlDbType.NVarChar, 50, ParameterDirection.Input, newProject.Image.ImageContentType);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileSize", SqlDbType.BigInt, 0, ParameterDirection.Input, newProject.Image.ImageFileLength);
                }
                else
                {
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileContent", SqlDbType.Binary, 0, ParameterDirection.Input, DBNull.Value);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileName", SqlDbType.NVarChar, 150, ParameterDirection.Input, DBNull.Value);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageContentType", SqlDbType.NVarChar, 50, ParameterDirection.Input, DBNull.Value);
                    AddParamToSqlCmd(sqlCmd, "@ProjectImageFileSize", SqlDbType.BigInt, 0, ParameterDirection.Input, DBNull.Value);
                }

                SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_PROJECT_CREATE);
                ExecuteScalarCmd(sqlCmd);
                return ((int)sqlCmd.Parameters["@ReturnValue"].Value);   
            }
        }
示例#5
0
 public abstract bool UpdateProject(Project projectToUpdate);
示例#6
0
 // Project
 public abstract int CreateNewProject(Project newProject);
示例#7
0
 public void setProject(Project proj)
 {
     p = proj;
 }
示例#8
0
 public RandomProjectData(Project proj)
 {
     rng = new Random();
     setProject(proj);
 }
示例#9
0
        /// <summary>
        /// Updates this instance.
        /// </summary>
        /// <returns></returns>
        public bool Update()
        {
            if (Page.IsValid)
            {
                var at = (rblAccessType.SelectedValue == "Public") ? Globals.ProjectAccessType.Public : Globals.ProjectAccessType.Private;
                var attachmentStorageType = (AttachmentStorageType.SelectedValue == "2") ? IssueAttachmentStorageTypes.Database : IssueAttachmentStorageTypes.FileSystem;

                ProjectImage projectImage = null;

                // get the current file
                var uploadFile = ProjectImageUploadFile.PostedFile;

                // if there was a file uploaded
                if (uploadFile.ContentLength > 0)
                {
                    var isFileOk = false;
                    var allowedFileTypes = new string[3] { ".gif", ".png", ".jpg" };
                    var fileExt = Path.GetExtension(uploadFile.FileName);
                    var uploadedFileName = Path.GetFileName(uploadFile.FileName);

                    foreach (var newfileType in allowedFileTypes.Select(fileType => fileType.Substring(fileType.LastIndexOf("."))).Where(newfileType => newfileType.CompareTo(fileExt) == 0))
                    {
                        isFileOk = true;
                    }

                    //file type is not valid
                    if (!isFileOk)
                    {
                        if (Log.IsErrorEnabled) Log.Error(string.Format(LoggingManager.GetErrorMessageResource("InvalidFileType"), uploadedFileName));
                        return false;
                    }

                    //check for illegal filename characters
                    if (uploadedFileName.IndexOfAny(Path.GetInvalidFileNameChars()) != -1)
                    {
                        if (Log.IsErrorEnabled) Log.Error(string.Format(LoggingManager.GetErrorMessageResource("InvalidFileName"), uploadedFileName));
                        return false;
                    }

                    var fileSize = uploadFile.ContentLength;
                    var fileBytes = new byte[fileSize];
                    var myStream = uploadFile.InputStream;
                    myStream.Read(fileBytes, 0, fileSize);

                    projectImage = new ProjectImage(ProjectId, fileBytes, uploadedFileName, fileSize, uploadFile.ContentType);
                }

                var project = new Project
                                      {
                                          AccessType = at,
                                          Name = txtName.Text.Trim(),
                                          Id = ProjectId,
                                          CreatorUserName = Page.User.Identity.Name,
                                          CreatorDisplayName = string.Empty,
                                          Description = ProjectDescriptionHtmlEditor.Text.Trim(),
                                          AllowAttachments = AllowAttachments.Checked,
                                          AllowIssueVoting = chkAllowIssueVoting.Checked,
                                          AttachmentStorageType = attachmentStorageType,
                                          Code = ProjectCode.Text.Trim(),
                                          Disabled = false,
                                          Image = projectImage,
                                          ManagerDisplayName = string.Empty,
                                          ManagerUserName = ProjectManager.SelectedValue,
                                          SvnRepositoryUrl = string.Empty,
                                          UploadPath = txtUploadPath.Text.Trim()
                                      };

                if (BLL.ProjectManager.SaveOrUpdate(project))
                {
                    ProjectId = project.Id;
                    return true;
                }

                lblError.Text = LoggingManager.GetErrorMessageResource("SaveProjectError");
            }

            return false;
        }
示例#10
0
        /// <summary>
        /// Updates the project.
        /// </summary>
        /// <returns></returns>
        private static bool Update(Project entity)
        {
            var p = GetById(entity.Id);

            //if (entity.AttachmentStorageType == IssueAttachmentStorageTypes.FileSystem && p.UploadPath != entity.UploadPath)
            //{
            //    // BGN-1909
            //    // Better santization of Upload Paths
            //    var currentPath = string.Concat("~", Globals.UPLOAD_FOLDER, p.UploadPath.Trim());
            //    var currentFullPath = HttpContext.Current.Server.MapPath(currentPath);

            //    var newPath = string.Concat("~", Globals.UPLOAD_FOLDER, entity.UploadPath.Trim());
            //    var newFullPath = HttpContext.Current.Server.MapPath(newPath);

            //    // WARNING: When editing an invalid path, and trying to make it valid, 
            //    // you will still get an error. This is because the Directory.Move() call 
            //    // can traverse directories! Maybe we should allow the database to change, 
            //    // but not change the file system?
            //    var isPathNorty = !Utilities.CheckUploadPath(currentPath);

            //    if (!Utilities.CheckUploadPath(newPath))
            //        isPathNorty = true;

            //    if (isPathNorty)
            //    {
            //        // something bad is going on. DONT even File.Exist()!!
            //        if (Log.IsErrorEnabled)
            //            Log.Error(string.Format(LoggingManager.GetErrorMessageResource("CouldNotCreateUploadDirectory"), newFullPath));

            //        return false;
            //    }

            //    try
            //    {
            //        // BGN-1878 Upload path not recreated when user fiddles with a project setting
            //        if (File.Exists(currentFullPath))
            //            Directory.Move(currentFullPath, newFullPath);
            //        else
            //            Directory.CreateDirectory(newFullPath);
            //    }
            //    catch (Exception ex)
            //    {
            //        if (Log.IsErrorEnabled)
            //            Log.Error(string.Format(LoggingManager.GetErrorMessageResource("CouldNotCreateUploadDirectory"), newFullPath), ex);
            //        return false;
            //    }
            //}

            return DataProviderManager.Provider.UpdateProject(entity);

        }
示例#11
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));

            entity.UploadPath = Guid.NewGuid().ToString();
            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 (HostSettingManager.Get(HostSettingNames.AttachmentStorageType, 0) == (int)IssueAttachmentStorageTypes.FileSystem)
            {
                var uploadPath = string.Concat(HostSettingManager.Get(HostSettingNames.AttachmentUploadPath), entity.UploadPath);
                if(uploadPath.StartsWith("~"))
                {
                    uploadPath = 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(uploadPath);
                }
                catch (Exception ex)
                {
                    if (Log.IsErrorEnabled)
                        Log.Error(
                            string.Format(
                                LoggingManager.GetErrorMessageResource("CouldNotCreateUploadDirectory"), uploadPath), ex);
                    return false;
                }
            }

            return true;
        }
示例#12
0
        /// <summary>
        /// Page Load Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var s = GetLocalResourceObject("DeleteIssueQuestion").ToString().Trim().JsEncode();
                lnkDelete.Attributes.Add("onclick", string.Format("return confirm('{0}');", s));

                IssueId = Request.QueryString.Get("id", 0);

                // If don't know issue id then redirect to something missing page
                if (IssueId == 0)
                    ErrorRedirector.TransferToSomethingMissingPage(Page);
                
                //set up global properties
                _currentIssue = IssueManager.GetById(IssueId);

                if (_currentIssue == null || _currentIssue.Disabled)
                {
                    ErrorRedirector.TransferToNotFoundPage(Page);
                    return;
                }

                //private issue check
                var issueVisible = IssueManager.CanViewIssue(_currentIssue, Security.GetUserName());

                //private issue check
                if (!issueVisible)
                {
                    ErrorRedirector.TransferToLoginPage(Page);
                }

                _currentProject = ProjectManager.GetById(_currentIssue.ProjectId);

                if (_currentProject == null)
                {
                    ErrorRedirector.TransferToNotFoundPage(Page);
                    return;
                }

                ProjectId = _currentProject.Id;

                if (_currentProject.AccessType == ProjectAccessType.Private && !User.Identity.IsAuthenticated)
                {
                    ErrorRedirector.TransferToLoginPage(Page);
                }
                else if (User.Identity.IsAuthenticated && _currentProject.AccessType == ProjectAccessType.Private 
                    && !ProjectManager.IsUserProjectMember(User.Identity.Name, ProjectId))
                {
                    ErrorRedirector.TransferToLoginPage(Page);
                }

                BindValues(_currentIssue);

                // Page.Title = string.Concat(_currentIssue.FullId, ": ", Server.HtmlDecode(_currentIssue.Title));
                lblIssueNumber.Text = string.Format("{0}-{1}", _currentProject.Code, IssueId);
                ctlIssueTabs.Visible = true;

                SetFieldSecurity();

                if (!_currentProject.AllowIssueVoting)
                { 
                    VoteBox.Visible = false;
                }
          
                //set the referrer url
                if (Request.UrlReferrer != null)
                {
                    if (Request.UrlReferrer.ToString() != Request.Url.ToString())
                        Session["ReferrerUrl"] = Request.UrlReferrer.ToString();
                }
                else
                {
                    Session["ReferrerUrl"] = string.Format("~/Issues/IssueList.aspx?pid={0}", ProjectId);
                }

            }

            Page.Title = string.Concat(lblIssueNumber.Text, ": ", Server.HtmlDecode(TitleTextBox.Text));

            //need to rebind these on every postback because of dynamic controls
            ctlCustomFields.DataSource = CustomFieldManager.GetByIssueId(IssueId);
            ctlCustomFields.DataBind();

            // The ExpandIssuePaths method is called to handle
            // the SiteMapResolve event.
            SiteMap.SiteMapResolve += ExpandIssuePaths;

            ctlIssueTabs.IssueId = IssueId;
            ctlIssueTabs.ProjectId = ProjectId;
        }
示例#13
0
        private string GetMessageContent(Mail_Message mailbody, Project project, out bool isContentHtml, ref List<MIME_Entity> attachments)
        {
            string content = "";
            isContentHtml = false;
            attachments = new List<MIME_Entity>();

            // parse the text content
            if (string.IsNullOrEmpty(mailbody.BodyHtmlText)) // no html must be text
            {
                content = mailbody.BodyText.Replace("\n\r", "<br/>").Replace("\r\n", "<br/>").Replace("\r", "");
                int replyToPos = content.IndexOf("-- WRITE ABOVE THIS LINE TO REPLY --");
                if (replyToPos != -1)
                    content = content.Substring(0, replyToPos);
            }
            else
            {
                //TODO: Enhancements could include regular expressions / string matching or not matching 
                // for particular strings values in the subject or body.
                // strip the <body> out of the message (using code from below)
                var bodyExtractor = new Regex("<body.*?>(?<content>.*)</body>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                var match = bodyExtractor.Match(mailbody.BodyHtmlText);

                var emailContent = match.Success && match.Groups["content"] != null
                    ? match.Groups["content"].Value
                    : mailbody.BodyHtmlText;

                isContentHtml = true;
                content = emailContent.Replace("&lt;", "<").Replace("&gt;", ">");

                content = Regex.Replace(content, "</?o:p>", string.Empty); // Clean MSWord stuff

                int replyToStart = content.IndexOf("<p>-- WRITE ABOVE THIS LINE TO REPLY --</p>");
                int replyToEnd = content.IndexOf("<p>-- WRITE BELOW THIS LINE TO REPLY --</p>");
                if (replyToStart != -1 && replyToEnd != -1)
                    content = content.Substring(0, replyToStart) +
                              content.Substring(replyToEnd + 43);
            }

            // parse attachments
            if (Config.ProcessAttachments && project.AllowAttachments)
            {
                List<MIME_Entity> allAttachs = mailbody.GetAttachments(Config.ProcessInlineAttachedPictures).Where(p => p.ContentType != null).ToList();

                // parse inline images
                for (int i = 0; i < allAttachs.Count; i++)
                {
                    var attachment = allAttachs[i];
                    if (attachment.Body is MIME_b_Image && !string.IsNullOrEmpty(attachment.ContentID))
                    {
                        var inlineKey = "cid:" + attachment.ContentID.Replace("<", "").Replace(">", "");
                        if (content.Contains(inlineKey))
                        {
                            content = content.Replace(inlineKey, ConvertImageToBase64(attachment));
                        }
                        else
                        {
                            attachments.Add(attachment);
                        }
                    }
                    else
                    {
                        attachments.Add(attachment);
                    }
                }
            }

            return content;
        }
示例#14
0
        /// <summary>
        /// Page Load Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lnkDelete.Attributes.Add("onclick", string.Format("return confirm('{0}');", GetLocalResourceObject("DeleteIssue")));
                imgDelete.Attributes.Add("onclick", string.Format("return confirm('{0}');", GetLocalResourceObject("DeleteIssue")));

                IssueId = Request.QueryString.Get("id", 0);
                ProjectId = Request.QueryString.Get("pid", 0);

                // If don't know project or issue then redirect to something missing page
                if (ProjectId == 0 && IssueId == 0)
                    ErrorRedirector.TransferToSomethingMissingPage(Page);

                // Initialize for Adding or Editing
                if (IssueId == 0) // new issue
                {
                    CurrentProject = ProjectManager.GetById(ProjectId);

                    if (CurrentProject == null)
                    {
                        ErrorRedirector.TransferToNotFoundPage(Page);
                    }

                    ProjectId = CurrentProject.Id;

                    //security check: add issue
                    if (!UserManager.HasPermission(ProjectId, Globals.Permission.AddIssue.ToString()))
                    {
                        ErrorRedirector.TransferToLoginPage(Page);
                    }

                    BindOptions();

                    TitleTextBox.Visible = true;
                    DescriptionHtmlEditor.Visible = true;
                    Description.Visible = false;
                    TitleLabel.Visible = false;
                    DisplayTitleLabel.Visible = false;
                    Page.Title = GetLocalResourceObject("PageTitleNewIssue").ToString();
                    lblIssueNumber.Text = GetGlobalResourceObject("SharedResources", "NotAvailableAbbr").ToString();
                    VoteButton.Visible = false;

                    //check users role permission for adding an attachment
                    if (!Page.User.Identity.IsAuthenticated || !UserManager.HasPermission(ProjectId, Globals.Permission.AddAttachment.ToString()))
                    {
                        pnlAddAttachment.Visible = false;
                    }
                    else
                    {
                        pnlAddAttachment.Visible = true;
                    }

                }
                else //existing issue
                {
                    //set up global properties
                    CurrentIssue = IssueManager.GetById(IssueId);

                    if (CurrentIssue == null || CurrentIssue.Disabled)
                    {
                        ErrorRedirector.TransferToNotFoundPage(Page);
                    }

                    //private issue check
                    if (CurrentIssue.Visibility == (int)Globals.IssueVisibility.Private && CurrentIssue.AssignedDisplayName != Security.GetUserName()
                        && CurrentIssue.CreatorDisplayName != Security.GetUserName()
                        && !UserManager.IsInRole(Globals.SUPER_USER_ROLE)
                        && !UserManager.IsInRole(Globals.ProjectAdminRole))
                    {
                        ErrorRedirector.TransferToLoginPage(Page);
                    }

                    CurrentProject = ProjectManager.GetById(CurrentIssue.ProjectId);

                    if (CurrentProject == null)
                    {
                        ErrorRedirector.TransferToNotFoundPage(Page);
                    }
                    else
                    {
                        ProjectId = CurrentProject.Id;
                    }

                    if (CurrentProject.AccessType == Globals.ProjectAccessType.Private && !User.Identity.IsAuthenticated)
                    {
                        ErrorRedirector.TransferToLoginPage(Page);
                    }
                    else if (User.Identity.IsAuthenticated && CurrentProject.AccessType == Globals.ProjectAccessType.Private
                        && !ProjectManager.IsUserProjectMember(User.Identity.Name, ProjectId))
                    {
                        ErrorRedirector.TransferToLoginPage(Page);
                    }

                    IsClosed = CurrentIssue.IsClosed;
                    BindValues(CurrentIssue);

                    Page.Title = string.Concat(CurrentIssue.FullId, ": ", Server.HtmlDecode(CurrentIssue.Title));
                    lblIssueNumber.Text = string.Format("{0}-{1}", CurrentProject.Code, IssueId);
                    ctlIssueTabs.Visible = true;
                    TimeLogged.Visible = true;
                    TimeLoggedLabel.Visible = true;
                    chkNotifyAssignedTo.Visible = false;
                    chkNotifyOwner.Visible = false;

                    SetFieldSecurity();
                }

                if (!CurrentProject.AllowIssueVoting)
                {
                    VoteBox.Visible = false;
                }

                //set the referrer url
                if (Request.UrlReferrer != null)
                {
                    if (Request.UrlReferrer.ToString() != Request.Url.ToString())
                        Session["ReferrerUrl"] = Request.UrlReferrer.ToString();
                }
                else
                {
                    Session["ReferrerUrl"] = string.Format("~/Issues/IssueList.aspx?pid={0}", ProjectId);
                }

            }

            //need to rebind these on every postback because of dynamic controls
            ctlCustomFields.DataSource = IssueId == 0 ?
                CustomFieldManager.GetByProjectId(ProjectId) :
                CustomFieldManager.GetByIssueId(IssueId);

            ctlCustomFields.DataBind();

            // The ExpandIssuePaths method is called to handle
            // the SiteMapResolve event.
            SiteMap.SiteMapResolve += ExpandIssuePaths;

            ctlIssueTabs.IssueId = IssueId;
            ctlIssueTabs.ProjectId = ProjectId;
        }