Пример #1
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);
        }
Пример #2
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.DemandCreateMilestone(milestone.Project);
                milestone = _milestoneDao.Save(milestone);
            }
            else
            {
                var oldMilestone = _milestoneDao.GetById(new[] { milestone.ID }).FirstOrDefault();

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

                oldResponsible = oldMilestone.Responsible;

                ProjectSecurity.DemandEdit(milestone);
                milestone = _milestoneDao.Save(milestone);
            }


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

            return(milestone);
        }