public int EditItem(int id, POST Post) { POST PostEdit = db.POSTs.Find(id); using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { PostEdit.TITLE = Post.TITLE; PostEdit.URL_SLUG = ConvertString.ToUrlSlug(Post.TITLE); PostEdit.DATE_EDIT = DateTime.Now; PostEdit.ACTIVE = Post.ACTIVE; PostEdit.DESCRIPTION = Post.DESCRIPTION; PostEdit.DETAIL = Post.DETAIL; PostEdit.PICTURE = Post.PICTURE; db.Entry(PostEdit).State = EntityState.Modified; int i = db.SaveChanges(); transaction.Commit(); return(Post.ID); } catch { transaction.Rollback(); return(0); } } }
public int AddItem(CATEGORy Category) { using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { Category.URL_SLUG = ConvertString.ToUrlSlug(Category.NAME); db.CATEGORIES.Add(Category); int i = db.SaveChanges(); transaction.Commit(); return(Category.ID); } catch { transaction.Rollback(); return(0); } } }
public int AddItem(POST Post) { using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { Post.URL_SLUG = ConvertString.ToUrlSlug(Post.TITLE); Post.DATE_CREATED = DateTime.Now; db.POSTs.Add(Post); int i = db.SaveChanges(); transaction.Commit(); return(Post.ID); } catch { transaction.Rollback(); return(0); } } }
public int EditItem(int id, CATEGORy Category) { CATEGORy CategoryEdit = db.CATEGORIES.Find(id); using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { CategoryEdit.NAME = Category.NAME; CategoryEdit.URL_SLUG = ConvertString.ToUrlSlug(Category.NAME); CategoryEdit.DESCRIPTION = Category.DESCRIPTION; CategoryEdit.ID_PARENT = Category.ID_PARENT; db.Entry(CategoryEdit).State = EntityState.Modified; int i = db.SaveChanges(); transaction.Commit(); return(CategoryEdit.ID); } catch { transaction.Rollback(); return(0); } } }