Пример #1
0
 public UserViewModel GetUserById(int? id)
 {
     UserViewModel uvm = new UserViewModel();
     var query = db.User.Where(u => u.Id == id).ToList();
     foreach(var u in query)
     {
         User user = new User();
         user.Name = u.Name;
         user.UserName = u.UserName;
         uvm.ListUser.Add(user);
     }
     return uvm;
 }
Пример #2
0
 public void UpdateUser(UserViewModel userViewModel)
 {
     List<User> lUser = userViewModel.ListUser;
     foreach(User u in lUser)
     {
         db.Entry(u).State = EntityState.Modified;
     }
     try
     {
         db.SaveChanges();
     }
     catch(Exception e)
     {
         log.Error("Error Update User : " + e.Message, e);
     }
 }
Пример #3
0
 public void InsertNewUser(UserViewModel userViewModel)
 {
     List<User> lUser = userViewModel.ListUser;
     foreach (User u in lUser)
     {
         db.User.Add(u);
     }
     try
     {
         db.SaveChanges();
     }
     catch (Exception e)
     {
         log.Error("Error Insert New User :" + e.Message, e);
     }
 }