public static void InsertOrUpdate(User user) { using (SgllEntities db = new SgllEntities()) { try { db.Entry(user).State = user.Id == 0 ? EntityState.Added : EntityState.Modified; db.SaveChanges(); } catch (Exception) { } } }
public static void InsertUser(User user) { using (SgllEntities db = new SgllEntities()) { try { db.Users.Add(user); db.SaveChanges(); } catch (Exception) { } } }
public static void DeleteUsers(List<User> users) { using (SgllEntities db = new SgllEntities()) { try { users.ForEach(u => db.Users.Attach(u)); db.Users.RemoveRange(users); db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } }