Example #1
0
        public TimeSpend SaveOrUpdate(TimeSpend timeSpend)
        {
            ProjectSecurity.DemandEdit(timeSpend);

            // check guest responsible
            if (ProjectSecurity.IsVisitor(timeSpend.Person))
            {
                ProjectSecurity.CreateGuestSecurityException();
            }

            timeSpend.CreateOn = DateTime.UtcNow;
            return(timeSpendDao.Save(timeSpend));
        }
Example #2
0
        public Milestone ChangeStatus(Milestone milestone, MilestoneStatus newStatus)
        {
            ProjectSecurity.DemandEdit(milestone);

            if (milestone == null)
            {
                throw new ArgumentNullException("milestone");
            }
            if (milestone.Project == null)
            {
                throw new Exception("Project can be null.");
            }
            if (milestone.Status == newStatus)
            {
                return(milestone);
            }

            switch (newStatus)
            {
            case MilestoneStatus.Closed:
                TimeLinePublisher.Milestone(milestone, EngineResource.ActionText_Closed, UserActivityConstants.ActivityActionType, UserActivityConstants.ImportantActivity);
                break;


            case MilestoneStatus.Open:
                TimeLinePublisher.Milestone(milestone, EngineResource.ActionText_Reopen, UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity);
                break;
            }


            milestone.Status          = newStatus;
            milestone.LastModifiedBy  = SecurityContext.CurrentAccount.ID;
            milestone.LastModifiedOn  = TenantUtil.DateTimeNow();
            milestone.StatusChangedOn = TenantUtil.DateTimeNow();

            var senders = new HashSet <Guid> {
                milestone.Project.Responsible, milestone.CreateBy, milestone.Responsible
            };

            senders.Remove(SecurityContext.CurrentAccount.ID);

            var recipientsProvider = NotifySource.Instance.GetRecipientsProvider();
            var recipients         = senders.Select(r => recipientsProvider.GetRecipient(r.ToString())).Where(r => r != null).ToList();

            if (newStatus == MilestoneStatus.Closed && !_engineFactory.DisableNotifications && recipients.Count != 0)
            {
                NotifyClient.Instance.SendAboutMilestoneClosing(recipients, milestone);
            }

            return(milestoneDao.Save(milestone));
        }
Example #3
0
        public virtual Project SaveOrUpdate(Project project, bool notifyManager, bool isImport)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            // check guest responsible
            if (ProjectSecurity.IsVisitor(project.Responsible))
            {
                ProjectSecurity.CreateGuestSecurityException();
            }

            project.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            project.LastModifiedOn = TenantUtil.DateTimeNow();

            if (project.ID == 0)
            {
                if (project.CreateBy == default(Guid))
                {
                    project.CreateBy = SecurityContext.CurrentAccount.ID;
                }
                if (project.CreateOn == default(DateTime))
                {
                    project.CreateOn = TenantUtil.DateTimeNow();
                }

                ProjectSecurity.DemandCreateProject();

                projectDao.Save(project);
            }
            else
            {
                var oldProject = projectDao.GetById(new[] { project.ID }).FirstOrDefault();
                ProjectSecurity.DemandEdit(oldProject);

                projectDao.Save(project);

                if (!project.Private)
                {
                    ResetTeamSecurity(oldProject);
                }
            }

            if (notifyManager && !factory.DisableNotifications && !project.Responsible.Equals(SecurityContext.CurrentAccount.ID))
            {
                NotifyClient.Instance.SendAboutResponsibleByProject(project.Responsible, project);
            }

            return(project);
        }
Example #4
0
        public Message SaveOrUpdate(Message message, bool notify, IEnumerable <Guid> participant,
                                    IEnumerable <int> fileIds = null)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            var isNew = message.ID == default(int);

            message.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            message.LastModifiedOn = TenantUtil.DateTimeNow();

            if (isNew)
            {
                if (message.CreateBy == default(Guid))
                {
                    message.CreateBy = SecurityContext.CurrentAccount.ID;
                }
                if (message.CreateOn == default(DateTime))
                {
                    message.CreateOn = TenantUtil.DateTimeNow();
                }

                ProjectSecurity.DemandCreate <Message>(message.Project);
                DaoFactory.MessageDao.Save(message);
            }
            else
            {
                ProjectSecurity.DemandEdit(message);
                DaoFactory.MessageDao.Save(message);
            }

            if (fileIds != null)
            {
                foreach (var fileId in fileIds)
                {
                    AttachFile(message, fileId);
                }
            }

            if (!participant.Any())
            {
                participant = GetSubscribers(message).Select(r => new Guid(r.ID)).ToList();
            }

            NotifyParticipiant(message, isNew, participant, GetFiles(message), notify);

            return(message);
        }
