예제 #1
0
 public int CreateUser(User user)
 {
     using (QYDbContext db = new QYDbContext())
     {
         db.Users.Add(user);
         return(db.SaveChanges());
     }
 }
예제 #2
0
 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());
     }
 }