public ActionResult GetCustomFieldValue(string term, string cf)
        {
            var             cfId = IssueFieldsHelper.GetChosenCustomFieldDetails(cf);
            List <ListItem> data = new List <ListItem>();

            if (cfId == 0)
            {
                if (cf.StartsWith("pgpicker", StringComparison.InvariantCultureIgnoreCase))
                {
                    int groupId = Convert.ToInt32(cf.Substring(cf.IndexOf("__") + 2, cf.Length - "PGPICKER___chosen".Length));

                    ProjectGroup group = Cache.ProjectGroups.Get(groupId);

                    List <ProjectGroupMembership> allMembers = new List <ProjectGroupMembership>(group.MembersForProject(null));

                    var users = UserManager.Convert(Cache.Users.FindAll(u => u.Active &&
                                                                        u.Id != Countersoft.Gemini.Commons.Constants.SystemAccountUserId &&
                                                                        u.Fullname.Contains(term, StringComparison.InvariantCultureIgnoreCase) &&
                                                                        !allMembers.Any(s => s.UserId == u.Id))
                                                    .Take(100).ToList());
                    data.AddRange(UserManager.ToListItem(users, new List <int>()));
                }

                return(JsonSuccess(data));
            }

            data.AddRange(CustomFieldManager.GetCustomFieldLookUp(cfId, CurrentProject.Entity.Id == 0 ? null : new int?(CurrentProject.Entity.Id), term, 100, CurrentIssue));

            return(JsonSuccess(data));
        }
        /// <summary>
        /// Handles the Click event of the lnkAddCustomField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void lnkAddCustomField_Click(object sender, EventArgs e)
        {
            var newName = txtName.Text.Trim();

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

            var dataType  = (ValidationDataType)Enum.Parse(typeof(ValidationDataType), dropDataType.SelectedValue);
            var fieldType = (CustomFieldType)Enum.Parse(typeof(CustomFieldType), rblCustomFieldType.SelectedValue);
            var required  = chkRequired.Checked;

            var newCustomField = new CustomField
            {
                ProjectId = ProjectId,
                Name      = newName,
                DataType  = dataType,
                Required  = required,
                FieldType = fieldType
            };

            if (CustomFieldManager.SaveOrUpdate(newCustomField))
            {
                txtName.Text = "";
                dropDataType.SelectedIndex = 0;
                chkRequired.Checked        = false;
                BindCustomFields();
            }
            else
            {
                lblError.Text = LoggingManager.GetErrorMessageResource("SaveCustomFieldError");
            }
        }