Example #5
0
        public Subtask Move(Subtask subtask, Task fromTask, Task toTask, IEnumerable <Participant> toTaskTeam)
        {
            if (subtask == null)
            {
                throw new Exception("subtask.Task");
            }
            if (subtask.Status == TaskStatus.Closed)
            {
                throw new Exception("subtask can't be closed");
            }
            if (fromTask == null)
            {
                throw new ArgumentNullException("task");
            }
            if (fromTask.Status == TaskStatus.Closed)
            {
                throw new Exception("task can't be closed");
            }
            if (toTask == null)
            {
                throw new ArgumentNullException("task");
            }
            if (toTask.Status == TaskStatus.Closed)
            {
                throw new Exception("task can't be closed");
            }

            ProjectSecurity.DemandEdit(fromTask, subtask);
            ProjectSecurity.DemandCreateSubtask(toTask);

            var oldResponsible = subtask.Responsible;

            if (oldResponsible != Guid.Empty && !toTaskTeam.Any(r => r.ID == oldResponsible))
            {
                subtask.Responsible = Guid.Empty;
            }

            subtask.Task = toTask.ID;

            subtask = DaoFactory.SubtaskDao.Save(subtask);

            var senders = GetSubscribers(toTask);

            if (!DisableNotifications && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutSubTaskMoved(senders, toTask, subtask);
            }

            return(subtask);
        }
Example #6
0
        public Milestone SaveOrUpdate(Milestone milestone, bool notifyResponsible, bool import)
        {
            if (milestone == null)
            {
                throw new ArgumentNullException("milestone");
            }
            if (milestone.Project == null)
            {
                throw new Exception("milestone.project is null");
            }

            milestone.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            milestone.LastModifiedOn = TenantUtil.DateTimeNow();

            var isNew = milestone.ID == default(int);//Task is new

            if (isNew)
            {
                if (milestone.CreateBy == default(Guid))
                {
                    milestone.CreateBy = SecurityContext.CurrentAccount.ID;
                }
                if (milestone.CreateOn == default(DateTime))
                {
                    milestone.CreateOn = TenantUtil.DateTimeNow();
                }

                ProjectSecurity.DemandCreateMilestone(milestone.Project);
                milestone = milestoneDao.Save(milestone);
                TimeLinePublisher.Milestone(milestone, import ? EngineResource.ActionText_Imported : EngineResource.ActionText_Create, UserActivityConstants.ContentActionType, UserActivityConstants.ImportantContent);
            }
            else
            {
                ProjectSecurity.DemandEdit(milestone);
                milestone = milestoneDao.Save(milestone);
                TimeLinePublisher.Milestone(milestone, EngineResource.ActionText_Update, UserActivityConstants.ActivityActionType, UserActivityConstants.ImportantActivity);
            }


            if (!milestone.Responsible.Equals(Guid.Empty))
            {
                NotifyMilestone(milestone, notifyResponsible, isNew);
            }


            var objectId = String.Format("{0}_{1}", milestone.UniqID, milestone.Project.ID);

            NotifySource.Instance.GetSubscriptionProvider().Subscribe(NotifyConstants.Event_NewCommentForMilestone, objectId, NotifySource.Instance.GetRecipientsProvider().GetRecipient(SecurityContext.CurrentAccount.ID.ToString()));
            return(milestone);
        }
Example #7
0
        public Message SaveOrUpdate(Message message, bool notify, IEnumerable <Guid> participant, IEnumerable <int> fileIds, bool isImport)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            var isNew = message.ID == default(int);

            message.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            message.LastModifiedOn = TenantUtil.DateTimeNow();

            if (isNew)
            {
                if (message.CreateBy == default(Guid))
                {
                    message.CreateBy = SecurityContext.CurrentAccount.ID;
                }
                if (message.CreateOn == default(DateTime))
                {
                    message.CreateOn = TenantUtil.DateTimeNow();
                }

                ProjectSecurity.DemandCreateMessage(message.Project);
                _messageDao.Save(message);
                TimeLinePublisher.Message(message, isImport ? EngineResource.ActionText_Imported : EngineResource.ActionText_Create, UserActivityConstants.ContentActionType, UserActivityConstants.NormalContent);
            }
            else
            {
                ProjectSecurity.DemandEdit(message);
                _messageDao.Save(message);
                TimeLinePublisher.Message(message, EngineResource.ActionText_Update, UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity, true);
            }

            var fileEngine = _engineFactory.GetFileEngine();

            if (fileIds != null)
            {
                foreach (var fileId in fileIds)
                {
                    fileEngine.AttachFileToMessage(message.ID, fileId);
                }
            }

            NotifyParticipiant(message, isNew, participant, fileEngine.GetMessageFiles(message), notify);

            return(message);
        }
