public User Edit(User user) { user.ModifiedOn = DateTime.Now; User dbUser = Single(user.ID); // get the database columns which need to be updated var databaseMembers = db.Mapping.MappingSource.GetModel(typeof(BizzyQuoteDataContext)).GetMetaType(typeof(User)).DataMembers .Where(d => d.IsAssociation == false && d.IsDbGenerated == false && d.IsPersistent == true); // reflect to get instances of the entity preoprties var editProperties = from p in dbUser.GetType().GetProperties() join m in databaseMembers on p.Name equals m.Name select p; // copy the values PropertyInfo[] editProps = editProperties.ToArray(); foreach (PropertyInfo propertyInfo in editProps) { propertyInfo.SetValue(dbUser, propertyInfo.GetValue(user, null), null); } db.SubmitChanges(); return dbUser; }
public ActionResult Edit(User user) { using (var um = new UserManager()) { user = um.Edit(user); } return RedirectToAction("List"); }
public User Create(User user) { user.CreatedOn = DateTime.Now; user.ModifiedOn = DateTime.Now; db.Users.InsertOnSubmit(user); db.SubmitChanges(); return user; }
public void CreateUserTest() { User user = new User(); user.CompanyID = 1; user.CreatedOn = DateTime.Now; user.Email = "*****@*****.**"; user.FirstName = "John2"; user.LastName = "Ocker2s"; user.Username = "******"; using (var um = new UserManager()) { user = um.Create(user); } Assert.IsTrue(user.ID > 0); }
partial void DeleteUser(User instance);
partial void UpdateUser(User instance);
partial void InsertUser(User instance);
private void detach_Users(User entity) { this.SendPropertyChanging(); entity.Company = null; }
private void attach_Users(User entity) { this.SendPropertyChanging(); entity.Company = this; }