コード例 #1
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.DemandCreate <Project>(null);

                DaoFactory.ProjectDao.Create(project);

                FactoryIndexer <ProjectsWrapper> .IndexAsync(project);
            }
            else
            {
                var oldProject = DaoFactory.ProjectDao.GetById(new List <int> {
                    project.ID
                }).FirstOrDefault();
                ProjectSecurity.DemandEdit(oldProject);

                DaoFactory.ProjectDao.Update(project);

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

                FactoryIndexer <ProjectsWrapper> .UpdateAsync(project);
            }

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

            return(project);
        }
コード例 #2
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 == null)
            {
                participant = GetSubscribers(message).Select(r => new Guid(r.ID)).ToList();
            }

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

            FactoryIndexer <DiscussionsWrapper> .IndexAsync(message);

            return(message);
        }
コード例 #3
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);
        }
コード例 #4
0
        public Task SaveOrUpdate(Task task, IEnumerable <int> attachedFileIds, bool notifyResponsible, bool isImport = false)
        {
            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();
                }

                if (!ProjectSecurity.IsInTeam(task.Project, responsible))
                {
                    ProjectSecurity.CreateSecurityException();
                }
            }

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

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

            task.Responsibles.RemoveAll(r => r.Equals(Guid.Empty));

            if (task.Deadline.Kind != DateTimeKind.Local && task.Deadline != DateTime.MinValue)
            {
                task.Deadline = TenantUtil.DateTimeFromUtc(task.Deadline);
            }

            if (task.StartDate.Kind != DateTimeKind.Local && task.StartDate != DateTime.MinValue)
            {
                task.StartDate = TenantUtil.DateTimeFromUtc(task.StartDate);
            }

            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.DemandCreate <Task>(task.Project);

                task = DaoFactory.TaskDao.Create(task);

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

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

                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)));

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

                task = DaoFactory.TaskDao.Update(task);
            }

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

            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);
        }