Example #8
0
        public void Delete(Milestone milestone)
        {
            if (milestone == null)
            {
                throw new ArgumentNullException("milestone");
            }

            ProjectSecurity.DemandEdit(milestone);
            _milestoneDao.Delete(milestone.ID);

            var users = new HashSet <Guid> {
                milestone.Project.Responsible, milestone.Responsible
            };

            NotifyClient.Instance.SendAboutMilestoneDeleting(users, milestone);
        }
Example #9
0
        public Task ChangeStatus(Task task, TaskStatus newStatus)
        {
            ProjectSecurity.DemandEdit(task);

            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (task.Project == null)
            {
                throw new Exception("Project can be null.");
            }
            if (task.Status == newStatus)
            {
                return(task);
            }

            var senders = GetSubscribers(task);

            if (newStatus == TaskStatus.Closed && !factory.DisableNotifications && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutTaskClosing(senders, task);
            }

            if (newStatus == TaskStatus.Open && !factory.DisableNotifications && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutTaskResumed(senders, task);
            }

            task.Status          = newStatus;
            task.LastModifiedBy  = SecurityContext.CurrentAccount.ID;
            task.LastModifiedOn  = TenantUtil.DateTimeNow();
            task.StatusChangedOn = TenantUtil.DateTimeNow();

            //subtask
            if (newStatus == TaskStatus.Closed)
            {
                if (!task.Responsibles.Any())
                {
                    task.Responsibles.Add(SecurityContext.CurrentAccount.ID);
                }

                subtaskDao.CloseAllSubtasks(task);
            }

            return(taskDao.Save(task));
        }
Example #10
0
        public Milestone ChangeStatus(Milestone milestone, MilestoneStatus newStatus)
        {
            ProjectSecurity.DemandEdit(milestone);

            if (milestone == null)
            {
                throw new ArgumentNullException("milestone");
            }
            if (milestone.Project == null)
            {
                throw new Exception("Project can be null.");
            }
            if (milestone.Status == newStatus)
            {
                return(milestone);
            }
            if (milestone.Project.Status == ProjectStatus.Closed)
            {
                throw new Exception(EngineResource.ProjectClosedError);
            }
            if (milestone.ActiveTaskCount != 0 && newStatus == MilestoneStatus.Closed)
            {
                throw new Exception("Can not close a milestone with open tasks");
            }

            milestone.Status          = newStatus;
            milestone.LastModifiedBy  = SecurityContext.CurrentAccount.ID;
            milestone.LastModifiedOn  = TenantUtil.DateTimeNow();
            milestone.StatusChangedOn = TenantUtil.DateTimeNow();

            var senders = new HashSet <Guid> {
                milestone.Project.Responsible, milestone.CreateBy, milestone.Responsible
            };

            if (newStatus == MilestoneStatus.Closed && !false && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutMilestoneClosing(senders, milestone);
            }

            if (newStatus == MilestoneStatus.Open && !false && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutMilestoneResumed(senders, milestone);
            }

            return(DaoFactory.MilestoneDao.Save(milestone));
        }
Example #11
0
        public Subtask ChangeStatus(Task task, Subtask subtask, TaskStatus newStatus)
        {
            if (subtask == null)
            {
                throw new Exception("subtask.Task");
            }
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (task.Status == TaskStatus.Closed)
            {
                throw new Exception("task can't be closed");
            }

            if (subtask.Status == newStatus)
            {
                return(subtask);
            }

            ProjectSecurity.DemandEdit(task, subtask);

            subtask.Status          = newStatus;
            subtask.LastModifiedBy  = SecurityContext.CurrentAccount.ID;
            subtask.LastModifiedOn  = TenantUtil.DateTimeNow();
            subtask.StatusChangedOn = TenantUtil.DateTimeNow();

            if (subtask.Responsible.Equals(Guid.Empty))
            {
                subtask.Responsible = SecurityContext.CurrentAccount.ID;
            }

            var senders = GetSubscribers(task);

            if (task.Status != TaskStatus.Closed && newStatus == TaskStatus.Closed && !DisableNotifications && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutSubTaskClosing(senders, task, subtask);
            }

            if (task.Status != TaskStatus.Closed && newStatus == TaskStatus.Open && !DisableNotifications && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutSubTaskResumed(senders, task, subtask);
            }

            return(DaoFactory.SubtaskDao.Save(subtask));
        }
