public static void addObject <T>(T obj) { DataBaseBlog db = new DataBaseBlog(); db.Set(obj.GetType()).Add(obj); db.SaveChanges(); }
public static void removeFromBlogId(string BlogId) { DataBaseBlog db = new DataBaseBlog(); db.Blog_category.RemoveRange(db.Blog_category.Where(b => b.blog_id == BlogId)); db.SaveChanges(); }
public static void addObject(FormCollection collection, UserSection section) { DataBaseBlog db = new DataBaseBlog(); Models.Blog obj = new Models.Blog(); obj.ID = Guid.NewGuid().ToString(); obj.title = collection["title"]; obj.contents = collection["contents"]; obj.thumbnail = collection["thumbnail"]; obj.status = 2; obj.create_at = DateTime.Now; obj.create_by = section.UserID; db.Set(obj.GetType()).Add(obj); db.SaveChanges(); if (collection["categories"] != null) { List <string> result = collection["categories"].Split(',').ToList(); blog_category_Data.inserts(obj.ID, result); } }
public static void removeFromCategory(string category_id) { DataBaseBlog db = new DataBaseBlog(); db.Blog_category.RemoveRange(db.Blog_category.Where(b => b.category_id == category_id)); db.SaveChanges(); }
public async Task <IActionResult> Edit(BlogDetails unBlog, List <IFormFile> Picture) { foreach (var item in Picture) { if (item.Length > 0) { using (var unStream = new MemoryStream()) { await item.CopyToAsync(unStream); unBlog.Picture = unStream.ToArray(); } } } _context.BlogDetails.Update(unBlog); _context.SaveChanges(); //return View(); return(Redirect("~/BlogsDetails/Index")); }
public static void remove(string id) { DataBaseBlog db = new DataBaseBlog(); Category objRemove = db.Categories.Find(id); try{ blog_category_Data.removeFromCategory(id); db.Categories.Remove(objRemove); db.SaveChanges(); } catch { } }
public static void update(Category newObj) { DataBaseBlog db = new DataBaseBlog(); try { Category oldObj = db.Categories.Find(newObj.ID); oldObj.name = newObj.name; oldObj.description = newObj.description; db.SaveChanges(); } catch { } }
public static void remove(string id) { DataBaseBlog db = new DataBaseBlog(); db.Blog_category.RemoveRange(db.Blog_category.Where(x => x.blog_id == id)); try { db.Blogs.Remove(db.Blogs.Find(id)); db.SaveChanges(); } catch { } }
public static void inserts(string blogId, List <string> categoryIds) { DataBaseBlog db = new DataBaseBlog(); foreach (string categoryId in categoryIds) { Blog_category bc = new Blog_category(); bc.ID = Guid.NewGuid().ToString(); bc.blog_id = blogId; bc.category_id = categoryId; db.Blog_category.Add(bc); } db.SaveChanges(); }
public static void Update(string blogId, List <string> categoryIds) { DataBaseBlog db = new DataBaseBlog(); db.Blog_category.RemoveRange(db.Blog_category.Where(b => b.blog_id == blogId)); foreach (string categoryId in categoryIds) { Blog_category bc = new Blog_category(); bc.ID = Guid.NewGuid().ToString(); bc.blog_id = blogId; bc.category_id = categoryId; db.Blog_category.Add(bc); } db.SaveChanges(); }
public static void Update(string id, FormCollection collection) { DataBaseBlog db = new DataBaseBlog(); Models.Blog obj = db.Blogs.Find(id); obj.title = collection["title"]; obj.contents = collection["contents"]; obj.thumbnail = collection["thumbnail"]; db.SaveChanges(); if (collection["categories"] != null) { List <string> result = collection["categories"].Split(',').ToList(); blog_category_Data.Update(id, result); } else { blog_category_Data.removeFromBlogId(id); } }
public String Insert(Models.User u) { db.Users.Add(u); db.SaveChanges(); return(u.ID); }