public void UpdateUser(User user) { using (var context = new GiaikhatNgocMaiEntities()) { var dbUser = context.Users.SingleOrDefault(u => u.Id == user.Id); if (dbUser == null) throw new NullReferenceException("Can not found user " + user.UserName); context.Entry(user).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public int CreateUser(User user) { using (var context = new GiaikhatNgocMaiEntities()) { context.Users.Add(user); context.SaveChanges(); return user.Id; } }