Example #12
0
        public Project ChangeStatus(Project project, ProjectStatus status)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            ProjectSecurity.DemandEdit(project);

            project.LastModifiedBy  = SecurityContext.CurrentAccount.ID;
            project.LastModifiedOn  = TenantUtil.DateTimeNow();
            project.StatusChangedOn = DateTime.Now;
            project.Status          = status;

            projectDao.Save(project);

            return(project);
        }
Example #13
0
        public virtual Project SaveOrUpdate(Project project, bool notifyManager, bool isImport)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            project.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            project.LastModifiedOn = TenantUtil.DateTimeNow();

            if (project.ID == 0)
            {
                if (project.CreateBy == default(Guid))
                {
                    project.CreateBy = SecurityContext.CurrentAccount.ID;
                }
                if (project.CreateOn == default(DateTime))
                {
                    project.CreateOn = TenantUtil.DateTimeNow();
                }

                ProjectSecurity.DemandCreateProject();
                projectDao.Save(project);

                TimeLinePublisher.Project(project, isImport ? EngineResource.ActionText_Imported: EngineResource.ActionText_Create, UserActivityConstants.ContentActionType, UserActivityConstants.Max);
            }
            else
            {
                ProjectSecurity.DemandEdit(project);
                projectDao.Save(project);

                if (!project.Private)
                {
                    ResetTeamSecurity(project);
                }

                TimeLinePublisher.Project(project, EngineResource.ActionText_Update, UserActivityConstants.ActivityActionType, UserActivityConstants.Max);
            }

            if (notifyManager && !_factory.DisableNotifications && !project.Responsible.Equals(SecurityContext.CurrentAccount.ID))
            {
                NotifyClient.Instance.SendAboutResponsibleByProject(project.Responsible, project);
            }

            return(project);
        }
Example #14
0
        public void Delete(Task task)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            ProjectSecurity.DemandEdit(task);
            task.Links.ForEach(link => taskDao.RemoveLink(link));
            task.SubTasks.ForEach(subTask => subtaskDao.Delete(subTask.ID));
            taskDao.Delete(task.ID);

            var recipients = GetSubscribers(task);

            if (recipients.Count != 0)
            {
                NotifyClient.Instance.SendAboutTaskDeleting(recipients, task);
            }
        }
Example #15
0
        public virtual void Delete(int projectId)
        {
            var project = GetByID(projectId);

            if (project == null)
            {
                return;
            }

            ProjectSecurity.DemandEdit(project);

            factory.GetFileEngine().RemoveRoot(projectId);

            projectDao.Delete(projectId);

            NotifyClient.Instance.SendAboutProjectDeleting(new HashSet <Guid> {
                project.Responsible
            }, project);
        }
Example #16
0
        public void Delete(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (message.Project == null)
            {
                throw new Exception("Project");
            }

            ProjectSecurity.DemandEdit(message);
            TimeLinePublisher.Message(message, EngineResource.ActionText_Delete, UserActivityConstants.ActivityActionType, UserActivityConstants.SmallActivity);

            _messageDao.Delete(message.ID);

            String objectID = String.Format("{0}_{1}", message.UniqID, message.Project.ID);

            NotifySource.Instance.GetSubscriptionProvider().UnSubscribe(NotifyConstants.Event_NewCommentForMessage, objectID);
        }
Example #17
0
        public void Delete(Subtask subtask, Task task)
        {
            if (subtask == null)
            {
                throw new ArgumentNullException("subtask");
            }
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            ProjectSecurity.DemandEdit(task, subtask);
            DaoFactory.SubtaskDao.Delete(subtask.ID);

            var recipients = GetSubscribers(task);

            if (recipients.Any())
            {
                NotifyClient.Instance.SendAboutSubTaskDeleting(recipients, task, subtask);
            }
        }
