Beispiel #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);
        }
Beispiel #2
0
        public List <ReportTemplate> GetAutoTemplates()
        {
            if (ProjectSecurity.IsVisitor(SecurityContext.CurrentAccount.ID))
            {
                throw new SecurityException("Access denied.");
            }

            return(DaoFactory.ReportDao.GetAutoTemplates());
        }
Beispiel #3
0
        public ReportTemplate SaveTemplate(ReportTemplate template)
        {
            if (ProjectSecurity.IsVisitor(SecurityContext.CurrentAccount.ID))
            {
                throw new SecurityException("Access denied.");
            }

            return(DaoFactory.ReportDao.SaveTemplate(template));
        }
Beispiel #4
0
        public ReportFile GetByFileId(int fileid)
        {
            if (ProjectSecurity.IsVisitor(SecurityContext.CurrentAccount.ID))
            {
                throw new SecurityException("Access denied.");
            }

            return(DaoFactory.ReportDao.GetByFileId(fileid));
        }
Beispiel #5
0
        public IEnumerable <ReportFile> Get()
        {
            if (ProjectSecurity.IsVisitor(SecurityContext.CurrentAccount.ID))
            {
                throw new SecurityException("Access denied.");
            }

            return(DaoFactory.ReportDao.Get());
        }
Beispiel #6
0
        public void DeleteTemplate(int id)
        {
            if (ProjectSecurity.IsVisitor(SecurityContext.CurrentAccount.ID))
            {
                throw new SecurityException("Access denied.");
            }

            DaoFactory.ReportDao.DeleteTemplate(id);
        }
Beispiel #7
0
        public ReportTemplate GetTemplate(int id)
        {
            if (ProjectSecurity.IsVisitor(SecurityContext.CurrentAccount.ID))
            {
                throw new SecurityException("Access denied.");
            }

            return(reportDao.GetTemplate(id));
        }
Beispiel #8
0
        public List <ReportTemplate> GetTemplates(Guid userId)
        {
            if (ProjectSecurity.IsVisitor(SecurityContext.CurrentAccount.ID))
            {
                throw new SecurityException("Access denied.");
            }

            return(reportDao.GetTemplates(userId));
        }
Beispiel #9
0
        public void Remove(ReportFile report)
        {
            if (ProjectSecurity.IsVisitor(SecurityContext.CurrentAccount.ID))
            {
                throw new SecurityException("Access denied.");
            }

            DaoFactory.ReportDao.Remove(report);

            FileEngine.MoveToTrash(report.FileId);
        }
Beispiel #10
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));
        }
Beispiel #11
0
        public ReportTemplate SaveTemplate(ReportTemplate template)
        {
            if (template == null)
            {
                throw new ArgumentNullException("template");
            }

            if (ProjectSecurity.IsVisitor(SecurityContext.CurrentAccount.ID))
            {
                throw new SecurityException("Access denied.");
            }

            if (template.CreateOn == default(DateTime))
            {
                template.CreateOn = TenantUtil.DateTimeNow();
            }
            if (template.CreateBy.Equals(Guid.Empty))
            {
                template.CreateBy = SecurityContext.CurrentAccount.ID;
            }
            return(reportDao.SaveTemplate(template));
        }
Beispiel #12
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);
        }
Beispiel #13
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);
        }
        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);
        }