예제 #1
0
        public Response<Post> AddPost(Post newPost)
        {
            Regex pattern = new Regex(@"#\w+", RegexOptions.IgnoreCase);
            var cats = new List<string>();
            List<Category> catList = new List<Category>();

            foreach (Match match in pattern.Matches(newPost.Content))
            {
                string cat = match.Value;
                cats.Add(cat.Substring(1, cat.Length - 1) + " ");

                foreach (var c in cats)
                {
                    catList.Add(new Category() { category = c });
                }
            }

            newPost.Categories = catList;
            var response = new Response<Post>();

            try
            {

                _repo.AddPost(newPost);
                response.Success = true;
                response.Message = "Successfully added post.";
            }
            catch(Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
예제 #2
0
        public void AddPost(Post newPost)
        {
            using (var context = new Models.PostContext())
            {
                Models.Post post = new Models.Post();

                post.Title = newPost.Title;
                post.IsApproved = newPost.IsApproved;
                post.DatePosted = newPost.DatePosted;
                post.Content = newPost.Content;
                post.CatID = newPost.CatID;
                post.Categories = newPost.Categories.Select(x => new Models.Category() { category = x.category }).ToList();

                context.Posts.Add(post);
                context.SaveChanges();
            }
        }
예제 #3
0
        public ActionResult CreatePost(Models.HTMLContent x)
        {
            if(ModelState.IsValid)
            {
            var newPost = new Post();
            newPost.Content = x.HtmlContent;
            newPost.Title = x.Title;
            newPost.IsApproved = false;
            newPost.DatePosted = DateTime.Now;

            var manager = new BlogManager();
            var response = manager.AddPost(newPost);

            return View("Pending");
            }
            else
            {
                return View("NewAdminPost");
            }
        }
예제 #4
0
        private Post MapPost(Models.Post from)
        {
            var to = new Post();

            to.PostID = from.PostID;
            to.Title = from.Title;
            to.IsApproved = from.IsApproved;
            to.DatePosted = from.DatePosted;
            to.Content = from.Content;
            to.CatID = from.CatID;
            to.Categories = from.Categories.Select(x => MapCategory(x)).ToList();

            return to;
        }