Пример #1
0
        /// <summary>
        /// This method executes a query and displays the results.
        /// </summary>
        void ExecuteQuery()
        {
            var queryClauses = BuildQuery();

            if (queryClauses.Count > 0)
            {
                try
                {
                    var sortColumns = new List <KeyValuePair <string, string> >();

                    var sorter = ctlDisplayIssues.SortString;

                    if (sorter.Trim().Length.Equals(0))
                    {
                        sorter = "iv.[IssueId] DESC";
                    }

                    foreach (var sort in sorter.Split(','))
                    {
                        var args = sort.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                        if (args.Length.Equals(2))
                        {
                            sortColumns.Add(new KeyValuePair <string, string>(args[0], args[1]));
                        }
                    }

                    // add the disabled query filter since the UI cannot add this
                    queryClauses.Insert(0, new QueryClause("AND", "iv.[Disabled]", "=", "0", SqlDbType.Int));

                    var colIssues = IssueManager.PerformQuery(queryClauses, sortColumns, ProjectId);
                    ctlDisplayIssues.DataSource = colIssues;
                    Results.Visible             = true;
                    ctlDisplayIssues.DataBind();
                }
                catch
                {
                    Message1.ShowErrorMessage(GetLocalResourceObject("RunQueryError").ToString());
                }
            }
            else
            {
                Message1.ShowWarningMessage(GetLocalResourceObject("SelectOneQueryClause").ToString());
            }
        }
Пример #2
0
        /// <summary>
        /// This method is called when a user clicks the Save Query button.
        /// The method saves the query to a database table.
        /// </summary>
        void SaveQuery()
        {
            if (!Page.IsValid)
            {
                return;
            }

            var queryName = txtQueryName.Text.Trim();
            var userName  = Security.GetUserName();

            if (queryName == String.Empty)
            {
                return;
            }

            var queryClauses = BuildQuery();

            if (queryClauses.Count == 0)
            {
                return;
            }

            var query = new Query
            {
                Id       = _queryId,
                Name     = queryName,
                IsPublic = chkGlobalQuery.Checked,
                Clauses  = queryClauses
            };

            var success = QueryManager.SaveOrUpdate(userName, ProjectId, query);

            if (success)
            {
                Response.Redirect(string.Format("QueryList.aspx?pid={0}", ProjectId));
            }
            else
            {
                Message1.ShowErrorMessage(GetLocalResourceObject("SaveQueryError").ToString());
            }
        }
Пример #3
0
        /// <summary>
        /// Handles the Click event of the SaveButton control.
        /// </summary>
        /// <param name="s">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void SaveButton_Click(object s, EventArgs e)
        {
            var membershipUser = UserManager.GetUser(User.Identity.Name);

            membershipUser.Email           = Email.Text;
            WebProfile.Current.FirstName   = FirstName.Text;
            WebProfile.Current.LastName    = LastName.Text;
            WebProfile.Current.DisplayName = FullName.Text;

            try
            {
                WebProfile.Current.Save();
                Membership.UpdateUser(membershipUser);

                Message1.ShowSuccessMessage(GetLocalResourceObject("ProfileSaved").ToString());

                if (Log.IsInfoEnabled)
                {
                    if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        MDC.Set("user", HttpContext.Current.User.Identity.Name);
                    }
                    Log.Info("Profile updated");
                }
            }
            catch (Exception ex)
            {
                if (Log.IsErrorEnabled)
                {
                    if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        MDC.Set("user", HttpContext.Current.User.Identity.Name);
                    }
                    Log.Error("Profile update error", ex);
                }

                Message1.ShowErrorMessage(GetLocalResourceObject("ProfileUpdateError").ToString());
            }
        }