Beispiel #3
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;
        }
        /// <summary>
        /// Binds the custom fields.
        /// </summary>
        private void BindCustomFields()
        {
            //check if we are editing the sub grid - needed to fire update command on the nested grid.
            if (ViewState["EditingSubGrid"] == null)
            {
                grdCustomFields.DataSource   = CustomFieldManager.GetByProjectId(ProjectId);
                grdCustomFields.DataKeyField = "Id";
                grdCustomFields.DataBind();

                grdCustomFields.Visible = grdCustomFields.Items.Count != 0;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Handles the PreRender event of the Page 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 Page_PreRender(object sender, EventArgs e)
        {
            //hide votes column if issue voting is disabled
            if (!ProjectManager.GetById(ProjectId).AllowIssueVoting)
            {
                dropField.Items.Remove(dropField.Items.FindByValue("IssueVotes"));
            }

            if (CustomFieldManager.GetByProjectId(ProjectId).Count == 0)
            {
                dropField.Items.Remove("CustomFieldName");
            }
        }
        protected void btnDeleteCustomField_Click(object sender, ImageClickEventArgs e)
        {
            var btn = sender as ImageButton;

            if (btn == null)
            {
                return;
            }

            var id = btn.CommandArgument.To <int>();

            if (!CustomFieldManager.Delete(id))
            {
                lblError.Text = LoggingManager.GetErrorMessageResource("DeleteCustomFieldError");
            }
            else
            {
                BindCustomFields();
            }
        }
        /// <summary>
        /// Handles the Update event of the grdCustomFields control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void grdCustomFields_Update(object sender, DataGridCommandEventArgs e)
        {
            var cf = CustomFieldManager.GetById(Convert.ToInt32(grdCustomFields.DataKeys[e.Item.ItemIndex]));
            var txtCustomFieldName = (TextBox)e.Item.FindControl("txtCustomFieldName");
            var customFieldType    = (DropDownList)e.Item.FindControl("dropCustomFieldType");
            var dataType           = (DropDownList)e.Item.FindControl("dropEditDataType");
            var required           = (CheckBox)e.Item.FindControl("chkEditRequired");

            cf.Name = txtCustomFieldName.Text;

            var DataType  = (ValidationDataType)Enum.Parse(typeof(ValidationDataType), dataType.SelectedValue);
            var FieldType = (CustomFieldType)Enum.Parse(typeof(CustomFieldType), customFieldType.SelectedValue);

            cf.FieldType = FieldType;
            cf.DataType  = DataType;
            cf.Required  = required.Checked;
            CustomFieldManager.SaveOrUpdate(cf);

            grdCustomFields.EditItemIndex = -1;
            BindCustomFields();
        }
Beispiel #8
0
        /// <summary>
        /// When the user changes the selected field type, show the corresponding list
        /// of possible values.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void dropFieldSelectedIndexChanged(Object s, EventArgs e)
        {
            dropValue.Items.Clear();

            dropValue.Visible = false;
            txtValue.Visible  = false;
            DateValue.Visible = false;

            switch (dropField.SelectedValue)
            {
            case "IssueId":
            case "IssueTitle":
            case "IssueDescription":
            case "IssueVotes":
            case "IssueProgress":
            case "IssueEstimation":
            case "TimeLogged":
                txtValue.Visible = true;
                break;

            case "IssuePriorityId":
                dropValue.Visible = true;

                dropValue.DataSource     = PriorityManager.GetByProjectId(ProjectId);
                dropValue.DataTextField  = "Name";
                dropValue.DataValueField = "Id";
                break;

            case "IssueTypeId":
                dropValue.Visible = true;

                dropValue.DataSource     = IssueTypeManager.GetByProjectId(ProjectId);
                dropValue.DataTextField  = "Name";
                dropValue.DataValueField = "Id";
                break;

            case "IssueMilestoneId":
                dropValue.Visible = true;

                dropValue.DataSource     = MilestoneManager.GetByProjectId(ProjectId);
                dropValue.DataTextField  = "Name";
                dropValue.DataValueField = "Id";
                break;

            case "IssueAffectedMilestoneId":
                dropValue.Visible = true;

                dropValue.DataSource     = MilestoneManager.GetByProjectId(ProjectId);
                dropValue.DataTextField  = "Name";
                dropValue.DataValueField = "Id";
                break;

            case "IssueResolutionId":
                dropValue.Visible = true;

                dropValue.DataSource     = ResolutionManager.GetByProjectId(ProjectId);
                dropValue.DataTextField  = "Name";
                dropValue.DataValueField = "Id";
                break;

            case "IssueCategoryId":
                dropValue.Visible = true;

                var objCats = new CategoryTree();
                dropValue.DataSource     = objCats.GetCategoryTreeByProjectId(ProjectId);
                dropValue.DataTextField  = "Name";
                dropValue.DataValueField = "Id";

                break;

            case "IssueStatusId":
                dropValue.Visible = true;

                dropValue.DataSource     = StatusManager.GetByProjectId(ProjectId);
                dropValue.DataTextField  = "Name";
                dropValue.DataValueField = "Id";
                break;

            case "IssueAssignedUserId":
                dropValue.Visible = true;

                dropValue.DataSource     = UserManager.GetUsersByProjectId(ProjectId);
                dropValue.DataTextField  = "DisplayName";
                dropValue.DataValueField = "Id";
                break;

            case "IssueOwnerUserId":
                dropValue.Visible        = true;
                txtValue.Visible         = false;
                dropValue.DataSource     = UserManager.GetUsersByProjectId(ProjectId);
                dropValue.DataTextField  = "DisplayName";
                dropValue.DataValueField = "Id";
                break;

            case "IssueCreatorUserId":
                dropValue.Visible = true;

                dropValue.DataSource     = UserManager.GetUsersByProjectId(ProjectId);
                dropValue.DataTextField  = "DisplayName";
                dropValue.DataValueField = "Id";
                break;

            case "DateCreatedAsDate":
            case "LastUpdateAsDate":
            case "IssueDueDate":
                DateValue.Visible = true;
                break;

            case "CustomFieldName":

                dropValue.Visible   = false;
                txtValue.Visible    = true;   //show the text value field. Not needed.
                CustomFieldSelected = true;

                if (CustomFieldManager.GetByProjectId(ProjectId).Count > 0)
                {
                    dropField.DataSource     = CustomFieldManager.GetByProjectId(ProjectId);
                    dropField.DataTextField  = "Name";
                    dropField.DataValueField = "Name";
                    dropField.DataBind();    // bind to the new data source.
                    dropField.Items.Add(GetGlobalResourceObject("SharedResources", "DropDown_ResetFields").ToString());
                    dropField.Items.Insert(0, new ListItem(GetGlobalResourceObject("SharedResources", "DropDown_SelectCustomField").ToString(), "0"));
                }
                break;

            default:
                if (dropField.SelectedItem.Text.Equals(GetGlobalResourceObject("SharedResources", "DropDown_SelectCustomField").ToString()))
                {
                    return;
                }

                // The user decides to reset the fields
                if (dropField.SelectedItem.Text.Equals(GetGlobalResourceObject("SharedResources", "DropDown_ResetFields").ToString()))
                {
                    dropField.DataSource     = null;
                    dropField.DataSource     = RequiredFieldManager.GetRequiredFields();
                    dropField.DataTextField  = "Name";
                    dropField.DataValueField = "Value";
                    dropField.DataBind();
                }

                //RW Once the list is populated with any varying type of name,
                //we just default to this case, because we know it is not a standard field.
                else
                {
                    //check the type of this custom field and load the appropriate values.
                    var cf = CustomFieldManager.GetByProjectId(ProjectId).Find(c => c.Name == dropField.SelectedValue);

                    if (cf == null)
                    {
                        return;
                    }

                    CustomFieldSelected = true;
                    CustomFieldId       = cf.Id;
                    CustomFieldDataType = cf.DataType;

                    switch (cf.FieldType)
                    {
                    case CustomFieldType.DropDownList:
                        dropValue.Visible        = true;
                        dropValue.DataSource     = CustomFieldSelectionManager.GetByCustomFieldId(cf.Id);
                        dropValue.DataTextField  = "Name";
                        dropValue.DataValueField = "Value";
                        break;

                    case CustomFieldType.Date:
                        DateValue.Visible = true;
                        break;

                    case CustomFieldType.YesNo:
                        dropValue.Visible = true;
                        dropValue.Items.Add(new ListItem(GetGlobalResourceObject("SharedResources", "DropDown_SelectOne").ToString()));
                        dropValue.Items.Add(new ListItem(GetGlobalResourceObject("SharedResources", "Yes").ToString(), Boolean.TrueString));
                        dropValue.Items.Add(new ListItem(GetGlobalResourceObject("SharedResources", "No").ToString(), Boolean.FalseString));
                        break;

                    default:
                        txtValue.Visible = true;
                        break;
                    }
                }
                break;
            }
            try
            {
                dropValue.DataBind();
            }
            catch { }
        }
Beispiel #9
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);
        }
