private void SaveStudent(Student model) { var userId = 0; var user = new User { UserName = model.Email, Password = model.MatricNo, CreatedBy = model.FirstName, CreatedDate = DateTime.Now }; if (user == null) { _db.Users.Add(user); userId = _db.SaveChanges(); } model.UserId = userId; if (_db.Entry <Student>(model).State == EntityState.Detached) { _db.Set <Student>().Attach(model); } _db.Entry(model).State = EntityState.Modified; _db.SaveChanges(); preenrollmentFmds.Clear(); picBoxFingerPrint.Image = null; count = 0; lblCount.Invoke(new Action(() => { lblCount.Text = count.ToString(); })); }
public void Update <T>(int id, T item) where T : class { if (context.Entry <T>(item).State == EntityState.Detached) { context.Set <T>().Attach(item); } context.Entry(item).State = EntityState.Modified; context.SaveChanges(); }
public void atualizar(T pEntity) { dbSet.Attach(pEntity); context.Entry(pEntity).State = EntityState.Modified; SaveChange(); }