Example #18
0
        public void AddLink(Task parentTask, Task dependentTask, TaskLinkType linkType)
        {
            CheckLink(parentTask, dependentTask, linkType);

            var link = new TaskLink
            {
                ParentTaskId     = parentTask.ID,
                DependenceTaskId = dependentTask.ID,
                LinkType         = linkType
            };

            if (taskDao.IsExistLink(link))
            {
                throw new Exception("link already exist");
            }

            ProjectSecurity.DemandEdit(dependentTask);
            ProjectSecurity.DemandEdit(parentTask);

            taskDao.AddLink(link);
        }
Example #19
0
        public void Delete(Task task)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            ProjectSecurity.DemandEdit(task);
            task.SubTasks.ForEach(subTask => _subtaskDao.Delete(subTask.ID));
            _taskDao.Delete(task.ID);

            var milestone = task.Milestone != 0 ? _milestoneDao.GetById(task.Milestone) : null;

            TimeLinePublisher.Task(task, milestone, EngineResource.ActionText_Delete, UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity);

            var objectID   = task.UniqID + "_" + task.Project.ID;
            var recipients = NotifySource.Instance.GetSubscriptionProvider().GetRecipients(NotifyConstants.Event_NewCommentForTask, objectID)
                             .Where(r => r.ID != SecurityContext.CurrentAccount.ID.ToString()).ToList();

            if (recipients.Count != 0)
            {
                NotifyClient.Instance.SendAboutTaskDeleting(recipients, task);
            }
        }
        public void Delete(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (message.Project == null)
            {
                throw new Exception("Project");
            }

            ProjectSecurity.DemandEdit(message);

            messageDao.Delete(message.ID);

            var recipients = GetSubscribers(message);

            if (recipients.Any() && !engineFactory.DisableNotifications)
            {
                NotifyClient.Instance.SendAboutMessageDeleting(recipients, message);
            }

            UnSubscribe(message);
        }
Example #21
0
        public Subtask SaveOrUpdate(Subtask subtask, Task task)
        {
            if (subtask == null)
            {
                throw new Exception("subtask.Task");
            }
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (task.Status == TaskStatus.Closed)
            {
                throw new Exception("task can't be closed");
            }

            var isNew = subtask.ID == default(int); //Task is new

            subtask.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            subtask.LastModifiedOn = TenantUtil.DateTimeNow();

            if (isNew)
            {
                if (subtask.CreateBy == default(Guid))
                {
                    subtask.CreateBy = SecurityContext.CurrentAccount.ID;
                }
                if (subtask.CreateOn == default(DateTime))
                {
                    subtask.CreateOn = TenantUtil.DateTimeNow();
                }

                ProjectSecurity.DemandEdit(task);
                subtask = _subtaskDao.Save(subtask);
                TimeLinePublisher.Subtask(subtask, task, EngineResource.ActionText_Create,
                                          UserActivityConstants.ContentActionType, UserActivityConstants.NormalContent);
            }
            else
            {
                //changed task
                ProjectSecurity.DemandEdit(task, GetById(subtask.ID));
                subtask = _subtaskDao.Save(subtask);
                TimeLinePublisher.Subtask(subtask, task, EngineResource.ActionText_Update,
                                          UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity);
            }

            var objectID   = task.UniqID + "_" + task.Project.ID;
            var recipients = NotifySource.Instance.GetSubscriptionProvider().GetRecipients(NotifyConstants.Event_NewCommentForTask, objectID)
                             .Where(r => r.ID != SecurityContext.CurrentAccount.ID.ToString() && r.ID != subtask.Responsible.ToString() && r.ID != subtask.CreateBy.ToString())
                             .ToList();

            NotifySubtask(task, subtask, recipients, isNew);

            var senders = new HashSet <Guid> {
                subtask.Responsible, subtask.CreateBy
            };

            senders.Remove(Guid.Empty);

            foreach (var sender in senders)
            {
                _factory.GetTaskEngine().SubscribeToTask(task, sender);
            }

            return(subtask);
        }