Beispiel #10
0
        /// <summary>
        /// Binds a data source to the invoked server control and all its child controls.
        /// </summary>
        public new void DataBind()
        {
            //Private issue check
            DataSource = IssueManager.StripPrivateIssuesForRequestor(DataSource, Security.GetUserName()).ToList();

            if (DataSource.Count > 0)
            {
                gvIssues.Visible              = true;
                pager.Visible                 = true;
                ScrollPanel.Visible           = true;
                OptionsContainerPanel.Visible = true;

                var pId = Request.QueryString.Get("pid", -1);

                //get custom fields for project
                if (pId > Globals.NEW_ID)
                {
                    var customFields = CustomFieldManager.GetByProjectId(pId);

                    var nrColumns = FIXED_COLUMNS;
                    //checks if its initial load to add custom controls and checkboxes
                    if (gvIssues.Columns.Count <= nrColumns + 1)
                    {
                        var firstIssue = DataSource[0];

                        //if there is custom fields add them
                        if (firstIssue.IssueCustomFields.Count > 0)
                        {
                            foreach (var value in firstIssue.IssueCustomFields)
                            {
                                //increments nr of columns
                                nrColumns++;

                                //create checkbox item
                                var lstValue = new ListItem(value.FieldName, nrColumns.ToString());

                                //find custom controls that has been checked and check them
                                var selected = Array.IndexOf(_arrIssueColumns, nrColumns.ToString()) >= 0;
                                if (selected)
                                {
                                    lstValue.Selected = true;
                                }

                                //add item to checkbox list
                                lstIssueColumns.Items.Add(lstValue);

                                //create column for custom control
                                var tf = new TemplateField {
                                    HeaderText = value.FieldName, SortExpression = value.DatabaseFieldName.Replace(" ", "[]")
                                };
                                tf.HeaderStyle.Wrap = false;
                                gvIssues.Columns.Add(tf);
                            }
                        }
                    }
                }

                DisplayColumns();
                SelectColumnsPanel.Visible = true;
                lblResults.Visible         = false;

                if (ShowProjectColumn)
                {
                    gvIssues.Columns[0].Visible      = false;
                    LeftButtonContainerPanel.Visible = false;
                }
                else
                {
                    gvIssues.Columns[4].Visible = false;
                    lstIssueColumns.Items.Remove(lstIssueColumns.Items.FindByValue("4"));

                    var projectId = _dataSource[0].ProjectId;

                    //hide votes column if issue voting is disabled
                    if (!ProjectManager.GetById(projectId).AllowIssueVoting)
                    {
                        gvIssues.Columns[4].Visible = false;
                        lstIssueColumns.Items.Remove(lstIssueColumns.Items.FindByValue("4"));
                    }

                    if (Page.User.Identity.IsAuthenticated && UserManager.HasPermission(projectId, Common.Permission.EditIssue.ToString()))
                    {
                        LeftButtonContainerPanel.Visible = true;

                        // performance enhancement
                        // WRH 2012-04-06
                        // only load these if the user has permission to do so
                        var categories = new CategoryTree();
                        dropCategory.DataSource = categories.GetCategoryTreeByProjectId(projectId);
                        dropCategory.DataBind();
                        dropMilestone.DataSource = MilestoneManager.GetByProjectId(projectId);
                        dropMilestone.DataBind();
                        dropAffectedMilestone.DataSource = dropMilestone.DataSource;
                        dropAffectedMilestone.DataBind();
                        dropOwner.DataSource = UserManager.GetUsersByProjectId(projectId);
                        dropOwner.DataBind();
                        dropPriority.DataSource = PriorityManager.GetByProjectId(projectId);
                        dropPriority.DataBind();
                        dropStatus.DataSource = StatusManager.GetByProjectId(projectId);
                        dropStatus.DataBind();
                        dropType.DataSource = IssueTypeManager.GetByProjectId(projectId);
                        dropType.DataBind();
                        dropAssigned.DataSource = UserManager.GetUsersByProjectId(projectId);
                        dropAssigned.DataBind();
                        dropResolution.DataSource = ResolutionManager.GetByProjectId(projectId);
                        dropResolution.DataBind();
                        chkDueDateReset.Checked = false;
                    }
                    else
                    {
                        //hide selection column for unauthenticated users
                        gvIssues.Columns[0].Visible      = false;
                        LeftButtonContainerPanel.Visible = false;
                    }
                }

                foreach (var item in _arrIssueColumns.Select(colIndex => lstIssueColumns.Items.FindByValue(colIndex)).Where(item => item != null))
                {
                    item.Selected = true;
                }

                gvIssues.DataSource = DataSource;
                gvIssues.DataBind();
            }
            else
            {
                ScrollPanel.Visible           = false;
                OptionsContainerPanel.Visible = false;
                lblResults.Visible            = true;
                gvIssues.Visible = false;
                pager.Visible    = false;
            }
        }
        public ActionResult Create(string startDate, string endDate, int itemId)
        {
            DateTime?startDateTime = ParseDateString.GetDateForString(startDate);
            DateTime?endDateTime   = ParseDateString.GetDateForString(endDate);

            if (startDateTime == null || endDateTime == null || endDateTime < startDateTime)
            {
                return(JsonError("Make sure Start Date and End Date are valid dates"));
            }

            //If selection range is bigger than 3 years set the last date to max 3 years
            if (((endDateTime.Value - DateTime.Today).TotalDays / 365) > 3)
            {
                endDateTime = DateTime.Today.AddYears(3);

                if (startDateTime > endDateTime)
                {
                    startDateTime = endDateTime;
                }
            }

            var closedStatuses = MetaManager.StatusGetClosed();

            List <IssueLinkType> linkTypes        = IssueManager.GeminiContext.Meta.LinkTypeGet();
            IssueLinkType        repeatedLinkType = linkTypes.Find(t => string.Compare(t.Label, "Repeated", true) == 0);

            if (repeatedLinkType == null && linkTypes.Count > 0)
            {
                repeatedLinkType = linkTypes[0];
            }

            var issue = IssueManager.Get(itemId);

            RepeatParser repeat = new RepeatParser(issue.Repeated);

            List <IssueDto> repeatedIssues = IssueManager.GetItemsForOriginator(IssueOriginatorType.Repeat, issue.Id.ToString());

            if (repeatedIssues.Count > 0)
            {
                var previousItemsToDelete = repeatedIssues.FindAll(c => c.Created.Date() >= startDateTime.Value && c.Created.Date() <= endDateTime.Value && !closedStatuses.Contains(c.Entity.StatusId));

                foreach (var item in previousItemsToDelete)
                {
                    IssueManager.Delete(item.Entity.Id);
                }
            }



            for (DateTime date = startDateTime.Value; date <= endDateTime.Value; date = date.AddDays(1))
            {
                repeat.CurrentDateTime = date.Date();

                IssueDto lastRepeated = IssueManager.GetLastCreatedIssueForOriginator(IssueOriginatorType.Repeat, issue.Id.ToString());

                DateTime lastRepeatedDate = issue.Created;

                if (lastRepeated != null && lastRepeated.Entity.IsExisting)
                {
                    lastRepeatedDate = lastRepeated.Created;
                }

                if (repeat.MaximumRepeats > 0)
                {
                    repeatedIssues = IssueManager.GetItemsForOriginator(IssueOriginatorType.Repeat, issue.Id.ToString());

                    if (repeatedIssues != null && repeatedIssues.Count >= repeat.MaximumRepeats)
                    {
                        continue;
                    }
                }

                //If last item was created into the future do this
                if (lastRepeatedDate > date.Date())
                {
                    List <IssueDto> tmpRepeatedIssues = IssueManager.GetItemsForOriginator(IssueOriginatorType.Repeat, issue.Id.ToString());

                    List <IssueDto> ItemsBeforeStartDate = tmpRepeatedIssues.FindAll(i => i.Created < date.Date());

                    if (ItemsBeforeStartDate.Count == 0)
                    {
                        lastRepeatedDate = issue.Created;
                    }
                    else
                    {
                        lastRepeatedDate = ItemsBeforeStartDate.OrderBy("Created").Last().Created;
                    }
                }

                if (repeat.NeedsToRepeat(lastRepeatedDate))
                {
                    var customFields = issue.CustomFields;

                    issue.Attachments = new List <IssueAttachmentDto>();

                    issue.Entity.Repeated = string.Empty;

                    issue.Entity.OriginatorData = issue.Entity.Id.ToString();

                    issue.Entity.OriginatorType = IssueOriginatorType.Repeat;

                    issue.Entity.ParentIssueId = null;
                    issue.Entity.IsParent      = false;

                    issue.Entity.StatusId = 0;

                    issue.Entity.ResolutionId = 0;

                    if (issue.Entity.StartDate.HasValue && issue.Entity.DueDate.HasValue &&
                        issue.Entity.StartDate != new DateTime() && issue.Entity.DueDate != new DateTime())
                    {
                        TimeSpan tsDates = issue.Entity.DueDate.Value - issue.Entity.StartDate.Value;

                        issue.Entity.DueDate = date.AddDays(tsDates.TotalDays);

                        issue.Entity.StartDate = date.Date();
                    }
                    else
                    {
                        issue.Entity.StartDate = null;

                        issue.Entity.DueDate = null;
                    }

                    int issueId = issue.Id;

                    issue.Entity.Created = date;

                    IssueDto repeated = IssueManager.Create(issue.Entity);

                    if (repeated.Entity.Id > 0)
                    {
                        string statment = "update gemini_issues set created = @created where issueid = @issueid";

                        SQLService.Instance.ExecuteQuery(statment, new { created = new DateTime(date.Year, date.Month, date.Day, 8, 0, 0).ToUtc(UserContext.User.TimeZone), issueid = repeated.Entity.Id });
                    }

                    if (customFields != null && customFields.Count > 0)
                    {
                        foreach (var field in customFields)
                        {
                            try
                            {
                                //Find the existing ID to 'replace', if exists.
                                var existingCF = repeated.CustomFields
                                                 .SingleOrDefault(s => s.Entity.CustomFieldId == field.Entity.CustomFieldId);
                                field.Entity.Id = existingCF == null ? 0 : existingCF.Entity.Id;

                                field.Entity.IssueId = repeated.Entity.Id;

                                field.Entity.ProjectId = repeated.Entity.ProjectId;

                                CustomFieldManager.Update(new CustomFieldData(field.Entity));
                            }
                            catch (Exception ex)
                            {
                                LogException(ex);
                            }
                        }
                    }

                    if (repeatedLinkType != null)
                    {
                        IssueManager.IssueLinkCreate(repeated.Entity.Id, issueId, repeatedLinkType.Id);
                    }
                }
            }

            return(JsonSuccess());
        }
        /// <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);
        }
        /// <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;
        }
