Exemplo n.º 1
0
        public ActionResult EditUser(string id)
        {
            IDAL dal = new DBDataAL();
            string userName = id;
            userName = userName ?? "";
            bool requestHasError = false;
            User user = dal.GetUser(userName);

            if (dal.isInRole(userName, "Admin")
                && User.Identity.Name != userName)
            {
                ViewBag.AdminError = userName + " is an admin and you are currently logged in as " + User.Identity.Name
                    + ". To edit this user, please log in to that account.";
                requestHasError = true;
            }
            else if (user == null)
            {
                ViewBag.AdminError = "User was not found";
                requestHasError = true;
            }

            ActionResult view = null;
            if(!requestHasError)
                view = View(new UserViewModel(user));
            else
                view = View("~/Views/Admin/AdminError.cshtml");

            return view;
        }
Exemplo n.º 2
0
        public ActionResult FriendProfile(string name)
        {
            IDAL DAL = new DBDataAL();
            User u = DAL.GetUser(name);

            return View("Profile", u);
        }
Exemplo n.º 3
0
        public ActionResult DenyFriendRequest(string sender)
        {
            string currentUser = User.Identity.Name;

            IDAL DAL = new DBDataAL();
            User user = DAL.GetUser(currentUser);
            FriendRequest fr = DAL.GetFriendRequests(user).Where(r => r.Sender == sender).ToList().First();
            DAL.RemoveFriendRequest(fr);

            FriendData data = new FriendData(currentUser);
            return View("~/Views/Web/Friends.cshtml", data);
        }
Exemplo n.º 4
0
        public ActionResult AcceptFriendRequest(string sender)
        {
            string currentUser = User.Identity.Name;
            IDAL DAL = new DBDataAL();

            User user = DAL.GetUser(currentUser);

            IEnumerable<string> friends = DAL.GetFriends(user).ToList();
            if(!friends.Contains(sender))
            {
                DAL.AddFriend(currentUser, sender);
            }

            IEnumerable<FriendRequest> requests = DAL.GetFriendRequests(user).Where(r => r.Sender == sender);
            IEnumerable<FriendRequest> requests2 = DAL.GetFriendRequests(DAL.GetUser(sender)).Where(r => r.Sender == currentUser);
            IEnumerable<FriendRequest> fullList = requests.Concat(requests2);
            foreach (FriendRequest req in fullList)
            {
                DAL.RemoveFriendRequest(req);
            }

            FriendData data = new FriendData(currentUser);
            return View("~/Views/Web/Friends.cshtml", data);
        }
        public ActionResult AcceptFriendRequest(User receiver, string sender)
        {
            IDAL DAL = new DBDataAL();
            DAL.AddFriend(receiver.UserName, sender);

            IEnumerable<FriendRequest> requests = DAL.GetFriendRequests(receiver).Where(r => r.Sender == sender);
            IEnumerable<FriendRequest> requests2 = DAL.GetFriendRequests(DAL.GetUser(sender)).Where(r => r.Sender == receiver.UserName);
            IEnumerable<FriendRequest> fullList = requests.Concat(requests2);
            foreach (FriendRequest req in fullList)
            {
                DAL.RemoveFriendRequest(req);
            }

            IEnumerable<FriendRequest> friends = DAL.GetFriendRequests(receiver);

            FriendData data = new FriendData("matt");
            return View("Web/Friends", data);
        }
Exemplo n.º 6
0
        public ActionResult SortByDefenseAscending(bool isGlobal)
        {
            IDAL DAL = new DBDataAL();
            Leaderboard board = new Leaderboard();
            board.IsGlobal = isGlobal;
            IEnumerable<User> users;
            if (isGlobal)
            {
                users = DAL.GetAllUsers().OrderBy(x => x.HighDefense);
            }
            else
            {
                string userName = User.Identity.Name;
                User currentUser = DAL.GetUser(userName);
                IEnumerable<string> friends = DAL.GetFriends(currentUser);
                users = DAL.GetAllUsers().Where(x => friends.Contains(x.UserName)).OrderBy(x => x.HighDefense);

            }
            board.Users = users;
            return View("~/Views/Web/Leaderboard.cshtml", board);
        }
Exemplo n.º 7
0
        public ActionResult EditUser(string id, UserViewModel viewModel)
        {
            string userName = id;
            IDAL dal = new DBDataAL();
            User user = dal.GetUser(userName);

            if (user != null)
            {
                user.Attack = viewModel.Attack;
                //user.AttackRange = viewModel.AttackRange;
                //user.AttackSpeed = viewModel.AttackSpeed;
                user.CurrentHealth = viewModel.CurrentHealth;
                user.Defense = viewModel.Defense;
                user.HighMonstersKilled = viewModel.MonstersKilled;
                //user.MoveSpeed = viewModel.MoveSpeed;
                user.HighRoomsTraveled = viewModel.RoomsTraveled;
                user.HighDefense = viewModel.HighestDefenseAchieved;
                user.HighAttack = viewModel.HighestAttackAchieved;

                dal.UpdateUser(user);
            }

            return EditUser(userName);
        }
Exemplo n.º 8
0
        public ActionResult RequestFriend(string name)
        {
            string currentUser = User.Identity.Name;

            IDAL DAL = new DBDataAL();
            User user = DAL.GetUser(name);
            try
            {
                FriendRequest requests = DAL.GetFriendRequests(user).Where(x => x.Sender == currentUser).First();
            }
            catch(Exception) //if null catch explosion
            {
                FriendRequest fr = new FriendRequest();
                fr.Receiver = name;
                fr.Sender = currentUser;
                DAL.CreateFriendRequest(fr);
            }

            FriendData data = new FriendData(currentUser);

            return View("~/Views/Web/Friends.cshtml", data);
        }
Exemplo n.º 9
0
 public ActionResult ViewMessage(int messageId)
 {
     IDAL DAL = new DBDataAL();
     string Name = User.Identity.Name;
     User user = DAL.GetUser(Name);
     Message message = DAL.GetMessagesFor(user).Where(m => m.Id == messageId).ToList().First();
     return View("Message", message);
 }
Exemplo n.º 10
0
 public FriendData(string name)
 {
     IDAL DAL = new DBDataAL();
     Owner = DAL.GetUser(name);
     SetUp();
 }
Exemplo n.º 11
0
        public ActionResult Profile()
        {
            if (User.Identity.IsAuthenticated)
            {
                IDAL DAL = new DBDataAL();
                User u = DAL.GetUser(User.Identity.Name);

                return View("Profile", u);
            }
            else
            {
                return RedirectToAction("Login", "Membership");
            }
        }
Exemplo n.º 12
0
 public ActionResult SwitchToFriends()
 {
     Leaderboard board = new Leaderboard();
     board.IsGlobal = false;
     IDAL DAL = new DBDataAL();
     User currentUser = DAL.GetUser(User.Identity.Name);
     IEnumerable<string> friends = DAL.GetFriends(currentUser);
     IEnumerable<User> users = DAL.GetAllUsers().Where(x => friends.Contains(x.UserName));
     return View("~/Views/Web/Leaderboard.cshtml", board);
 }