Example #22
0
        public Task ChangeStatus(Task task, CustomTaskStatus newStatus)
        {
            ProjectSecurity.DemandEdit(task);

            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (task.Project == null)
            {
                throw new Exception("Project can't be null.");
            }
            if (task.Project.Status == ProjectStatus.Closed)
            {
                throw new Exception(EngineResource.ProjectClosedError);
            }

            if (task.Status == newStatus.StatusType && task.CustomTaskStatus == newStatus.Id)
            {
                return(task);
            }

            var status       = StatusEngine.Get().FirstOrDefault(r => r.Id == newStatus.Id);
            var cannotChange =
                status != null &&
                status.Available.HasValue && !status.Available.Value &&
                task.CreateBy != SecurityContext.CurrentAccount.ID &&
                task.Project.Responsible != SecurityContext.CurrentAccount.ID &&
                !ProjectSecurity.CurrentUserAdministrator;

            if (cannotChange)
            {
                ProjectSecurity.CreateSecurityException();
            }


            var senders = GetSubscribers(task);

            if (newStatus.StatusType == TaskStatus.Closed && !DisableNotifications && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutTaskClosing(senders, task);
            }

            if (newStatus.StatusType == TaskStatus.Open && !DisableNotifications && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutTaskResumed(senders, task);
            }

            task.Status           = newStatus.StatusType;
            task.CustomTaskStatus = newStatus.Id < 0 ? null : (int?)newStatus.Id;
            task.LastModifiedBy   = SecurityContext.CurrentAccount.ID;
            task.LastModifiedOn   = TenantUtil.DateTimeNow();
            task.StatusChangedOn  = TenantUtil.DateTimeNow();

            //subtask
            if (newStatus.StatusType == TaskStatus.Closed)
            {
                if (!task.Responsibles.Any())
                {
                    task.Responsibles.Add(SecurityContext.CurrentAccount.ID);
                }

                DaoFactory.SubtaskDao.CloseAllSubtasks(task);
                foreach (var subTask in task.SubTasks)
                {
                    subTask.Status = TaskStatus.Closed;
                }
            }

            return(DaoFactory.TaskDao.Update(task));
        }
Example #23
0
        public Subtask SaveOrUpdate(Subtask subtask, Task task)
        {
            if (subtask == null)
            {
                throw new Exception("subtask.Task");
            }
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (task.Status == TaskStatus.Closed)
            {
                throw new Exception("task can't be closed");
            }

            // check guest responsible
            if (ProjectSecurity.IsVisitor(subtask.Responsible))
            {
                ProjectSecurity.CreateGuestSecurityException();
            }

            var isNew          = subtask.ID == default(int); //Task is new
            var oldResponsible = Guid.Empty;

            subtask.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            subtask.LastModifiedOn = TenantUtil.DateTimeNow();

            if (isNew)
            {
                if (subtask.CreateBy == default(Guid))
                {
                    subtask.CreateBy = SecurityContext.CurrentAccount.ID;
                }
                if (subtask.CreateOn == default(DateTime))
                {
                    subtask.CreateOn = TenantUtil.DateTimeNow();
                }

                ProjectSecurity.DemandEdit(task);
                subtask = DaoFactory.SubtaskDao.Save(subtask);
            }
            else
            {
                var oldSubtask = DaoFactory.SubtaskDao.GetById(new[] { subtask.ID }).First();

                if (oldSubtask == null)
                {
                    throw new ArgumentNullException("subtask");
                }

                oldResponsible = oldSubtask.Responsible;

                //changed task
                ProjectSecurity.DemandEdit(task, oldSubtask);
                subtask = DaoFactory.SubtaskDao.Save(subtask);
            }

            NotifySubtask(task, subtask, isNew, oldResponsible);

            var senders = new HashSet <Guid> {
                subtask.Responsible, subtask.CreateBy
            };

            senders.Remove(Guid.Empty);

            foreach (var sender in senders)
            {
                Subscribe(task, sender);
            }

            return(subtask);
        }
