Example #1
0
        private static List <IssueHistory> GetCustomFieldChanges(int issueId, List <CustomField> originalFields, List <CustomField> newFields)
        {
            var fieldChanges = new List <IssueHistory>();

            foreach (CustomField cf in newFields)
            {
                var field = originalFields.Find(f => f.Id == cf.Id);
                if (field != null && field.Value != cf.Value)
                {
                    var history = new IssueHistory {
                        CreatedUserName = Security.GetUserName(), IssueId = issueId, DateChanged = DateTime.Now
                    };
                    fieldChanges.Add(GetNewIssueHistory(history, cf.Name, field.Value, cf.Value));
                }
                else if (field == null)
                {
                    // new field added - do we want to track history for this since a value wasn't selected
                    var history = new IssueHistory {
                        CreatedUserName = Security.GetUserName(), IssueId = issueId, DateChanged = DateTime.Now
                    };
                    fieldChanges.Add(GetNewIssueHistory(history, cf.Name, string.Empty, cf.Value));
                }
            }

            return(fieldChanges);
        }
Example #2
0
        public IIssuesDTO CreateIssue(IIssuesDTO issuesDTO)
        {
            IIssuesDTO createIssueRetval = null;

            try
            {
                using (EmployeePortalEntities context = new EmployeePortalEntities())
                {
                    Issue issue = new Issue();
                    issuesDTO.IsActive = true;
                    EntityConverter.FillEntityFromDTO(issuesDTO, issue);
                    context.Issues.Add(issue);

                    issuesDTO.IssueHistoriesDTO.AssignedTo = 1;
                    issuesDTO.IssueHistoriesDTO.Comments   = "new issue has been generated";
                    issuesDTO.IssueHistoriesDTO.ModifiedBy = 1;
                    issuesDTO.IssueHistoriesDTO.Status     = 1;
                    issuesDTO.IssueHistoriesDTO.ModifiedOn = DateTime.Now;
                    issuesDTO.IssueHistoriesDTO.IssueId    = issue.IssueId;

                    IssueHistory newissueHistory = new IssueHistory();
                    EntityConverter.FillEntityFromDTO(issuesDTO.IssueHistoriesDTO, newissueHistory);
                    context.IssueHistories.Add(newissueHistory);
                    context.SaveChanges();

                    createIssueRetval = issuesDTO;
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(createIssueRetval);
        }
Example #3
0
        public async Task <Issue> Transition(Issue issue, IssueTransition transition, string userId, string comment)
        {
            //if transition not in possible transitions
            if (!GetTransitions(issue).Contains(transition))
            {
                throw new BusinessException(BusinessErrors.TransitionIsImpossible);
            }

            issue.IssueStatusCode = _stateMachine.Transition(issue.IssueStatusCode, transition);

            await TransferOwnerShip(issue, transition, userId);

            _db.Issues.Update(issue);

            var history = new IssueHistory
            {
                IssueId   = issue.Id,
                CreatedOn = DateTime.Now,
                Comment   = comment,
                Status    = issue.IssueStatusCode,
                UserId    = HttpContext.Current.User.Identity.GetUserId()
            };

            _db.Histories.Add(history);

            await _db.SaveAsync();

            return(issue);
        }
        /// <summary>
        /// Handles the ItemCommand event of the TimeEntriesDataGrid control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void TimeEntriesDataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            var id = Convert.ToInt32(e.CommandArgument);

            if (!IssueWorkReportManager.Delete(id))
            {
                return;
            }

            var history = new IssueHistory
            {
                IssueId                 = IssueId,
                CreatedUserName         = Security.GetUserName(),
                DateChanged             = DateTime.Now,
                FieldChanged            = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "TimeLogged", "Time Logged"),
                OldValue                = string.Empty,
                NewValue                = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Deleted", "Deleted"),
                TriggerLastUpdateChange = true
            };

            IssueHistoryManager.SaveOrUpdate(history);

            var changes = new List <IssueHistory> {
                history
            };

            IssueNotificationManager.SendIssueNotifications(IssueId, changes);

            BindTimeEntries();
        }
