public void DeleteBlog(int blogId) { Blog blog = context.Blog.Find(blogId); context.Blog.Remove(blog); context.SaveChanges(); }
public void AddPage(Page p) { context.Page.Add(p); context.SaveChanges(); }
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)); } }