Example #24
0
        public Task SaveOrUpdate(Task task, IEnumerable <int> attachedFileIds, bool notifyResponsible, bool isImport)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (task.Project == null)
            {
                throw new Exception("task.Project");
            }

            var milestone            = task.Milestone != 0 ? _milestoneDao.GetById(task.Milestone) : null;
            var milestoneResponsible = milestone != null ? milestone.Responsible : Guid.Empty;

            task.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            task.LastModifiedOn = TenantUtil.DateTimeNow();

            var isNew = task.ID == default(int); //Task is new

            if (isNew)
            {
                if (task.CreateBy == default(Guid))
                {
                    task.CreateBy = SecurityContext.CurrentAccount.ID;
                }
                if (task.CreateOn == default(DateTime))
                {
                    task.CreateOn = TenantUtil.DateTimeNow();
                }

                ProjectSecurity.DemandCreateTask(task.Project);
                task = _taskDao.Save(task);

                TimeLinePublisher.Task(task, milestone,
                                       isImport ? EngineResource.ActionText_Imported : EngineResource.ActionText_Create,
                                       UserActivityConstants.ContentActionType, UserActivityConstants.NormalContent,
                                       true);
            }
            else
            {
                //changed task
                ProjectSecurity.DemandEdit(GetByID(new[] { task.ID }).FirstOrDefault());
                task = _taskDao.Save(task);
                TimeLinePublisher.Task(task, milestone, EngineResource.ActionText_Update, UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity);
            }

            if (attachedFileIds != null && attachedFileIds.Count() > 0)
            {
                foreach (var attachedFileId in attachedFileIds)
                {
                    _fileEngine.AttachFileToTask(task.ID, attachedFileId);
                }
            }

            //Object id for sender
            var objectID = task.UniqID + "_" + task.Project.ID;

            var senders = new HashSet <Guid>(task.Responsibles)
            {
                task.Project.Responsible, milestoneResponsible, task.CreateBy, task.Responsible
            };

            senders.Remove(Guid.Empty);

            var subscriptionProvider = NotifySource.Instance.GetSubscriptionProvider();
            var recipientsProvider   = NotifySource.Instance.GetRecipientsProvider();

            var recipients = senders
                             .Select(r => recipientsProvider.GetRecipient(r.ToString()))
                             .Where(r => r != null && !IsUnsubscribedToTask(task, r.ID))
                             .ToList();

            foreach (var recipient in recipients)
            {
                subscriptionProvider.Subscribe(NotifyConstants.Event_NewCommentForTask, objectID, recipient);
            }

            recipients.RemoveAll(r => r.ID == SecurityContext.CurrentAccount.ID.ToString());

            if (isNew)
            {
                NotifyTaskCreated(task, recipients, milestoneResponsible, notifyResponsible);
            }
            else
            {
                NotifyTaskEdited(task, notifyResponsible);
            }


            return(task);
        }
Example #25
0
        public Milestone SaveOrUpdate(Milestone milestone, bool notifyResponsible, bool import)
        {
            if (milestone == null)
            {
                throw new ArgumentNullException("milestone");
            }
            if (milestone.Project == null)
            {
                throw new Exception("milestone.project is null");
            }
            if (milestone.Responsible.Equals(Guid.Empty))
            {
                throw new Exception("milestone.responsible is empty");
            }

            // check guest responsible
            if (ProjectSecurity.IsVisitor(milestone.Responsible))
            {
                ProjectSecurity.CreateGuestSecurityException();
            }

            milestone.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            milestone.LastModifiedOn = TenantUtil.DateTimeNow();

            var isNew          = milestone.ID == default(int);//Task is new
            var oldResponsible = Guid.Empty;

            if (isNew)
            {
                if (milestone.CreateBy == default(Guid))
                {
                    milestone.CreateBy = SecurityContext.CurrentAccount.ID;
                }
                if (milestone.CreateOn == default(DateTime))
                {
                    milestone.CreateOn = TenantUtil.DateTimeNow();
                }

                ProjectSecurity.DemandCreate <Milestone>(milestone.Project);
                milestone = DaoFactory.MilestoneDao.Save(milestone);
            }
            else
            {
                var oldMilestone = DaoFactory.MilestoneDao.GetById(new[] { milestone.ID }).FirstOrDefault();

                if (oldMilestone == null)
                {
                    throw new ArgumentNullException("milestone");
                }

                oldResponsible = oldMilestone.Responsible;

                ProjectSecurity.DemandEdit(milestone);
                milestone = DaoFactory.MilestoneDao.Save(milestone);
            }


            if (!milestone.Responsible.Equals(Guid.Empty))
            {
                NotifyMilestone(milestone, notifyResponsible, isNew, oldResponsible);
            }

            FactoryIndexer <MilestonesWrapper> .IndexAsync(milestone);

            return(milestone);
        }
