public int CreateUser(User user) { using (QYDbContext db = new QYDbContext()) { db.Users.Add(user); return(db.SaveChanges()); } }
public int UpdateUser(User user, string loginName = null) { using (QYDbContext db = new QYDbContext()) { var userDb = db.Users.Find(user.Id); AutoMapper.Mapper.Map(user, userDb); if (!string.IsNullOrWhiteSpace(loginName)) { userDb.UpdatedBy = loginName; userDb.UpdatedTime = DateTime.Now; } db.Users.Attach(userDb); db.Entry(userDb).State = EntityState.Modified; return(db.SaveChanges()); } }