Пример #1
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns></returns>
        public static bool SaveOrUpdate(IssueComment entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (entity.IssueId <= Globals.NEW_ID)
            {
                throw (new ArgumentException("Cannot save issue comment, the issue id is invalid"));
            }
            if (string.IsNullOrEmpty(entity.Comment))
            {
                throw (new ArgumentException("The issue comment cannot be empty or null"));
            }

            if (entity.Id > Globals.NEW_ID)
            {
                return(DataProviderManager.Provider.UpdateIssueComment(entity));
            }

            var tempId = DataProviderManager.Provider.CreateNewIssueComment(entity);

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

            entity.Id = tempId;

            IssueNotificationManager.SendNewIssueCommentNotification(entity.IssueId, GetById(entity.Id));

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Saves the issue
        /// </summary>
        /// <param name="entity">The issue to save.</param>
        /// <returns></returns>
        public static bool SaveOrUpdate(Issue entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (entity.ProjectId <= Globals.NEW_ID)
            {
                throw (new ArgumentException("The issue project id is invalid"));
            }
            if (string.IsNullOrEmpty(entity.Title))
            {
                throw (new ArgumentException("The issue title cannot be empty or null"));
            }

            try
            {
                if (entity.Id <= Globals.NEW_ID)
                {
                    var tempId = DataProviderManager.Provider.CreateNewIssue(entity);

                    if (tempId > 0)
                    {
                        entity.Id = tempId;
                        return(true);
                    }

                    return(false);
                }

                // this is here due to issue with updating the issue from the Mailbox reader
                // to fix the inline images.  we don't have an http context so we are limited to what we can
                // do from here.  in any case the mailbox reader is creating and updating concurrently so
                // we are not missing anything.
                if (HttpContext.Current != null)
                {
                    //existing issue
                    entity.LastUpdate         = DateTime.Now;
                    entity.LastUpdateUserName = Security.GetUserName();

                    var issueChanges = GetIssueChanges(GetById(entity.Id), entity);

                    DataProviderManager.Provider.UpdateIssue(entity);

                    UpdateHistory(issueChanges);

                    IssueNotificationManager.SendIssueNotifications(entity.Id, issueChanges);

                    if (entity.SendNewAssigneeNotification)
                    {
                        //add this user to notifications and send them a notification
                        var notification = new IssueNotification
                        {
                            IssueId = entity.Id,
                            NotificationUsername = entity.AssignedUserName,
                            NotificationCulture  = string.Empty
                        };

                        var profile = new WebProfile().GetProfile(entity.AssignedUserName);
                        if (profile != null && !string.IsNullOrWhiteSpace(profile.PreferredLocale))
                        {
                            notification.NotificationCulture = profile.PreferredLocale;
                        }

                        IssueNotificationManager.SaveOrUpdate(notification);
                        IssueNotificationManager.SendNewAssigneeNotification(notification);
                    }
                }
                else
                {
                    DataProviderManager.Provider.UpdateIssue(entity);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(LoggingManager.GetErrorMessageResource("SaveIssueError"), ex);
                return(false);
            }
        }
Пример #3
0
        /// <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);
        }