Example #5
0
        /// <summary>
        /// adds user to database and redirects to index
        /// </summary>
        /// <param name="issue"></param>
        /// <returns></returns>
        public async Task <ActionResult> Add(Issue issue)
        {
            if (issue.Subject == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            issue.CreatorId       = User.Identity.GetUserId();
            issue.Registered      = DateTime.Now;
            issue.IssueStatusCode = IssueStatusCode.New;
            _db.Issues.Add(issue);

            var history = new IssueHistory
            {
                IssueId   = issue.Id,
                CreatedOn = DateTime.Now,
                Comment   = "Created: " + issue.Subject,
                Status    = issue.IssueStatusCode,
                UserId    = System.Web.HttpContext.Current.User.Identity.GetUserId()
            };

            _db.Histories.Add(history);

            await _db.SaveAsync();

            return(RedirectToAction("Index", "Issue"));
        }
        protected CollectionBase  GenerateIssueHistoryCollectionFromReader(IDataReader returnData)
        {
            IssueHistoryCollection hstCollection = new IssueHistoryCollection();

            while (returnData.Read())
            {
                IssueHistory newHistory = new IssueHistory((int)returnData["HistoryId"], (int)returnData["IssueId"], (string)returnData["CreatorDisplayName"], (DateTime)returnData["DateCreated"]);
                hstCollection.Add(newHistory);
            }
            return(hstCollection);
        }
Example #7
0
 /// <summary>
 /// Gets the new issue history.
 /// </summary>
 /// <param name="history">The history.</param>
 /// <param name="fieldChanged">The field changed.</param>
 /// <param name="oldValue">The old value.</param>
 /// <param name="newValue">The new value.</param>
 /// <returns></returns>
 private static IssueHistory GetNewIssueHistory(IssueHistory history, string fieldChanged, string oldValue, string newValue)
 {
     return(new IssueHistory
     {
         CreatedUserName = history.CreatedUserName,
         CreatorDisplayName = string.Empty,
         DateChanged = history.DateChanged,
         FieldChanged = fieldChanged,
         IssueId = history.IssueId,
         NewValue = newValue,
         OldValue = oldValue
     });
 }
Example #8
0
        void grdHistoryItemDataBound(Object s, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                IssueHistory currentHistory = (IssueHistory)e.Item.DataItem;

                Label lblCreatorDisplayName = (Label)e.Item.FindControl("lblCreatorDisplayName");
                lblCreatorDisplayName.Text = currentHistory.CreatorDisplayName;

                Label lblDateCreated = (Label)e.Item.FindControl("lblDateCreated");
                lblDateCreated.Text = currentHistory.DateCreated.ToString("f");
            }
        }
        /// <summary>
        /// Handles the Click event of the cmdAddBugTimeEntry 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 AddTimeEntry_Click(object sender, EventArgs e)
        {
            if (DurationTextBox.Text.Trim().Length == 0)
            {
                return;
            }

            var selectedWorkDate = TimeEntryDate.SelectedValue == null
                                       ? DateTime.MinValue
                                       : (DateTime)TimeEntryDate.SelectedValue;
            var workDuration = Convert.ToDecimal(DurationTextBox.Text);

            var workReport = new IssueWorkReport
            {
                CommentText     = CommentHtmlEditor.Text.Trim(),
                CreatorUserName = Context.User.Identity.Name,
                Duration        = workDuration,
                IssueId         = IssueId,
                WorkDate        = selectedWorkDate
            };

            IssueWorkReportManager.SaveOrUpdate(workReport);

            var history = new IssueHistory
            {
                IssueId                 = IssueId,
                CreatedUserName         = Security.GetUserName(),
                DateChanged             = DateTime.Now,
                FieldChanged            = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "TimeLogged", "Time Logged"),
                OldValue                = string.Empty,
                NewValue                = DurationTextBox.Text.Trim(),
                TriggerLastUpdateChange = true
            };

            IssueHistoryManager.SaveOrUpdate(history);

            var changes = new List <IssueHistory> {
                history
            };

            IssueNotificationManager.SendIssueNotifications(IssueId, changes);

            CommentHtmlEditor.Text = string.Empty;

            DurationTextBox.Text = string.Empty;

            BindTimeEntries();
        }