Пример #4
0
        /// <summary>
        /// Saves the issue.
        /// </summary>
        /// <returns></returns>
        private bool SaveIssue()
        {
            decimal estimation;

            decimal.TryParse(txtEstimation.Text.Trim(), out estimation);
            var dueDate = DueDatePicker.SelectedValue == null ? DateTime.MinValue : (DateTime)DueDatePicker.SelectedValue;

            // WARNING: DO NOT ENCODE THE HTMLEDITOR TEXT.
            // It expects raw input. So pass through a raw string.
            // This is a potential XSS vector as the Issue Class should
            // handle sanitizing the input and checking that its input is HtmlEncoded
            // (ie no < or > characters), not the IssueDetail.aspx.cs

            var issue = new Issue
            {
                AffectedMilestoneId       = DropAffectedMilestone.SelectedValue,
                AffectedMilestoneImageUrl = string.Empty,
                AffectedMilestoneName     = DropAffectedMilestone.SelectedText,
                AssignedDisplayName       = DropAssignedTo.SelectedText,
                AssignedUserId            = Guid.Empty,
                AssignedUserName          = DropAssignedTo.SelectedValue,
                CategoryId         = DropCategory.SelectedValue,
                CategoryName       = DropCategory.SelectedText,
                CreatorDisplayName = Security.GetDisplayName(),
                CreatorUserId      = Guid.Empty,
                CreatorUserName    = Security.GetUserName(),
                DateCreated        = DateTime.Now,
                Description        = DescriptionHtmlEditor.Text.Trim(),
                Disabled           = false,
                DueDate            = dueDate,
                Estimation         = estimation,
                Id                    = IssueId,
                IsClosed              = false,
                IssueTypeId           = DropIssueType.SelectedValue,
                IssueTypeName         = DropIssueType.SelectedText,
                IssueTypeImageUrl     = string.Empty,
                LastUpdate            = DateTime.Now,
                LastUpdateDisplayName = Security.GetDisplayName(),
                LastUpdateUserName    = Security.GetUserName(),
                MilestoneDueDate      = null,
                MilestoneId           = DropMilestone.SelectedValue,
                MilestoneImageUrl     = string.Empty,
                MilestoneName         = DropMilestone.SelectedText,
                OwnerDisplayName      = DropOwned.SelectedText,
                OwnerUserId           = Guid.Empty,
                OwnerUserName         = DropOwned.SelectedValue,
                PriorityId            = DropPriority.SelectedValue,
                PriorityImageUrl      = string.Empty,
                PriorityName          = DropPriority.SelectedText,
                Progress              = Convert.ToInt32(ProgressSlider.Text),
                ProjectCode           = string.Empty,
                ProjectId             = ProjectId,
                ProjectName           = string.Empty,
                ResolutionId          = DropResolution.SelectedValue,
                ResolutionImageUrl    = string.Empty,
                ResolutionName        = DropResolution.SelectedText,
                StatusId              = DropStatus.SelectedValue,
                StatusImageUrl        = string.Empty,
                StatusName            = DropStatus.SelectedText,
                Title                 = Server.HtmlEncode(TitleTextBox.Text),
                TimeLogged            = 0,
                Visibility            = chkPrivate.Checked ? 1 : 0,
                Votes                 = 0
            };

            if (!IssueManager.SaveOrUpdate(issue))
            {
                Message1.ShowErrorMessage(Resources.Exceptions.SaveIssueError);
                return(false);
            }

            IssueId = issue.Id;

            if (!CustomFieldManager.SaveCustomFieldValues(IssueId, ctlCustomFields.Values))
            {
                Message1.ShowErrorMessage(Resources.Exceptions.SaveCustomFieldValuesError);
                return(false);
            }

            return(true);
        }
