Пример #1
0
 public bool IsNewTopicValid(NewTopicBindingModel bind)
 {
     if (bind.Title.Length > 30 || bind.Content.Length > 5000)
     {
         return(false);
     }
     return(true);
 }
Пример #2
0
 public bool IsValidNewTopicModel(NewTopicBindingModel model)
 {
     if (model.Title.Length > 30)
     {
         return(false);
     }
     if (model.Content.Length > 5000)
     {
         return(false);
     }
     return(true);
 }
Пример #3
0
        public void CreateNewTopic(HttpSession session, NewTopicBindingModel ntbm)
        {
            Topic topic = new Topic();

            topic.Author      = this.signInManagerService.GetAuthenticatedUser(session);
            topic.Content     = ntbm.Content;
            topic.PublishDate = DateTime.Now;
            topic.Title       = ntbm.Title;
            topic.Category    = this.Context.Categories.Where(cn => cn.Name == ntbm.CategoryName).FirstOrDefault();

            this.Context.Topics.Add(topic);
            this.Context.SaveChanges();
        }
Пример #4
0
        public bool IsNewTopicBindingModelValid(NewTopicBindingModel ntbm)
        {
            if (ntbm.Title.Length > 30)
            {
                return(false);
            }

            if (this.Context.Categories.Where(cn => cn.Name == ntbm.CategoryName).Count() == 0)
            {
                return(false);
            }

            return(true);
        }
Пример #5
0
        public void AddNewTopic(NewTopicBindingModel model, User currentUser)
        {
            Category category = this.context.Categories.FirstOrDefault(cat => cat.Name == model.Category);
            Topic    topic    = new Topic()
            {
                Title       = model.Title,
                Category    = category,
                Author      = currentUser,
                Content     = model.Content,
                PublishDate = DateTime.Now
            };

            this.context.Topics.Add(topic);
            this.context.Commit();
        }
Пример #6
0
        public void AddNewTopic(NewTopicBindingModel bind, User user)
        {
            Category category = Context.Categories.FirstOrDefault(c => c.Name == bind.Category);
            Topic    topic    = new Topic()
            {
                Author        = user,
                Content       = bind.Content,
                Title         = bind.Title,
                PublishedDate = DateTime.Now,
                Category      = category
            };

            Context.Topics.Add(topic);
            Context.SaveChanges();
        }
        internal void AddNewTopic(NewTopicBindingModel bind, User user)
        {
            Category category = this.Context.Categories.FirstOrDefault(cat => cat.Name == bind.Category);

            Topic topic = new Topic()
            {
                Author      = user,
                Title       = bind.Title,
                Content     = bind.Content,
                PublishDate = DateTime.Now,
                Category    = category
            };

            this.Context.Topics.Add(topic);
            this.Context.SaveChanges();
        }
Пример #8
0
        public void AddNewTopicFromBind(NewTopicBindingModel model, User author)
        {
            var category = this.Context.Categories.FirstOrDefault(x => x.Name == model.Category);

            var topic = new Topic()
            {
                Title       = model.Title,
                Content     = model.Content,
                Category    = category,
                Author      = author,
                PublishDate = DateTime.Now.Date
            };

            this.Context.Topics.Add(topic);
            this.Context.SaveChanges();
        }
Пример #9
0
        public IActionResult New(HttpSession session, HttpResponse response,
                                 NewTopicBindingModel ntbm)
        {
            if (!AuthenticationManager.IsAuthenticated(session))
            {
                this.Redirect(response, "/forum/login");
                return(null);
            }

            var user = AuthenticationManager.GetAuthenticatedUser(session.Id);

            service.AddNewTopicFromBind(ntbm, user);

            this.Redirect(response, "/home/topics");
            return(null);
        }
Пример #10
0
        public void New(HttpResponse response, HttpSession session, NewTopicBindingModel model)
        {
            User currentUser = AuthenticationManager.GetAuthenticatedUser(session.Id);

            if (currentUser == null)
            {
                Redirect(response, "/home/topics");
                return;
            }

            if (!this.service.IsValidNewTopicModel(model))
            {
                Redirect(response, "/topics/new");
                return;
            }

            this.service.AddNewTopic(model, currentUser);
            Redirect(response, "/home/topics");
        }
Пример #11
0
        public void New(HttpSession session, HttpResponse response, NewTopicBindingModel bind)
        {
            User user = AuthenticatedManager.GetAuthenticatedUser(session.Id);

            if (user == null)
            {
                this.Redirect(response, "/home/topics");
                return;
            }
            if (!service.IsNewTopicValid(bind))
            {
                this.Redirect(response, "/topics/new");
                return;
            }
            this.service.IsNewTopicValid(bind);
            this.service.AddNewTopic(bind, user);

            this.Redirect(response, "/home/topics");
        }
Пример #12
0
        public IActionResult <TopicsNewViewModel> New(HttpResponse response, HttpSession session, NewTopicBindingModel ntbm)
        {
            TopicsNewViewModel tnvm = this.topicsService.GenerateTopicsNewViewModel(session);

            if (this.topicsService.IsNewTopicBindingModelValid(ntbm))
            {
                this.topicsService.CreateNewTopic(session, ntbm);

                this.Redirect(response, "/home/topics");
                return(null);
            }

            return(this.View(tnvm));
        }