示例#1
0
 public void AddUser(User user)
 {
     using (var db = new UsersAppContext())
     {
         db.Users.Add(user);
         db.SaveChanges();
     }
 }
示例#2
0
 public void UpdateUserById(User user, int id)
 {
     using (var db = new UsersAppContext())
     {
         var foundUser = db.Users.FirstOrDefault(x => x.Id == id);
         foundUser = user;
         db.SaveChanges();
     }
 }
示例#3
0
        public int GetUsersAmount()
        {
            int amount;

            using (var db = new UsersAppContext())
            {
                amount = db.Users.Count();
            }

            return(amount);
        }
示例#4
0
        public User GetUserById(int id)
        {
            User user = null;

            using (var db = new UsersAppContext())
            {
                user = db.Users.FirstOrDefault(x => x.Id == id);
            }

            return(user);
        }
示例#5
0
        public List <User> GetSpecifiedUsers(int skip, int take)
        {
            List <User> usersResponse = null;

            using (var db = new UsersAppContext())
            {
                usersResponse = db.Users.OrderBy(x => x.Id).Skip(skip).Take(take).ToList();
            }

            return(usersResponse);
        }
示例#6
0
        public List <User> GetAllUsers()
        {
            List <User> users = null;

            using (var db = new UsersAppContext())
            {
                users = db.Users.ToList();
            }

            return(users);
        }
示例#7
0
 public void RemoveUserById(int id)
 {
     using (var db = new UsersAppContext())
     {
         var user = db.Users.FirstOrDefault(x => x.Id == id);
         if (user != null)
         {
             db.Users.Remove(user);
             db.SaveChanges();
         }
     }
 }