Пример #5
0
        /// <summary>
        /// Handles the Click event of the OkButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void OkButton_Click(object sender, EventArgs e)
        {
            var oldCategoryId = 0;

            if (!string.IsNullOrEmpty(HiddenField1.Value))
            {
                oldCategoryId = Convert.ToInt32(HiddenField1.Value);
            }

            if (oldCategoryId != 0)
            {
                var queryClauses = new List <QueryClause>
                {
                    new QueryClause("AND", "iv.[IssueCategoryId]", "=", HiddenField1.Value, SqlDbType.Int)
                };

                var issues = IssueManager.PerformQuery(queryClauses, null, ProjectId);

                if (RadioButton1.Checked) //delete category
                {
                    //if (RecursiveDelete.Checked == true)
                    //Category.DeleteChildCategoriesByCategoryId(OldCategoryId);
                    //delete the category.
                    CategoryManager.Delete(oldCategoryId);
                }

                if (RadioButton2.Checked) //reassign issues to existing category.
                {
                    if (DropCategory.SelectedValue == 0)
                    {
                        Message1.ShowErrorMessage(GetLocalResourceObject("NoCategorySelected").ToString());
                        return;
                    }
                    if (oldCategoryId == DropCategory.SelectedValue)
                    {
                        Message1.ShowErrorMessage(GetLocalResourceObject("SameCategorySelected").ToString());
                        return;
                    }

                    foreach (var issue in issues)
                    {
                        issue.CategoryName = DropCategory.SelectedText;
                        issue.CategoryId   = DropCategory.SelectedValue;
                        IssueManager.SaveOrUpdate(issue);
                    }

                    //delete the category.
                    CategoryManager.Delete(oldCategoryId);
                }

                //assign new category
                if (RadioButton3.Checked)
                {
                    if (string.IsNullOrEmpty(NewCategoryTextBox.Text))
                    {
                        Message1.ShowErrorMessage(GetLocalResourceObject("NewCategoryNotEntered").ToString());
                        return;
                    }
                    var c = new Category {
                        ProjectId = ProjectId, ParentCategoryId = 0, Name = NewCategoryTextBox.Text, ChildCount = 0
                    };
                    CategoryManager.SaveOrUpdate(c);
                    foreach (var issue in issues)
                    {
                        issue.CategoryName = NewCategoryTextBox.Text;
                        issue.CategoryId   = c.Id;
                        IssueManager.SaveOrUpdate(issue);
                    }
                    //delete the category.
                    CategoryManager.Delete(oldCategoryId);
                }
            }
            else
            {
                Message1.ShowErrorMessage(GetLocalResourceObject("CannotDeleteRootCategory").ToString());
            }
        }
