Beispiel #1
0
        public void CreateRandomIssues()
        {
            List<Project> ps = Project.GetAllProjects();
            if (ps.Count > 0) {

                Project p = ps[0];

                int StartIssueCount = Issue.GetIssuesByProjectId(p.Id).Count;

                RandomProjectData prand = new RandomProjectData(p);

                for (int i = 0; i < CNST_NumIssues; i++)
                {
                    // Get Random yet valid data for the current project
                    Category c = prand.GetCategory();
                    Milestone ms = prand.GetMilestone();
                    Status st = prand.GetStatus();
                    Priority pr = prand.GetPriority();
                    IssueType isst = prand.GetIssueType();
                    Resolution res = prand.GetResolution();

                    string assigned = prand.GetUsername();
                    // creator is also the owner
                    string createdby = prand.GetUsername();

                    Issue iss = new Issue(0, p.Id, RandomStrings.RandomString(30), RandomStrings.RandomString(250), c.Id, pr.Id, st.Id, isst.Id,
                        ms.Id, ms.Id, res.Id,createdby , assigned, createdby, 0, 1, DateTime.MinValue);
                    iss.Save();
                }

                int EndIssueCount = Issue.GetIssuesByProjectId(p.Id).Count;

                // Did we create only CNST_SmallIssues issues?
                Assert.IsTrue(EndIssueCount == StartIssueCount + CNST_NumIssues);
            }
        }
        /// <summary>
        /// Saves the bug.
        /// </summary>
        /// <returns></returns>
        private bool SaveIssue()
        {
            decimal estimation;
            decimal.TryParse(txtEstimation.Text.Trim(), out estimation);
            DateTime dueDate = DueDate.Text.Length > 0 ? DateTime.Parse(DueDate.Text) : DateTime.MinValue;

            bool NewIssue = (IssueId <= 0);

            // 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

            Issue newIssue = new Issue(IssueId, ProjectId, string.Empty, string.Empty, Server.HtmlEncode(TitleTextBox.Text), DescriptionHtmlEditor.Text.Trim(),
                DropCategory.SelectedValue, DropCategory.SelectedText, DropPriority.SelectedValue, DropPriority.SelectedText,
                string.Empty, DropStatus.SelectedValue, DropStatus.SelectedText, string.Empty, DropIssueType.SelectedValue,
                DropIssueType.SelectedText, string.Empty, DropResolution.SelectedValue, DropResolution.SelectedText, string.Empty,
                DropAssignedTo.SelectedText, DropAssignedTo.SelectedValue, Guid.Empty, Security.GetDisplayName(),
                Security.GetUserName(), Guid.Empty, DropOwned.SelectedText, DropOwned.SelectedValue, Guid.Empty, dueDate,
                DropMilestone.SelectedValue, DropMilestone.SelectedText, string.Empty, null, DropAffectedMilestone.SelectedValue, DropAffectedMilestone.SelectedText,
                string.Empty, chkPrivate.Checked == true ? 1 : 0,
                0, estimation, DateTime.MinValue, DateTime.MinValue, Security.GetUserName(), Security.GetDisplayName(),
                Convert.ToInt32(ProgressSlider.Text), false, 0);

            if (!newIssue.Save())
            {
                Message1.ShowErrorMessage("Could not save issue");
                return false;
            }

            IssueId = newIssue.Id;

            if (!CustomField.SaveCustomFieldValues(IssueId, ctlCustomFields.Values))
            {
                Message1.ShowErrorMessage("Could not save issue custom fields");
                return false;
            }

            //if new issue check if notify owner and assigned is checked.
            if (NewIssue)
            {
                //add attachment if present.
                // get the current file
                HttpPostedFile uploadFile = this.AspUploadFile.PostedFile;
                HttpContext context = HttpContext.Current;
                if (uploadFile.ContentLength > 0)
                {
                    IssueAttachment.UploadFile(IssueId, uploadFile, context, AttachmentDescription.Text.Trim());
                }

                //create a vote for the new issue
                IssueVote vote = new IssueVote(IssueId, Security.GetUserName());
                if (!vote.Save())
                    Message1.ShowErrorMessage("Could not save issue vote.");

                if (chkNotifyOwner.Checked)
                {
                    System.Web.Security.MembershipUser oUser = ITUser.GetUser(newIssue.OwnerUserName);
                    if (oUser != null)
                    {
                        IssueNotification notify = new IssueNotification(IssueId, oUser.UserName);
                        notify.Save();
                    }
                }
                if (chkNotifyAssignedTo.Checked && !string.IsNullOrEmpty(newIssue.AssignedUserName))
                {
                    System.Web.Security.MembershipUser oUser = ITUser.GetUser(newIssue.AssignedUserName);
                    if (oUser != null)
                    {
                        IssueNotification notify = new IssueNotification(IssueId, oUser.UserName);
                        notify.Save();
                    }
                }
                IssueNotification.SendIssueAddNotifications(IssueId);
            }

            return true;
        }
        /// <summary>
        /// Handles the Click event of the SaveIssues 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 SaveIssues_Click(object sender, EventArgs e)
        {
            //TODO: Ajax progress bar when this is running;
            string ids = GetSelectedIssueIds();
            if (ids.Length > 0)
            {

                //prune out all values that must not change
                var customFieldValues = ctlCustomFields.Values;
                for (int i = customFieldValues.Count - 1; i >= 0; i--)
                {
                    var value = customFieldValues[i];
                    if (string.IsNullOrEmpty(value.Value))
                    {
                        customFieldValues.RemoveAt(i);
                    }
                }

                foreach (string s in ids.Split(new char[] { ',' }))
                {
                    Issue issue = Issue.GetIssueById(Convert.ToInt32(s));
                    if (issue != null)
                    {
                        DateTime dueDate = DueDate.Text.Length > 0 ? DateTime.Parse(DueDate.Text) : DateTime.MinValue;

                        Issue newIssue = new Issue(issue.Id, issue.ProjectId, string.Empty, string.Empty,issue.Title, issue.Description,
                            dropCategory.SelectedValue != 0 ? dropCategory.SelectedValue : issue.CategoryId, dropCategory.SelectedValue != 0 ? dropCategory.SelectedText : issue.CategoryName,
                            dropPriority.SelectedValue != 0 ? dropPriority.SelectedValue : issue.PriorityId, dropPriority.SelectedValue != 0 ? dropPriority.SelectedText : issue.PriorityName,
                            string.Empty,
                            dropStatus.SelectedValue != 0 ? dropStatus.SelectedValue : issue.StatusId,
                            dropStatus.SelectedValue != 0 ? dropStatus.SelectedText : issue.StatusName, string.Empty,
                            dropType.SelectedValue != 0 ? dropType.SelectedValue : issue.IssueTypeId,
                            dropType.SelectedValue != 0 ? dropType.SelectedText : issue.IssueTypeName, string.Empty,
                            dropResolution.SelectedValue != 0 ? dropResolution.SelectedValue : issue.ResolutionId,
                            dropResolution.SelectedValue != 0 ? dropResolution.SelectedText : issue.ResolutionName, string.Empty,
                            dropAssigned.SelectedValue != string.Empty ? dropAssigned.SelectedText : issue.AssignedDisplayName,
                            dropAssigned.SelectedValue != string.Empty ? dropAssigned.SelectedValue : issue.AssignedUserName,
                            Guid.Empty, Security.GetDisplayName(),Security.GetUserName(), Guid.Empty,
                            dropOwner.SelectedValue !=string.Empty ? dropOwner.SelectedText : issue.OwnerDisplayName,
                            dropOwner.SelectedValue != string.Empty ? dropOwner.SelectedValue : issue.OwnerUserName, Guid.Empty, dueDate != DateTime.MinValue ? dueDate : issue.DueDate,
                            dropMilestone.SelectedValue != 0 ? dropMilestone.SelectedValue : issue.MilestoneId, dropMilestone.SelectedValue != 0 ? dropMilestone.SelectedText : issue.MilestoneName, string.Empty, null,
                            dropAffectedMilestone.SelectedValue != 0 ? dropAffectedMilestone.SelectedValue : issue.AffectedMilestoneId, dropAffectedMilestone.SelectedValue != 0 ? dropAffectedMilestone.SelectedText : issue.AffectedMilestoneName,
                            string.Empty, issue.Visibility,0, issue.Estimation, DateTime.MinValue, DateTime.MinValue, Security.GetUserName(), Security.GetDisplayName(),
                            issue.Progress, false, 0);

                        newIssue.Save();

                        CustomField.SaveCustomFieldValues(issue.Id, customFieldValues);

                    }

                }
            }
            OnRebindCommand(EventArgs.Empty);
        }