Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <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;
            var ids = GetSelectedIssueIds();

            if (ids.Length > 0)
            {
                //prune out all values that must not change
                var customFieldValues = ctlCustomFields.Values;

                for (var i = customFieldValues.Count - 1; i >= 0; i--)
                {
                    var value = customFieldValues[i];
                    if (string.IsNullOrEmpty(value.Value))
                    {
                        customFieldValues.RemoveAt(i);
                    }
                }

                foreach (var s in ids.Split(new[] { ',' }))
                {
                    int issueId;

                    if (!int.TryParse(s, out issueId))
                    {
                        throw new Exception(string.Format(LoggingManager.GetErrorMessageResource("InvalidIssueId"), s));
                    }

                    var issue = IssueManager.GetById(issueId);

                    if (issue == null)
                    {
                        continue;
                    }

                    if (DueDate.SelectedValue != null)
                    {
                        var dueDate = (DateTime)DueDate.SelectedValue;

                        if (dueDate != null)
                        {
                            issue.DueDate = dueDate;
                        }
                    }

                    if (chkDueDateReset.Checked)
                    {
                        issue.DueDate = DateTime.MinValue;
                    }

                    issue.CategoryId   = dropCategory.SelectedValue != 0 ? dropCategory.SelectedValue : issue.CategoryId;
                    issue.CategoryName = dropCategory.SelectedValue != 0 ? dropCategory.SelectedText : issue.CategoryName;

                    issue.MilestoneId   = dropMilestone.SelectedValue != 0 ? dropMilestone.SelectedValue : issue.MilestoneId;
                    issue.MilestoneName = dropMilestone.SelectedValue != 0 ? dropMilestone.SelectedText : issue.MilestoneName;

                    issue.IssueTypeId   = dropType.SelectedValue != 0 ? dropType.SelectedValue : issue.IssueTypeId;
                    issue.IssueTypeName = dropType.SelectedValue != 0 ? dropType.SelectedText : issue.IssueTypeName;

                    issue.PriorityId   = dropPriority.SelectedValue != 0 ? dropPriority.SelectedValue : issue.PriorityId;
                    issue.PriorityName = dropPriority.SelectedValue != 0 ? dropPriority.SelectedText : issue.PriorityName;

                    issue.AssignedDisplayName = dropAssigned.SelectedValue != string.Empty ? dropAssigned.SelectedText : issue.AssignedDisplayName;
                    issue.AssignedUserName    = dropAssigned.SelectedValue != string.Empty ? dropAssigned.SelectedValue : issue.AssignedUserName;

                    issue.OwnerDisplayName = dropOwner.SelectedValue != string.Empty ? dropOwner.SelectedText : issue.OwnerDisplayName;
                    issue.OwnerUserName    = dropOwner.SelectedValue != string.Empty ? dropOwner.SelectedValue : issue.OwnerUserName;

                    issue.AffectedMilestoneId   = dropAffectedMilestone.SelectedValue != 0 ? dropAffectedMilestone.SelectedValue : issue.AffectedMilestoneId;
                    issue.AffectedMilestoneName = dropAffectedMilestone.SelectedValue != 0 ? dropAffectedMilestone.SelectedText : issue.AffectedMilestoneName;

                    issue.ResolutionId   = dropResolution.SelectedValue != 0 ? dropResolution.SelectedValue : issue.ResolutionId;
                    issue.ResolutionName = dropResolution.SelectedValue != 0 ? dropResolution.SelectedText : issue.ResolutionName;

                    issue.StatusId   = dropStatus.SelectedValue != 0 ? dropStatus.SelectedValue : issue.StatusId;
                    issue.StatusName = dropStatus.SelectedValue != 0 ? dropStatus.SelectedText : issue.StatusName;

                    issue.LastUpdateDisplayName = Security.GetDisplayName();
                    issue.LastUpdateUserName    = Security.GetUserName();
                    issue.LastUpdate            = DateTime.Now;

                    IssueManager.SaveOrUpdate(issue);
                    CustomFieldManager.SaveCustomFieldValues(issue.Id, customFieldValues);
                }
            }

            OnRebindCommand(EventArgs.Empty);
        }
Ejemplo n.º 3
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);
        }