Пример #6
0
        /// <summary>
        /// Saves the issue.
        /// </summary>
        /// <returns></returns>
        private bool SaveIssue()
        {
            decimal estimation;

            decimal.TryParse(txtEstimation.Text.Trim(), out estimation);
            var dueDate = DueDatePicker.SelectedValue ?? DateTime.MinValue;

            var issue = new Issue
            {
                AffectedMilestoneId       = DropAffectedMilestone.SelectedValue,
                AffectedMilestoneImageUrl = string.Empty,
                AffectedMilestoneName     = DropAffectedMilestone.SelectedText,
                AssignedDisplayName       = DropAssignedTo.SelectedText,
                AssignedUserId            = Guid.Empty,
                AssignedUserName          = DropAssignedTo.SelectedValue,
                CategoryId         = DropCategory.SelectedValue,
                CategoryName       = DropCategory.SelectedText,
                CreatorDisplayName = Security.GetDisplayName(),
                CreatorUserId      = Guid.Empty,
                CreatorUserName    = Security.GetUserName(),
                DateCreated        = DateTime.Now,
                Description        = DescriptionHtmlEditor.Text.Trim(),
                Disabled           = false,
                DueDate            = dueDate,
                Estimation         = estimation,
                Id                    = 0,
                IsClosed              = false,
                IssueTypeId           = DropIssueType.SelectedValue,
                IssueTypeName         = DropIssueType.SelectedText,
                IssueTypeImageUrl     = string.Empty,
                LastUpdate            = DateTime.Now,
                LastUpdateDisplayName = Security.GetDisplayName(),
                LastUpdateUserName    = Security.GetUserName(),
                MilestoneDueDate      = null,
                MilestoneId           = DropMilestone.SelectedValue,
                MilestoneImageUrl     = string.Empty,
                MilestoneName         = DropMilestone.SelectedText,
                OwnerDisplayName      = DropOwned.SelectedText,
                OwnerUserId           = Guid.Empty,
                OwnerUserName         = DropOwned.SelectedValue,
                PriorityId            = DropPriority.SelectedValue,
                PriorityImageUrl      = string.Empty,
                PriorityName          = DropPriority.SelectedText,
                Progress              = Convert.ToInt32(ProgressSlider.Text),
                ProjectCode           = string.Empty,
                ProjectId             = ProjectId,
                ProjectName           = string.Empty,
                ResolutionId          = DropResolution.SelectedValue,
                ResolutionImageUrl    = string.Empty,
                ResolutionName        = DropResolution.SelectedText,
                StatusId              = DropStatus.SelectedValue,
                StatusImageUrl        = string.Empty,
                StatusName            = DropStatus.SelectedText,
                Title                 = Server.HtmlEncode(TitleTextBox.Text),
                TimeLogged            = 0,
                Visibility            = chkPrivate.Checked ? 1 : 0,
                Votes                 = 0
            };

            if (!IssueManager.SaveOrUpdate(issue))
            {
                Message1.ShowErrorMessage(Resources.Exceptions.SaveIssueError);
                return(false);
            }

            if (!CustomFieldManager.SaveCustomFieldValues(issue.Id, ctlCustomFields.Values, true))
            {
                Message1.ShowErrorMessage(Resources.Exceptions.SaveCustomFieldValuesError);
                return(false);
            }

            IssueId = issue.Id;

            //add attachment if present.
            if (AspUploadFile.HasFile)
            {
                // get the current file
                var    uploadFile = AspUploadFile.PostedFile;
                string inValidReason;
                var    validFile = IssueAttachmentManager.IsValidFile(uploadFile.FileName, out inValidReason);

                if (validFile)
                {
                    if (uploadFile.ContentLength > 0)
                    {
                        byte[] fileBytes;
                        using (var input = uploadFile.InputStream)
                        {
                            fileBytes = new byte[uploadFile.ContentLength];
                            input.Read(fileBytes, 0, uploadFile.ContentLength);
                        }

                        var issueAttachment = new IssueAttachment
                        {
                            Id                 = Globals.NEW_ID,
                            Attachment         = fileBytes,
                            Description        = AttachmentDescription.Text.Trim(),
                            DateCreated        = DateTime.Now,
                            ContentType        = uploadFile.ContentType,
                            CreatorDisplayName = string.Empty,
                            CreatorUserName    = Security.GetUserName(),
                            FileName           = uploadFile.FileName,
                            IssueId            = issue.Id,
                            Size               = fileBytes.Length
                        };

                        if (!IssueAttachmentManager.SaveOrUpdate(issueAttachment))
                        {
                            Message1.ShowErrorMessage(string.Format(GetGlobalResourceObject("Exceptions", "SaveAttachmentError").ToString(), uploadFile.FileName));
                        }
                    }
                }
                else
                {
                    Message1.ShowErrorMessage(inValidReason);
                    return(false);
                }
            }

            //create a vote for the new issue
            var vote = new IssueVote {
                IssueId = issue.Id, VoteUsername = Security.GetUserName()
            };

            if (!IssueVoteManager.SaveOrUpdate(vote))
            {
                Message1.ShowErrorMessage(Resources.Exceptions.SaveIssueVoteError);
                return(false);
            }

            if (chkNotifyOwner.Checked && !string.IsNullOrEmpty(issue.OwnerUserName))
            {
                var oUser = UserManager.GetUser(issue.OwnerUserName);
                if (oUser != null)
                {
                    var notify = new IssueNotification {
                        IssueId = issue.Id, NotificationUsername = oUser.UserName
                    };
                    IssueNotificationManager.SaveOrUpdate(notify);
                }
            }
            if (chkNotifyAssignedTo.Checked && !string.IsNullOrEmpty(issue.AssignedUserName))
            {
                var oUser = UserManager.GetUser(issue.AssignedUserName);
                if (oUser != null)
                {
                    var notify = new IssueNotification {
                        IssueId = issue.Id, NotificationUsername = oUser.UserName
                    };
                    IssueNotificationManager.SaveOrUpdate(notify);
                }
            }

            //send issue notifications
            IssueNotificationManager.SendIssueAddNotifications(issue.Id);

            return(true);
        }