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

            _topicRepository.Update(localtopic.ToDalTopic());
        }
Example #2
0
 public void Add(BllTopicTag topicTag)
 {
     _topicTagRepository.Insert(topicTag.ToDalTopicTag());
     _uow.Save();
 }
Example #3
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);
        }