public ActionResult Edit(TopicDto model)
        {
            var subscribers = this.GetValidSubscribers();
            if (subscribers == null || !subscribers.Any())
                return Json(false, "Modify the topic failure. there are not any subscriber.");

            model.Subscribers = (from subscriber in subscribers
                select new SubscriberDto
                {
                    Email = subscriber
                }).ToList();

            model.UpdatedBy = this.LoginUser.Identity.Name;
            this.EncodeInput(model);

            try
            {
                using (var service = ServiceLocator.Instance.Resolve<ITopicService>())
                {
                    service.ModifyTopic(model);
                }
            }
            catch (Exception)
            {
                return Json(false, "Modify the topic failure.");
            }

            return Json(true);
        }
Beispiel #2
0
        /// <summary>
        /// 建制 Mail
        /// </summary>
        /// <param name="topic">主题</param>
        /// <param name="stream">附件流</param>
        /// <returns>mail 管理者</returns>
        protected virtual MailManager BuildMail(TopicDto topic, Stream stream = null)
        {
            this.OnTopicBuilding(topic);

            var fileName = FilePathBuilder.BuildPath(
                string.Format("{0}-{1}", topic.TopicName, DateTime.Now.ToString("yyMMddHHmmss")),
                FileExtension.Excel2007);

            var subject = topic.Subject;
            var body = topic.Body;
            var mailTos = (from subscriber in topic.Subscribers
                select subscriber.Email).ToArray();

            if (stream != null)
            {
                var attachmemts = new List<Tuple<Stream, string>> {Tuple.Create(stream, fileName)};
                return new MailManager(subject, body, mailTos, attachmemts);
            }

            return new MailManager(subject, body, mailTos);
        }
Beispiel #3
0
        public void ModifyTopic(TopicDto topicDto, bool includeSubscriber = true)
        {
            var topic = this._topicRepository.GetByKey(topicDto.ID);
            if (topic == null)
                return;

            topic.Update(topicDto.TopicName, topicDto.Description, topicDto.Subject, topicDto.Body, topicDto.UpdatedBy);

            if (includeSubscriber)
            {
                this._topicRepository.RemoveSubscribers(topic.Subscribers);

                var subscribers = topicDto.Subscribers;
                if (subscribers != null)
                {
                    var taskSubcribers = (from subscriber in subscribers
                                          select new Subscriber(topic.ID, subscriber.Email));
                    topic.AddSubscribers(taskSubcribers.ToArray());
                }
            }

            this._topicRepository.Update(topic);
        }
Beispiel #4
0
 /// <summary>
 /// 建制 Topic, 发送邮件之前触发
 /// </summary>
 /// <param name="topic">主题</param>
 protected virtual void OnTopicBuilding(TopicDto topic)
 {
     topic.Body = HttpUtility.HtmlDecode(topic.Body);
 }
 private void EncodeInput(TopicDto topic)
 {
     topic.Body = HttpUtility.HtmlEncode(topic.Body);
 }
        private void CalibrateTopics(TopicDto topic)
        {
            var tasks = topic.TopicTasks.Where(this.CalibrateCore);
            if (!tasks.Any())
                return;

            this._filterTopics.Add(topic, tasks);
        }