Example #26
0
        public Task SaveOrUpdate(Task task, IEnumerable <int> attachedFileIds, bool notifyResponsible, bool isImport)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (task.Project == null)
            {
                throw new Exception("task.Project");
            }

            // check guests responsibles
            foreach (var responsible in task.Responsibles)
            {
                if (ProjectSecurity.IsVisitor(responsible))
                {
                    ProjectSecurity.CreateGuestSecurityException();
                }
            }

            var milestone            = task.Milestone != 0 ? milestoneDao.GetById(task.Milestone) : null;
            var milestoneResponsible = milestone != null ? milestone.Responsible : Guid.Empty;

            var removeResponsibles   = new List <Guid>();
            var inviteToResponsibles = new List <Guid>();

            task.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            task.LastModifiedOn = TenantUtil.DateTimeNow();

            var isNew = task.ID == default(int); //Task is new

            if (isNew)
            {
                if (task.CreateBy == default(Guid))
                {
                    task.CreateBy = SecurityContext.CurrentAccount.ID;
                }
                if (task.CreateOn == default(DateTime))
                {
                    task.CreateOn = TenantUtil.DateTimeNow();
                }

                ProjectSecurity.DemandCreateTask(task.Project);

                task = taskDao.Save(task);

                inviteToResponsibles.AddRange(task.Responsibles.Distinct());
            }
            else
            {
                var oldTask = GetByID(new[] { task.ID }).FirstOrDefault();

                if (oldTask == null)
                {
                    throw new ArgumentNullException("task");
                }

                var newResponsibles = task.Responsibles.Distinct().ToList();
                var oldResponsibles = oldTask.Responsibles.Distinct().ToList();

                removeResponsibles.AddRange(oldResponsibles.Where(p => !newResponsibles.Contains(p)));
                inviteToResponsibles.AddRange(newResponsibles.Where(participant => !oldResponsibles.Contains(participant)));

                //changed task
                ProjectSecurity.DemandEdit(oldTask);

                task = taskDao.Save(task);
            }

            if (attachedFileIds != null && attachedFileIds.Any())
            {
                foreach (var attachedFileId in attachedFileIds)
                {
                    AttachFile(task, attachedFileId, false);
                }
            }

            var senders = new HashSet <Guid>(task.Responsibles)
            {
                task.Project.Responsible, milestoneResponsible, task.CreateBy
            };

            senders.Remove(Guid.Empty);

            foreach (var subscriber in senders)
            {
                Subscribe(task, subscriber);
            }

            inviteToResponsibles.RemoveAll(r => r.Equals(Guid.Empty));
            removeResponsibles.RemoveAll(r => r.Equals(Guid.Empty));

            NotifyTask(task, inviteToResponsibles, removeResponsibles, isNew, notifyResponsible);

            return(task);
        }
Example #27
0
        public Task ChangeStatus(Task task, TaskStatus newStatus)
        {
            ProjectSecurity.DemandEdit(task);

            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (task.Project == null)
            {
                throw new Exception("Project can be null.");
            }
            if (task.Status == newStatus)
            {
                return(task);
            }

            var objectID  = String.Format("{0}_{1}", task.UniqID, task.Project.ID);
            var milestone = task.Milestone != 0 ? _milestoneDao.GetById(task.Milestone) : null;

            switch (newStatus)
            {
            case TaskStatus.Closed:
                TimeLinePublisher.Task(task, milestone, EngineResource.ActionText_Closed, UserActivityConstants.ActivityActionType, UserActivityConstants.ImportantActivity);
                break;

            case TaskStatus.Open:
                TimeLinePublisher.Task(task, milestone, task.Status == TaskStatus.Closed ? EngineResource.ActionText_Reopen : EngineResource.ActionText_Accept, UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity);
                break;
            }

            var senders = NotifySource.Instance.GetSubscriptionProvider().GetRecipients(NotifyConstants.Event_NewCommentForTask, objectID).ToList();

            senders.RemoveAll(r => r.ID == SecurityContext.CurrentAccount.ID.ToString());

            if (newStatus == TaskStatus.Closed && !_factory.DisableNotifications && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutTaskClosing(senders, task);
            }

            if (newStatus == TaskStatus.Open && !_factory.DisableNotifications && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutTaskResumed(senders, task);
            }

            _taskDao.TaskTrace(task.ID, (Guid)CallContext.GetData("CURRENT_ACCOUNT"), TenantUtil.DateTimeNow(), newStatus);

            task.Status          = newStatus;
            task.LastModifiedBy  = SecurityContext.CurrentAccount.ID;
            task.LastModifiedOn  = TenantUtil.DateTimeNow();
            task.StatusChangedOn = TenantUtil.DateTimeNow();

            //subtask
            if (newStatus == TaskStatus.Closed)
            {
                if (task.Responsible.Equals(Guid.Empty))
                {
                    task.Responsible = SecurityContext.CurrentAccount.ID;
                }

                _subtaskDao.CloseAllSubtasks(task);
            }

            return(_taskDao.Save(task));
        }