public ActionResult AddBlog() { BlogVM model = new BlogVM() { BlogCategories = new List <Category>(), Blog = new Blog() }; model.Blog.Author = User.Identity.Name; model.Blog.BlogTags = new List <Tag>(); model.Blog.Date = DateTime.Today; model.SetCategories(context.Categories.ToList()); return(View(model)); }
public ActionResult AddBlog() { BlogVM model = new BlogVM() { BlogCategory = new Category(), BlogTags = new List <Tag>(), Author = User.Identity.Name, Date = DateTime.Today }; var context = new ExploreMidwestDBContext(); model.SetCategories(context.Category.ToList()); return(View(model)); }
public ActionResult EditBlog(int id) { Blog b = repo.GetBlogById(id); var model = new BlogVM() { Author = b.Author, Body = b.Body, BlogId = b.BlogId, BlogCategory = b.BlogCategory, Date = b.Date, IsDeleted = b.IsDeleted, IsFinished = b.IsFinished, BlogTags = b.BlogTags, Title = b.Title, ImageLocation = b.ImageLocation, }; model.SetCategories(context.Category.ToList()); return(View(model)); }
public ActionResult AddBlog(BlogVM b) { var repo = BlogRepoFactory.Create(); var context = new ExploreMidwestDBContext(); if (ModelState.IsValid) { Blog blog = new Blog(); if (b.File != null) { string pic = Path.GetFileName(b.File.FileName); string path = Path.Combine( Server.MapPath("~/images"), pic); // file is uploaded b.File.SaveAs(path); blog = new Blog { BlogId = b.BlogId, Body = b.Body, IsDeleted = b.IsDeleted, IsFinished = b.IsFinished, BlogTags = new List <Tag>(), Title = b.Title, Author = User.Identity.Name, Date = DateTime.Now, ImageLocation = "images/" + Path.GetFileName(b.File.FileName), }; } else { blog = new Blog { BlogId = b.BlogId, Body = b.Body, IsDeleted = b.IsDeleted, IsFinished = b.IsFinished, BlogTags = new List <Tag>(), Title = b.Title, Author = User.Identity.Name, Date = DateTime.Now, }; } if (b.BlogCategory.CategoryId == 0) { Category c = new Category { CategoryType = b.NewCategory }; context.Category.Add(c); context.SaveChanges(); blog.BlogCategory = context.Category.FirstOrDefault(g => g.CategoryType == c.CategoryType); } else { blog.BlogCategory = context.Category.FirstOrDefault(c => c.CategoryId == b.BlogCategory.CategoryId); } repo.AddBlog(blog); return(RedirectToAction("Index", "Home")); } else { b.SetCategories(context.Category.ToList()); return(View(b)); } }