Example #10
0
        /// <summary>
        /// Handles the Click event of the cmdUpdate 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 CmdAddRelatedIssueClick(object sender, EventArgs e)
        {
            if (IssueIdTextBox.Text == String.Empty)
            {
                return;
            }

            if (!Page.IsValid)
            {
                return;
            }

            RelatedIssuesMessage.Visible = false;

            var issueId = Utilities.ParseFullIssueId(IssueIdTextBox.Text.Trim());

            if (issueId <= Globals.NEW_ID)
            {
                return;
            }

            RelatedIssueManager.CreateNewRelatedIssue(IssueId, issueId);

            IssueIdTextBox.Text = String.Empty;

            var history = new IssueHistory
            {
                IssueId                 = IssueId,
                CreatedUserName         = Security.GetUserName(),
                DateChanged             = DateTime.Now,
                FieldChanged            = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "RelatedIssue", "Related Issue"),
                OldValue                = string.Empty,
                NewValue                = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"),
                TriggerLastUpdateChange = true
            };

            IssueHistoryManager.SaveOrUpdate(history);

            var changes = new List <IssueHistory> {
                history
            };

            IssueNotificationManager.SendIssueNotifications(IssueId, changes);

            BindRelated();
        }
        /// <summary>
        /// Create a new entry in issue and issue history table
        /// </summary>
        /// <param name="issueDTO"></param>
        /// <returns></returns>
        public IIssueDTO CreateIssue(IIssueDTO issueDTO)
        {
            IIssueDTO createIssueRetVal = null;

            try
            {
                using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities())
                {
                    using (var transScope = new TransactionScope())
                    {
                        issueDTO.IsActive = true;
                        Issue issue = new Issue();
                        EntityConverter.FillEntityFromDTO(issueDTO, issue);
                        portal.Issues.Add(issue);
                        portal.SaveChanges();
                        issueDTO.IssueId = issue.IssueId;

                        IIssueHistoryDTO issueHistoryDTO = (IIssueHistoryDTO)DTOFactory.Instance.Create(DTOType.IssueHistoryDTO);
                        issueHistoryDTO.IssueId    = issue.IssueId;
                        issueHistoryDTO.AssignedTo = null;
                        issueHistoryDTO.Comments   = null;
                        issueHistoryDTO.ModifiedBy = issue.PostedBy;
                        issueHistoryDTO.ModifiedOn = DateTime.Now;
                        issueHistoryDTO.Status     = (int)IssueStatus.Raised;

                        IssueHistory issueHistory = new IssueHistory();
                        EntityConverter.FillEntityFromDTO(issueHistoryDTO, issueHistory);
                        portal.IssueHistories.Add(issueHistory);
                        portal.SaveChanges();
                        transScope.Complete();
                        createIssueRetVal = issueDTO;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(createIssueRetVal);
        }
Example #12
0
        public async Task LogChangeHistoryAsync(Issue issue)
        {
            var issueHistory = new IssueHistory
            {
                IssueId    = issue.Id,
                IssueTitle = issue.Title,
                Type       = issue.Type,
                Status     = issue.Status,
                Priority   = issue.Priority,

                // Current user making the change.
                OwnerId     = _currentUser.Id,
                OwnerAlias  = _cache.Users[_currentUser.Id].Alias,
                CreatedDate = DateTime.Now,
                CreatedOn   = DateTime.Now,
                CreatedBy   = _currentUser.Id,
                ChangedOn   = DateTime.Now
            };

            _db.Add(issueHistory);
            await _db.SaveChangesAsync();
        }
Example #13
0
        /// <summary>
        /// GRDs the bugs item command.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void GrdBugsItemCommand(Object s, DataGridCommandEventArgs e)
        {
            var commandArgument = e.CommandArgument.ToString();
            var commandName     = e.CommandName.ToLower().Trim();
            var currentIssueId  = Globals.NEW_ID;

            switch (commandName)
            {
            case "delete":
                currentIssueId = int.Parse(commandArgument);
                RelatedIssueManager.DeleteParentIssue(IssueId, currentIssueId);
                break;
            }

            if (currentIssueId > Globals.NEW_ID)
            {
                var history = new IssueHistory
                {
                    IssueId                 = IssueId,
                    CreatedUserName         = Security.GetUserName(),
                    DateChanged             = DateTime.Now,
                    FieldChanged            = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "ParentIssue", "Parent Issue"),
                    OldValue                = string.Empty,
                    NewValue                = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Deleted", "Deleted"),
                    TriggerLastUpdateChange = true
                };

                IssueHistoryManager.SaveOrUpdate(history);

                var changes = new List <IssueHistory> {
                    history
                };

                IssueNotificationManager.SendIssueNotifications(IssueId, changes);
            }

            BindRelated();
        }
Example #14
0
        /// <summary>
        /// Saves the issue history.
        /// </summary>
        /// <param name="issueHistoryToSave">The issue history to save.</param>
        /// <returns></returns>
        public static bool SaveOrUpdate(IssueHistory issueHistoryToSave)
        {
            if (issueHistoryToSave.Id > Globals.NEW_ID)
            {
                return(false);
            }

            var tempId = DataProviderManager.Provider.CreateNewIssueHistory(issueHistoryToSave);

            if (tempId <= 0)
            {
                return(false);
            }

            issueHistoryToSave.Id = tempId;

            if (issueHistoryToSave.TriggerLastUpdateChange)
            {
                DataProviderManager.Provider.UpdateIssueLastUpdated(issueHistoryToSave.IssueId, Security.GetUserName());
            }

            return(true);
        }
Example #15
0
        /// <summary>
        /// Handles the Click event of the cmdAddComment 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 CmdAddCommentClick(object sender, EventArgs e)
        {
            if (CommentHtmlEditor.Text.Trim().Length == 0)
            {
                return;
            }

            var comment = new IssueComment
            {
                IssueId         = IssueId,
                Comment         = CommentHtmlEditor.Text.Trim(),
                CreatorUserName = Security.GetUserName(),
                DateCreated     = DateTime.Now
            };

            var result = IssueCommentManager.SaveOrUpdate(comment);

            if (result)
            {
                //add history record
                var history = new IssueHistory
                {
                    IssueId                 = IssueId,
                    CreatedUserName         = Security.GetUserName(),
                    DateChanged             = DateTime.Now,
                    FieldChanged            = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Comment", "Comment"),
                    OldValue                = string.Empty,
                    NewValue                = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"),
                    TriggerLastUpdateChange = true
                };

                IssueHistoryManager.SaveOrUpdate(history);
            }

            CommentHtmlEditor.Text = String.Empty;
            BindComments();
        }
        /// <summary>
        /// This should make an insertion in the IssueHistory table against an entry in the Issue table.
        /// If successfully done, return the relevant IssueHistoryDTO else return null.
        /// </summary>
        /// <param name="issueHistoryDTO"></param>
        /// <returns></returns>
        public IIssueHistoryDTO UpdateIssueByAdmin(IIssueHistoryDTO issueHistoryDTO)
        {
            IIssueHistoryDTO updateIssueByAdminRetVal = null;

            try
            {
                using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities())
                {
                    IssueHistory issueHistory = new IssueHistory();
                    EntityConverter.FillEntityFromDTO(issueHistoryDTO, issueHistory);
                    portal.IssueHistories.Add(issueHistory);
                    portal.SaveChanges();
                    issueHistoryDTO.IssueHistoryId = issueHistory.IssueHistoryId;
                    updateIssueByAdminRetVal       = issueHistoryDTO;
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }

            return(updateIssueByAdminRetVal);
        }
        /// <summary>
        /// Deletes the IssueAttachment.
        /// </summary>
        /// <param name="issueAttachmentId">The issue attachment id.</param>
        /// <returns></returns>
        public static bool Delete(int issueAttachmentId)
        {
            var att     = GetById(issueAttachmentId);
            var issue   = IssueManager.GetById(att.IssueId);
            var project = ProjectManager.GetById(issue.ProjectId);

            if (DataProviderManager.Provider.DeleteIssueAttachment(issueAttachmentId))
            {
                try
                {
                    var history = new IssueHistory
                    {
                        IssueId                 = att.IssueId,
                        CreatedUserName         = Security.GetUserName(),
                        DateChanged             = DateTime.Now,
                        FieldChanged            = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Attachment", "Attachment"),
                        OldValue                = att.FileName,
                        NewValue                = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Deleted", "Deleted"),
                        TriggerLastUpdateChange = true
                    };

                    IssueHistoryManager.SaveOrUpdate(history);

                    var changes = new List <IssueHistory> {
                        history
                    };

                    IssueNotificationManager.SendIssueNotifications(att.IssueId, changes);
                }
                catch (Exception ex)
                {
                    if (Log.IsErrorEnabled)
                    {
                        Log.Error(ex);
                    }
                }

                if (HostSettingManager.Get(HostSettingNames.AttachmentStorageType, 0) == (int)IssueAttachmentStorageTypes.FileSystem)
                {
                    //delete IssueAttachment from file system.
                    try
                    {
                        if (string.IsNullOrEmpty(project.UploadPath))
                        {
                            project.UploadPath = project.Id.ToString();//use project id as pathroot
                        }
                        var filePath = String.Format(@"{2}{0}\{1}", project.UploadPath, att.FileName, HostSettingManager.Get(HostSettingNames.AttachmentUploadPath));

                        if (filePath.StartsWith("~"))
                        {
                            filePath = HttpContext.Current.Server.MapPath(filePath);
                        }

                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                        else
                        {
                            Log.Info(String.Format("Failed to locate file {0} to delete, it may have been moved or manually deleted", filePath));
                        }
                    }
                    catch (Exception ex)
                    {
                        //set user to log4net context, so we can use %X{user} in the appenders
                        if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
                        {
                            MDC.Set("user", HttpContext.Current.User.Identity.Name);
                        }

                        if (Log.IsErrorEnabled)
                        {
                            Log.Error(String.Format("Error Deleting IssueAttachment - {0}", String.Format("{0}\\{1}", project.UploadPath, att.FileName)), ex);
                        }

                        throw new ApplicationException(LoggingManager.GetErrorMessageResource("AttachmentDeleteError"), ex);
                    }
                }
            }
            return(true);
        }
Example #18
0
        /// <summary>
        /// Gets the issue changes.
        /// </summary>
        /// <param name="originalIssue">The original issue.</param>
        /// <param name="issueToCompare">The issue to compare.</param>
        /// <returns></returns>
        public static List <IssueHistory> GetIssueChanges(Issue originalIssue, Issue issueToCompare)
        {
            var issueChanges = new List <IssueHistory>();

            if (originalIssue != null && issueToCompare != null)
            {
                var history = new IssueHistory {
                    CreatedUserName = issueToCompare.CreatorUserName, IssueId = originalIssue.Id, DateChanged = DateTime.Now
                };

                if (originalIssue.Title.ToLower() != issueToCompare.Title.ToLower())
                {
                    issueChanges.Add(GetNewIssueHistory(history, "Title", originalIssue.Title, issueToCompare.Title));
                }

                if (originalIssue.Description.ToLower() != issueToCompare.Description.ToLower())
                {
                    issueChanges.Add(GetNewIssueHistory(history, "Description", originalIssue.Description, issueToCompare.Description));
                }

                if (originalIssue.CategoryId != issueToCompare.CategoryId)
                {
                    issueChanges.Add(GetNewIssueHistory(history, "Category", originalIssue.CategoryName, issueToCompare.CategoryName));
                }

                if (originalIssue.PriorityId != issueToCompare.PriorityId)
                {
                    issueChanges.Add(GetNewIssueHistory(history, "Priority", originalIssue.PriorityName, issueToCompare.PriorityName));
                }

                if (originalIssue.StatusId != issueToCompare.StatusId)
                {
                    issueChanges.Add(GetNewIssueHistory(history, "Status", originalIssue.StatusName, issueToCompare.StatusName));
                }

                if (originalIssue.MilestoneId != issueToCompare.MilestoneId)
                {
                    issueChanges.Add(GetNewIssueHistory(history, "Milestone", originalIssue.MilestoneName, issueToCompare.MilestoneName));
                }

                if (originalIssue.AffectedMilestoneId != issueToCompare.AffectedMilestoneId)
                {
                    issueChanges.Add(GetNewIssueHistory(history, "Affected Milestone", originalIssue.AffectedMilestoneName, issueToCompare.AffectedMilestoneName));
                }

                if (originalIssue.IssueTypeId != issueToCompare.IssueTypeId)
                {
                    issueChanges.Add(GetNewIssueHistory(history, "Issue Type", originalIssue.IssueTypeName, issueToCompare.IssueTypeName));
                }

                if (originalIssue.ResolutionId != issueToCompare.ResolutionId)
                {
                    issueChanges.Add(GetNewIssueHistory(history, "Resolution", originalIssue.ResolutionName, issueToCompare.ResolutionName));
                }

                var unassignedLiteral = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Unassigned", "Unassigned");

                var newAssignedUserName = String.IsNullOrEmpty(issueToCompare.AssignedUserName) ? unassignedLiteral : issueToCompare.AssignedUserName;

                if (originalIssue.AssignedUserName != newAssignedUserName)
                {
                    // if the new assigned user is the unassigned user then don't trigger the new assignee notification
                    issueToCompare.SendNewAssigneeNotification = (newAssignedUserName != unassignedLiteral);
                    issueToCompare.NewAssignee = true;
                    var newAssignedDisplayName = (newAssignedUserName == unassignedLiteral) ? newAssignedUserName : UserManager.GetUserDisplayName(newAssignedUserName);
                    issueChanges.Add(GetNewIssueHistory(history, "Assigned to", originalIssue.AssignedDisplayName, newAssignedDisplayName));
                }

                var newOwnerUserName = String.IsNullOrEmpty(issueToCompare.OwnerUserName) ? unassignedLiteral : issueToCompare.OwnerUserName;

                if (originalIssue.OwnerUserName != newOwnerUserName)
                {
                    var newOwnerDisplayName = (newOwnerUserName == unassignedLiteral) ? newOwnerUserName : UserManager.GetUserDisplayName(issueToCompare.OwnerUserName);
                    issueChanges.Add(GetNewIssueHistory(history, "Owner", originalIssue.OwnerDisplayName, newOwnerDisplayName));
                }


                if (originalIssue.Estimation != issueToCompare.Estimation)
                {
                    issueChanges.Add(GetNewIssueHistory(history, "Estimation", Utilities.EstimationToString(originalIssue.Estimation), Utilities.EstimationToString(issueToCompare.Estimation)));
                }

                if (originalIssue.Visibility != issueToCompare.Visibility)
                {
                    issueChanges.Add(GetNewIssueHistory(history, "Visibility", Utilities.GetBooleanAsString(originalIssue.Visibility.ToBool()), Utilities.GetBooleanAsString(issueToCompare.Visibility.ToBool())));
                }

                if (originalIssue.DueDate != issueToCompare.DueDate)
                {
                    var originalDate = originalIssue.DueDate == DateTime.MinValue ? string.Empty : originalIssue.DueDate.ToShortDateString();
                    var newDate      = issueToCompare.DueDate == DateTime.MinValue ? string.Empty : issueToCompare.DueDate.ToShortDateString();

                    issueChanges.Add(GetNewIssueHistory(history, "Due Date", originalDate, newDate));
                }

                if (originalIssue.Progress != issueToCompare.Progress)
                {
                    var nfi = new NumberFormatInfo {
                        PercentDecimalDigits = 0
                    };

                    var oldProgress = originalIssue.Progress.Equals(0) ? 0 : (originalIssue.Progress.To <double>() / 100);
                    var newProgress = issueToCompare.Progress.Equals(0) ? 0 : (issueToCompare.Progress.To <double>() / 100);

                    issueChanges.Add(GetNewIssueHistory(history, "Progress", oldProgress.ToString("P", nfi), newProgress.ToString("P", nfi)));
                }
            }
            else
            {
                throw new Exception("Unable to retrieve original issue data");
            }

            return(issueChanges);
        }
Example #19
0
 void BindHistory()
 {
     grdHistory.DataSource = IssueHistory.GetIssueHistoryByIssueId(_IssueId);
     grdHistory.DataBind();
 }
 partial void RefreshStatusHistory_Execute()
 {
     // Write your code here.
     IssueHistory.Refresh();
 }
 public IssueHistory AddIssueHistory(IssueHistory changes)
 {
     _context.IssueHistory.Add(changes);
     _context.SaveChanges();
     return(changes);
 }
Example #22
0
        public async Task <IActionResult> IssueDetails(IssueDetailsViewModel model)
        {
            var userId      = userManager.GetUserId(User);
            var currentUser = await userManager.FindByIdAsync(userId);

            var userClaims = await userManager.GetClaimsAsync(currentUser);

            Global.globalCurrentUserClaims = userClaims.ToList();

            var IsManagerLevel = ClaimsLevel.IsManager(userClaims.ToList(), model.Issue.AssociatedProject);

            if (IsManagerLevel && model.Issue.AssigneeUserId != null)
            {
                var assignedUser = await userManager.FindByIdAsync(model.Issue.AssigneeUserId);

                model.Issue.AssigneeUserName = assignedUser.UserName;
            }

            var uniqueFileNames = new List <ScreenShots>();

            if (Global.InitialScreenShots == true)
            {
                uniqueFileNames = await UploadScreenShotsToStorage(model.Issue.IssueId);
            }

            Global.InitialScreenShots = false;
            _issueRepository.AddScreenShots(uniqueFileNames);


            var originalIssue = _issueRepository.GetIssue(model.Issue.IssueId);

            if (model.Issue.Title == null)
            {
                model.Issue.Title = originalIssue.Title;
            }

            var IsDeveloperLevel = ClaimsLevel.IsDeveloper(userClaims.ToList(), model.Issue.AssociatedProject);

            if (IsDeveloperLevel)
            {
                foreach (var property in originalIssue.GetType().GetProperties())
                {
                    if (property.Name == "AssigneeUserId")
                    {
                        continue;
                    }

                    var oldValue = "";
                    var newValue = "";

                    if (property.GetValue(model.Issue) != null)
                    {
                        newValue = property.GetValue(model.Issue).ToString();
                    }

                    if (property.GetValue(originalIssue) != null)
                    {
                        oldValue = property.GetValue(originalIssue).ToString();
                    }

                    if (newValue != oldValue)
                    {
                        var changes = new IssueHistory
                        {
                            AssociatedIssueId = originalIssue.IssueId,
                            DateModified      = DateTime.Now,
                            NewValue          = newValue,
                            OldValue          = oldValue,
                            Property          = property.Name
                        };

                        _issueRepository.AddIssueHistory(changes);
                    }
                }
            }

            var issue = new Issue();

            if (IsDeveloperLevel)
            {
                model.Issue.ScreenShots = uniqueFileNames;
                model.Issue.ScreenShots.AddRange(_issueRepository.ScreenShots(model.Issue.IssueId));
                issue = _issueRepository.Update(model.Issue);
            }
            else
            {
                issue             = originalIssue;
                issue.ScreenShots = uniqueFileNames;
                issue.ScreenShots.AddRange(_issueRepository.ScreenShots(model.Issue.IssueId));
            }
            Console.WriteLine(issue.IssueId);
            var project     = _projectRepository.GetProject(issue.AssociatedProject);
            var projectName = project.ProjectName;

            issue.Comments = _issueRepository.Comments(issue.IssueId);
            var issueHistory = _issueRepository.GetIssueHistories(issue.IssueId);

            var users        = new List <IdentityUser>();
            var projectUsers = new List <string>();

            projectUsers.Add(project.OwnerId);

            if (project.UsersAssigned != null)
            {
                projectUsers.AddRange(project.UsersAssigned.Split(" ").ToList());
            }

            foreach (var uId in projectUsers)
            {
                var user = await userManager.FindByIdAsync(uId);

                if (user != null && !users.Contains(user))
                {
                    users.Add(user);
                }
            }

            var screenshots = _issueRepository.ScreenShots(model.Issue.IssueId);


            var viewModel = new IssueDetailsViewModel
            {
                Issue          = issue,
                IssueHistories = issueHistory,
                Updated        = 1,
                ProjectId      = issue.AssociatedProject,
                Source         = screenshots,
                ProjectUsers   = users,
                ProjectName    = projectName
            };

            return(View(viewModel));
        }
Example #23
0
        public void saveIssueHistory(IssueHistory history)
        {
            try
            {
                history.sequence = getNextHistorySequence(history.id);

                command  = "INSERT OR REPLACE INTO issuesHistory(\n";
                command += "id,\n";
                command += "sequence,\n";
                command += "number,\n";
                command += "title,\n";
                command += "assignee,\n";
                command += "type,\n";
                command += "priority,\n";
                command += "state,\n";
                command += "component,\n";
                command += "milestone,\n";
                command += "version,\n";
                command += "reporter,\n";
                command += "created_on,\n";
                command += "updated_on,\n";
                command += "eventDate)\n";
                command += "values (\n";
                command += "@id,\n";
                command += "@sequence,\n";
                command += "@number,\n";
                command += "@title,\n";
                command += "@assignee,\n";
                command += "@type,\n";
                command += "@priority,\n";
                command += "@state,\n";
                command += "@component,\n";
                command += "@milestone,\n";
                command += "@version,\n";
                command += "@reporter,\n";
                command += "@created_on,\n";
                command += "@updated_on,\n";
                command += "@eventDate)\n";;

                parameters = new List <clsDataBaseParametes>();
                parameters.Add(new clsDataBaseParametes("@id", history.id.ToString()));
                parameters.Add(new clsDataBaseParametes("@sequence", history.sequence.ToString()));
                parameters.Add(new clsDataBaseParametes("@number", history.number));
                parameters.Add(new clsDataBaseParametes("@title", history.title));
                parameters.Add(new clsDataBaseParametes("@assignee", history.assignee));
                parameters.Add(new clsDataBaseParametes("@type", history.kind));
                parameters.Add(new clsDataBaseParametes("@priority", history.priority));
                parameters.Add(new clsDataBaseParametes("@state", history.state));
                parameters.Add(new clsDataBaseParametes("@component", history.component));
                parameters.Add(new clsDataBaseParametes("@milestone", history.milestone));
                parameters.Add(new clsDataBaseParametes("@version", history.version));
                parameters.Add(new clsDataBaseParametes("@reporter", history.reporter));
                parameters.Add(new clsDataBaseParametes("@created_on", history.created_on.ToString("yyyy-MM-ddTHH:mm:ss")));
                parameters.Add(new clsDataBaseParametes("@updated_on", history.updated_on.ToString("yyyy-MM-ddTHH:mm:ss")));
                parameters.Add(new clsDataBaseParametes("@eventDate", history.eventDate.ToString("yyyy-MM-ddTHH:mm:ss")));

                dataBase.sbExecute(command, parameters);
                dataBase.sbCommit();
            }
            catch (DataBaseException exdb)
            {
                throw new Exception("Database error: " + exdb.Code + " - " + exdb.Message);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #24
0
 public abstract int CreateNewIssueHistory(IssueHistory newHistory);
Example #25
0
        private bool ProcessNewComment(List <string> recipients, POP3_ClientMessage message, Mail_Message mailHeader, MailboxReaderResult result)
        {
            string messageFrom = string.Empty;

            if (mailHeader.From.Count > 0)
            {
                messageFrom = string.Join("; ", mailHeader.From.ToList().Select(p => p.Address).ToArray()).Trim();
            }

            bool processed = false;

            foreach (var address in recipients)
            {
                Regex isReply      = new Regex(@"(.*)(\+iid-)(\d+)@(.*)");
                Match commentMatch = isReply.Match(address);
                if (commentMatch.Success && commentMatch.Groups.Count >= 4)
                {
                    // we are in a reply and group 4 must contain the id of the original issue
                    int issueId;
                    if (int.TryParse(commentMatch.Groups[3].Value, out issueId))
                    {
                        var _currentIssue = IssueManager.GetById(issueId);

                        if (_currentIssue != null)
                        {
                            var project = ProjectManager.GetById(_currentIssue.ProjectId);

                            var mailbody = Mail_Message.ParseFromByte(message.MessageToByte());

                            bool isHtml;
                            List <MIME_Entity> attachments = null;
                            string             content     = GetMessageContent(mailbody, project, out isHtml, ref attachments);

                            IssueComment comment = new IssueComment
                            {
                                IssueId     = issueId,
                                Comment     = content,
                                DateCreated = mailHeader.Date
                            };

                            // try to find if the creator is valid user in the project, otherwise take
                            // the user defined in the mailbox config
                            var users  = UserManager.GetUsersByProjectId(project.Id);
                            var emails = messageFrom.Split(';').Select(e => e.Trim().ToLower());
                            var user   = users.Find(x => emails.Contains(x.Email.ToLower()));
                            if (user != null)
                            {
                                comment.CreatorUserName = user.UserName;
                            }
                            else
                            {
                                // user not found
                                continue;
                            }

                            var saved = IssueCommentManager.SaveOrUpdate(comment);
                            if (saved)
                            {
                                //add history record
                                var history = new IssueHistory
                                {
                                    IssueId                 = issueId,
                                    CreatedUserName         = comment.CreatorUserName,
                                    DateChanged             = comment.DateCreated,
                                    FieldChanged            = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Comment", "Comment"),
                                    OldValue                = string.Empty,
                                    NewValue                = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"),
                                    TriggerLastUpdateChange = true
                                };
                                IssueHistoryManager.SaveOrUpdate(history);

                                var projectFolderPath = Path.Combine(Config.UploadsFolderPath, project.UploadPath);

                                // save attachments as new files
                                int attachmentsSavedCount = 1;
                                foreach (MIME_Entity mimeEntity in attachments)
                                {
                                    string fileName;
                                    var    contentType = mimeEntity.ContentType.Type.ToLower();

                                    var attachment = new IssueAttachment
                                    {
                                        Id                 = 0,
                                        Description        = "File attached by mailbox reader",
                                        DateCreated        = DateTime.Now,
                                        ContentType        = mimeEntity.ContentType.TypeWithSubtype,
                                        CreatorDisplayName = user.DisplayName,
                                        CreatorUserName    = user.UserName,
                                        IssueId            = issueId,
                                        ProjectFolderPath  = projectFolderPath
                                    };
                                    attachment.Attachment = ((MIME_b_SinglepartBase)mimeEntity.Body).Data;

                                    if (contentType.Equals("attachment")) // this is an attached email
                                    {
                                        fileName = mimeEntity.ContentDisposition.Param_FileName;
                                    }
                                    else if (contentType.Equals("message")) // message has no filename so we create one
                                    {
                                        fileName = string.Format("Attached_Message_{0}.eml", attachmentsSavedCount);
                                    }
                                    else
                                    {
                                        fileName = string.IsNullOrWhiteSpace(mimeEntity.ContentType.Param_Name) ?
                                                   string.Format("untitled.{0}", mimeEntity.ContentType.SubType) :
                                                   mimeEntity.ContentType.Param_Name;
                                    }

                                    attachment.FileName = fileName;

                                    var saveFile  = IsAllowedFileExtension(fileName);
                                    var fileSaved = false;

                                    // can we save the file?
                                    if (saveFile)
                                    {
                                        fileSaved = IssueAttachmentManager.SaveOrUpdate(attachment);

                                        if (fileSaved)
                                        {
                                            attachmentsSavedCount++;
                                        }
                                        else
                                        {
                                            LogWarning("MailboxReader: Attachment could not be saved, please see previous logs");
                                        }
                                    }
                                }

                                processed = true;

                                // add the entry if the save did not throw any exceptions
                                result.MailboxEntries.Add(new MailboxEntry());
                            }
                        }
                    }
                }
            }
            return(processed);
        }
Example #26
0
        /// <summary>
        /// Uploads the document.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void UploadDocument(object sender, EventArgs e)
        {
            // get the current file
            var uploadFile = AspUploadFile.PostedFile;

            // if there was a file uploaded
            if (uploadFile != null && uploadFile.ContentLength > 0)
            {
                var inValidReason = string.Empty;
                var fileName = Path.GetFileName(uploadFile.FileName);

                var validFile = IssueAttachmentManager.IsValidFile(fileName, out inValidReason);

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

                    var attachment = 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 = fileName,
                        IssueId = IssueId,
                        Size = fileBytes.Length
                    };

                    if (!IssueAttachmentManager.SaveOrUpdate(attachment))
                    {
                        AttachmentsMessage.ShowErrorMessage(string.Format(GetGlobalResourceObject("Exceptions", "SaveAttachmentError").ToString(), uploadFile.FileName));
                        if (Log.IsWarnEnabled) Log.Warn(string.Format(GetGlobalResourceObject("Exceptions", "SaveAttachmentError").ToString(), uploadFile.FileName));
                        return;
                    }

                    //add history record and send notifications
                    var history = new IssueHistory
                    {
                        IssueId = IssueId,
                        CreatedUserName = Security.GetUserName(),
                        DateChanged = DateTime.Now,
                        FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Attachment", "Attachment"),
                        OldValue = fileName,
                        NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"),
                        TriggerLastUpdateChange = true
                    };

                    IssueHistoryManager.SaveOrUpdate(history);

                    var changes = new List<IssueHistory> { history };

                    IssueNotificationManager.SendIssueNotifications(IssueId, changes);

                    BindAttachments();
                }
                else
                    AttachmentsMessage.ShowErrorMessage(inValidReason); 
            }
        }