Example #1
0
        public object AddBlog(Blog blog)
        {
            if (blog != null && !string.IsNullOrWhiteSpace(blog.Content))
            {
                var text = System.Text.RegularExpressions.Regex.Replace(blog.Content, @"<[^>]*>", "");
                if (text.Length > 100)
                {
                    text = text.Substring(0, 100);
                }

                blog.ID         = Guid.NewGuid().ToString("N");
                blog.Summary    = text;
                blog.CreateTime = DateTime.Now;

                BlogManager.AddBlog(blog);

                return(new JsonResponseModel {
                    Success = true
                });
            }
            else
            {
                return(new JsonResponseModel {
                    Success = false
                });
            }
        }
        public ActionResult AddBlogPost(BlogVM model)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(model.Blog.Title))
                {
                    ModelState.AddModelError("Title", "You must enter a title.");
                }
                else if (string.IsNullOrEmpty(model.Blog.Content))
                {
                    ModelState.AddModelError("Content", "You must enter something in the blog body.");
                }
                else
                {
                    TheCodingVineDbContext db = new TheCodingVineDbContext();


                    BlogManager manager = BlogManagerFactory.Create();

                    if (model.Blog.TagInputs != null)
                    {
                        string[] tags = model.Blog.TagInputs.Split(',');

                        foreach (var tag in tags)
                        {
                            var searchTag = new SearchTag()
                            {
                                SearchTagBody = tag
                            };
                            model.Blog.SearchTags.Add(searchTag);
                        }

                        model.Blog.TagInputs = null;
                    }

                    UserManager <AppUser> userManager = new UserManager <AppUser>(new UserStore <AppUser>(db));

                    model.Blog.BlogWriter = userManager.FindByName(User.Identity.Name);

                    manager.AddBlog(model.Blog);

                    return(RedirectToAction("MyBlogs"));
                }
            }

            return(View(model));
        }
Example #3
0
        public ActionResult Articles([Bind(Include = "BlogTitle, BlogData")] string blogTitle, string blogData)
        {
            BlogManager blogManager = new BlogManager();
            int         UserID      = RetrieveUserId();

            Blog blog = new Blog()
            {
                BlogTitle   = blogTitle,
                BlogData    = blogData,
                CreatedBy   = UserID,
                DateCreated = DateTime.Now,
                Active      = true
            };

            blogManager.AddBlog(blog);
            return(RedirectToAction("Index", "Expert"));
        }
Example #4
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            String message = "Sorry, we could not add the entry to our system.";
            bool   valid   = true;

            try
            {
                Blog blog = new Blog()
                {
                    BlogTitle   = txtTitle.Text,
                    BlogData    = txtContent.Text,
                    CreatedBy   = accessToken.UserID,
                    DateCreated = DateTime.Now,
                    Active      = true
                };

                if (blog.BlogTitle == "")
                {
                    valid    = false;
                    message += "\nYou must enter a title";
                }
                if (blog.BlogData == "")
                {
                    valid   = false;
                    message = "\nYou must enter some content";
                }
                if (valid)
                {
                    blogManager.AddBlog(blog);
                    MessageBox.Show("Thank you for submitting your blog!");
                    if (accessToken != null)
                    {
                        this.NavigationService.Navigate(new HomePages.ViewBlog(accessToken));
                    }
                }
                else
                {
                    MessageBox.Show(message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(message);
            }
        }
        public async Task Add_Blog()
        {
            try
            {
                string connection = @"Server=(localdb)\mssqllocaldb;Database=BloggingGeneric;Trusted_Connection=True;ConnectRetryCount=0";
                var    options    = new DbContextOptionsBuilder <DataContext>()
                                    .UseSqlServer(connection)
                                    .Options;

                //// Create the schema in the database
                //using (var context = new BloggingContext(options))
                //{
                //    context.Database.EnsureCreated();
                //}

                // Run the test against one instance of the context
                using (var context = new DataContext(options))
                {
                    //IBlogRepositoryGeneric blogsRepository = new BlogRepositoryGenerics(context);

                    var uow = new UnitOfWork <DataContext>(context);
                    //var repo = uow.GetRepository<Blog>();
                    BlogManager blogManager = new BlogManager(uow);

                    BlogDtoDll blogDtoDll = new BlogDtoDll();

                    blogDtoDll.Url = "test from VS";
                    blogManager.AddBlog(blogDtoDll);
                }

                //Use a separate instance of the context to verify correct data was saved to database
                //using (var context = new BloggingContext(options))
                //{
                //    Assert.AreEqual(1, context.Blogs.Count());
                //    Assert.AreEqual("http://sample.com", context.Blogs.Single().Url);
                //}
            }
            catch (Exception e)
            {
            }
            finally
            {
            }
        }
        public ActionResult Login(string returnUrl = "")
        {
            _blogManager.AddBlog(new Blog.Blog()
            {
                Title = "TAONY"
            });

            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                returnUrl = Request.ApplicationPath;
            }

            return(View(
                       new LoginFormViewModel
            {
                ReturnUrl = returnUrl,
                IsMultiTenancyEnabled = _multiTenancyConfig.IsEnabled
            }));
        }
        public IActionResult PostBlog([FromBody] BlogDto BlogDto)
        {
            int blog_id = 0;

            if (ModelState.IsValid)
            {
                BlogDtoDll BlogDtoDll = new BlogDtoDll();
                BlogDtoDll.Url = BlogDto.Url;

                foreach (var item in BlogDto.PostDto)
                {
                    PostDtoDll post = new PostDtoDll();
                    post.Content = item.Content;
                    post.Title   = item.Title;
                    BlogDtoDll.PostDtoDll.Add(post);
                }

                BlogManager blogManager = new BlogManager(this._unitOfWork);

                blog_id = blogManager.AddBlog(BlogDtoDll);
            }

            return(CreatedAtAction(actionName: "GetBlog", routeValues: new { id = blog_id }, value: null));
        }