public void CreateUser(Models.User user)
 {
     using(TempDBContext1 db = new TempDBContext1())
     {
         db.Users.Add(user);
         db.SaveChanges();
     }
 }
 public IEnumerable<Models.User> GetAllUsers()
 {
     IEnumerable<User> users = null;
     using (TempDBContext1 db = new TempDBContext1())
     {
         users = db.Users.ToList();
     }
     return users;
 }
 public IEnumerable<string> GetAllUsernames()
 {
     IEnumerable<User> users = null;
     List<string> names = new List<string>();
     using (TempDBContext1 db = new TempDBContext1())
     {
         users = db.Users.ToList();
     }
     if(users != null && users.Count() > 0)
     {
         foreach (User u in users)
         {
             names.Add(u.UserName);
         }
     }
     return names;
 }
 public void UpdateUser(Models.User user)
 {
     using (TempDBContext1 db = new TempDBContext1())
     {
         User oldUser = db.Users.Find(user.UserName);
         oldUser.CurrentHealth = user.CurrentHealth;
         oldUser.MonstersKilled = user.MonstersKilled;
         oldUser.RoomsTraveled = user.RoomsTraveled;
         oldUser.Attack = user.Attack;
         oldUser.Defense = user.Defense;
         oldUser.AttackSpeed = user.AttackSpeed;
         oldUser.AttackRange = user.AttackRange;
         oldUser.MoveSpeed = user.MoveSpeed;
         db.SaveChanges();
     }
 }
 public Models.User GetUser(string userName)
 {
     User foundUser = null;
     using (TempDBContext1 db = new TempDBContext1())
     {
         foundUser = db.Users.Find(userName);
     }
     return foundUser;
 }
Example #6
0
        public void DeleteUser(string userName)
        {
            //Remove user from Friend table
            using(SqlDBFriendListContext db = new SqlDBFriendListContext())
            {
                List<Friend> friends = db.Friends.Where(u => (u.Friend1 == userName) || (u.User == userName)).ToList();

                foreach(Friend friend in friends)
                {
                    db.Friends.Remove(friend);
                    db.Entry(friend).State = EntityState.Deleted;
                }
                db.SaveChanges();
            }

            //Remove user from FriendRequest and Message table
            using(TempDBFriendContext db = new TempDBFriendContext())
            {
                List<FriendRequest> friends = db.FriendRequests.Where(u => (u.Sender == userName) || (u.Receiver == userName)).ToList();
                List<Message> messages = db.Messages.Where(u => (u.Sender == userName) || (u.Receiver == userName)).ToList();

                foreach (FriendRequest friend in friends)
                {
                    db.FriendRequests.Remove(friend);
                    db.Entry(friend).State = EntityState.Deleted;
                }
                foreach(Message m in messages)
                {
                    db.Messages.Remove(m);
                    db.Entry(m).State = EntityState.Deleted;
                }

                db.SaveChanges();
            }

            //Remove user from User table
            using(TempDBContext1 db = new TempDBContext1())
            {
                User user = db.Users.Where(u => u.UserName == userName).FirstOrDefault();
                if (user != null)
                {
                    //db.Users.Attach(user);
                    db.Users.Remove(user);
                    db.Entry(user).State = EntityState.Deleted;
                    db.SaveChanges();
                }
            }

            //Remove user from LogUser table and UserRoles table
            using(TempDBLogUsers db = new TempDBLogUsers())
            {
                LogUser user = db.LogUsers.Where(u => u.UserName == userName).FirstOrDefault();
                if (user != null)
                {
                    user.Roles.FirstOrDefault().LogUsers.Remove(user);
                    user.Roles.Remove(user.Roles.FirstOrDefault());
                    //db.LogUsers.Attach(user);
                    db.LogUsers.Remove(user);
                    db.Entry(user).State = EntityState.Deleted;
                    db.SaveChanges();
                }
            }
        }
Example #7
0
 public Models.User GetUser(string userName)
 {
     User foundUser = null;
     using (TempDBContext1 db = new TempDBContext1())
     {
         foundUser = db.Users.Where(u => u.UserName == userName).FirstOrDefault();
         //foundUser = db.Users.Find(userName);
     }
     return foundUser;
 }