Example #1
0
        public IHttpActionResult CreateNewTopic([FromBody] NewTopicFormData ntfd)
        {
            if (ModelState.IsValid)
            {
                var response = forumComplexManager.CreateNewTopic(ntfd);
                if (!(response.IsSuccess))
                {
                    return(BadRequest(response.Explanation));
                }

                return(Ok(int.Parse(response.Explanation)));
            }
            else
            {
                string message = string.Empty;
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var error in modelState.Errors)
                    {
                        message += error.ErrorMessage + "\n";
                    }
                }
                return(BadRequest(message));
            }
        }
Example #2
0
        public JsonResult CreateNewTopic(NewTopicFormData ntfd)
        {
            if (ModelState.IsValid)
            {
                var response = forumComplexManager.CreateNewTopic(ntfd);
                if (!(response.IsSuccess))
                {
                    return(Json(new { IsSuccess = false, Error = response.Explanation }));
                }

                return(Json(new { IsSuccess = true, ID = int.Parse(response.Explanation) }));
            }
            else
            {
                string message = string.Empty;
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var error in modelState.Errors)
                    {
                        message += error.ErrorMessage + "\n";
                    }
                }
                return(Json(new { IsSuccess = false, Error = message }));
            }
        }
Example #3
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);
        }