public IActionResult Post([FromBody] TopicFormModel model)
        {
            if (!_topicPermissions.IsAllowedToCreate(User.Identity.GetUserIdentity()))
            {
                return(Forbidden());
            }

            if (ModelState.IsValid)
            {
                if (!TopicStatus.IsStatusValid(model.Status))
                {
                    ModelState.AddModelError("Status", "Invalid Topic Status");
                }
                else
                {
                    var result = _topicManager.AddTopic(User.Identity.GetUserIdentity(), model);
                    if (result.Success)
                    {
                        return(Ok(result));
                    }
                }
            }

            return(BadRequest(ModelState));
        }
Beispiel #2
0
        public TransactionObject CreateNewTopic(NewTopicFormData ntfd)
        {
            TransactionObject response = new TransactionObject();

            try
            {
                Lesson selectedLesson = lessonManager.GetLesson(ntfd.LessonID);
                User   currentUser    = userManager.GetUser(ntfd.UserID);

                Topic newTopic = new Topic();
                newTopic.Name   = ntfd.TopicName;
                newTopic.Lesson = selectedLesson;
                selectedLesson.Topics.Add(newTopic);

                Post post = new Post();
                post.Topic = newTopic;
                newTopic.Posts.Add(post);

                post.Content  = ntfd.Content;
                post.PostDate = DateTime.Now;

                post.Lesson = selectedLesson;
                selectedLesson.Posts.Add(post);

                SentFeeds sf = currentUser.SentFeeds;

                if (sf == null)
                {
                    sf      = new SentFeeds();
                    sf.User = currentUser;
                    currentUser.SentFeeds = sf;
                }
                sf.SentTopics.Add(newTopic);
                newTopic.SentFeed = sf;

                sf.SentPosts.Add(post);
                post.SentFeed = sf;

                if (sf == null)
                {
                    sentFeedManager.AddSentFeed(sf);
                }


                topicManager.AddTopic(newTopic);
                postManager.AddPost(post);
                uow.Save();
                response.IsSuccess   = true;
                response.Explanation = newTopic.ID.ToString();
            }
            catch (Exception ex)
            {
                response.IsSuccess   = false;
                response.Explanation = base.GetExceptionMessage(ex);
            }
            return(response);
        }
Beispiel #3
0
        public DisplayTopic AddTopic(string name, string group = null, string description = null)
        {
            string me = whoami();

            if (string.IsNullOrEmpty(group))
            {
                group = MembershipHelper.DefaultGroup(me);
            }
            else
            {
                MembershipHelper.CheckMembership(group, me);
            }

            Topic topic = new Topic();

            topic.Name        = name;
            topic.Description = description;
            topic.MsgCount    = 0;
            topic.GroupID     = group;
            var newtopic = _topicManager.AddTopic(topic);

            return(new DisplayTopic(newtopic, IsFavouriteTopic(newtopic.Id)));
        }