Beispiel #14
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);
        }
Beispiel #15
0
        public override bool Run(IssueManager issueManager)
        {
/*#if DEBUG
 *          Debugger.Launch();
 #endif*/
            LogDebugMessage("Repeat Processing");

            try
            {
                List <IssueDto> issues = issueManager.GetRepeated();

                if (issues == null || issues.Count == 0)
                {
                    return(true);
                }

                List <IssueLinkType> linkTypes = issueManager.GeminiContext.Meta.LinkTypeGet();

                IssueLinkType repeatedLinkType = linkTypes.Find(t => string.Compare(t.Label, "Repeated", true) == 0);

                if (repeatedLinkType == null && linkTypes.Count > 0)
                {
                    repeatedLinkType = linkTypes[0];
                }

                foreach (IssueDto issue in issues)
                {
                    RepeatParser repeat = new RepeatParser(issue.Repeated);

                    repeat.CurrentDateTime = DateTime.UtcNow.ToLocal(issueManager.UserContext.User.TimeZone);

                    IssueDto lastRepeated = issueManager.GetLastCreatedIssueForOriginator(IssueOriginatorType.Repeat, issue.Id.ToString());

                    DateTime lastRepeatedDate = issue.Created;

                    if (lastRepeated != null && lastRepeated.Entity.IsExisting)
                    {
                        lastRepeatedDate = lastRepeated.Created;
                    }

                    if (repeat.MaximumRepeats > 0)
                    {
                        List <IssueDto> repeatedIssues = issueManager.GetItemsForOriginator(IssueOriginatorType.Repeat, issue.Id.ToString());

                        if (repeatedIssues != null && repeatedIssues.Count >= repeat.MaximumRepeats)
                        {
                            continue;
                        }
                    }

                    if (repeat.NeedsToRepeat(lastRepeatedDate))
                    {
                        var customFields = issue.CustomFields;

                        issue.Attachments = new List <IssueAttachmentDto>();

                        issue.Entity.Repeated = string.Empty;

                        issue.Entity.OriginatorData = issue.Entity.Id.ToString();

                        issue.Entity.OriginatorType = IssueOriginatorType.Repeat;

                        issue.Entity.ParentIssueId = null;
                        issue.Entity.IsParent      = false;

                        issue.Entity.StatusId = 0;

                        issue.Entity.ResolutionId  = 0;
                        issue.Entity.LoggedHours   = 0;
                        issue.Entity.LoggedMinutes = 0;

                        if (issue.Entity.StartDate.HasValue && issue.Entity.DueDate.HasValue &&
                            issue.Entity.StartDate != new DateTime() && issue.Entity.DueDate != new DateTime())
                        {
                            TimeSpan tsDates = issue.Entity.DueDate.Value - issue.Entity.StartDate.Value;

                            issue.Entity.DueDate = DateTime.Today.AddDays(tsDates.TotalDays);

                            issue.Entity.StartDate = DateTime.Today;
                        }
                        else
                        {
                            issue.Entity.StartDate = null;

                            issue.Entity.DueDate = null;
                        }

                        int issueId = issue.Id;

                        //Set the ID to 0 so it does not steal the custom fields for that tissue
                        var originalIssueID = issue.Entity.Id;
                        issue.Entity.Id = 0;

                        IssueDto repeated = issueManager.Create(issue.Entity);

                        if (customFields != null && customFields.Count > 0)
                        {
                            var customFieldManager = new CustomFieldManager(issueManager);

                            foreach (var field in customFields)
                            {
                                try
                                {
                                    //Find the existing ID to 'replace', if exists.
                                    var existingCF = repeated.CustomFields
                                                     .SingleOrDefault(s => s.Entity.CustomFieldId == field.Entity.CustomFieldId);
                                    field.Entity.Id = existingCF == null ? 0 : existingCF.Entity.Id;

                                    field.Entity.IssueId = repeated.Entity.Id;

                                    field.Entity.ProjectId = repeated.Entity.ProjectId;

                                    customFieldManager.Update(new CustomFieldData(field.Entity));
                                }
                                catch (Exception ex)
                                {
                                    LogException(ex);
                                }
                            }
                        }

                        if (repeatedLinkType != null)
                        {
                            issueManager.IssueLinkCreate(repeated.Entity.Id, issueId, repeatedLinkType.Id);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
            }

            return(true);
        }
Beispiel #16
0
 public FileController()
 {
     _fileManager        = new FileManager();
     _customFieldManager = new CustomFieldManager();
 }