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.DemandCreateMessage(message.Project);
                messageDao.Save(message);
            }
            else
            {
                ProjectSecurity.DemandEdit(message);
                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);
        }
Beispiel #2
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);
        }