예제 #1
0
        public void ApplyTag(BllTopicTag tag, BllTopic topic)
        {
            var localtopic = Get(topic.Id);
            localtopic.TopicTags.Add(tag);

            _topicRepository.Update(localtopic.ToDalTopic());
        }
예제 #2
0
        public BllPost AddNewPost(string postContent, BllMembershipUser user, BllTopic topic, bool isTopicStarter)
        {
            var newPost = CreateNewPost(postContent, user, topic.Id, isTopicStarter);
            _postRepository.Insert(newPost.ToDalPost());
            _uow.Save();

            return newPost;
        }
예제 #3
0
 public BllPost AddNewPost(string postContent, BllMembershipUser user, BllTopic topic, bool isTopicStarter)
 {
     return _postService.AddNewPost(postContent, user, topic, isTopicStarter);
 }
예제 #4
0
 public void Add(BllTopic topic)
 {
     _topicRepository.Insert(topic.ToDalTopic());
     _uow.Save();
 }
예제 #5
0
 public void Update(BllTopic topic)
 {
     _topicRepository.Update(topic.ToDalTopic());
     _uow.Save();
 }
예제 #6
0
        public ActionResult Create(CreateEditTopicViewModel model)
        {
            if (IsPostingDisabled(User.Identity.Name))
            {
                ModelState.AddModelError("", "Administrator disabled posting for you.");
                return View(model);
            }

            if (ModelState.IsValid)
            {
                var category = _categoryService.Get(model.CategoryId);

                var user = _membershipServise.GetUserByEmail(User.Identity.Name);

                var createDate = DateTime.UtcNow;

                var existedTags = _topicTagService.GetAll().ToList();
                var newTagsStrings = model.Tags.Replace(", ",",").Split(',');
                var newTagsBll = new List<BllTopicTag>();

                foreach (var newTag in newTagsStrings)
                {
                    if (existedTags.Select(et => et.Tag).Contains(newTag))
                    {
                        newTagsBll.Add(existedTags.First(et => et.Tag == newTag));
                    }
                    else
                    {
                        var addTagToDbAndTopic = new BllTopicTag
                        {
                            Id = Guid.NewGuid(),
                            Tag = newTag
                        };
                        _topicTagService.Add(addTagToDbAndTopic);
                        newTagsBll.Add(addTagToDbAndTopic);
                    }

                }

                var topic = new BllTopic
                {
                    Id = Guid.NewGuid(),
                    Name = model.Title.Trim(),
                    CategoryId = category.Id,
                    CreateDate = DateTime.UtcNow,
                    Posts = new List<BllPost>(),
                    TopicTags = newTagsBll,
                    User = user
                };

                var firstPost = new BllPost()
                {
                    Id = Guid.NewGuid(),
                    DateCreated = createDate,
                    DateEdited = null,
                    IsTopicStarter = true,
                    PostContent = model.Content.Trim(),
                    ParentTopicId = topic.Id,
                    User = user
                };

                _topicService.Add(topic);
                _postService.Add(firstPost);

                return RedirectToAction("Details",new{id=topic.Id});
            }

            return View(model);
        }