Ejemplo n.º 1
0
 public ActionResult play(int id)
 {
     if (db.WaitedGames.Where(z => z.DesignedGameId == id).Count() > 0)
     {
         var        s = Session["username"].ToString();
         OnlineGame o = new OnlineGame();
         o.DesignedGameId = id;
         o.Player1User    = db.WaitedGames.Where(z => z.DesignedGameId == id).First().Username;
         o.Player2User    = s;
         db.WaitedGames.Remove(db.WaitedGames.First());
         db.OnlineGames.Add(o);
         db.SaveChanges();
         Session["gameid"] = db.OnlineGames.Where(u => u.Player2User == s).First().Id;
         if (db.DesignedGames.Where(u => u.Id == id).First().DiceCount == 1)
         {
             return(RedirectToAction("Index", "Game"));
         }
         else
         {
             return(RedirectToAction("TwoDice", "Game"));
         }
     }
     else
     {
         WaitedGame w = new WaitedGame();
         w.Username       = Session["username"].ToString();
         w.DesignedGameId = id;
         db.WaitedGames.Add(w);
         db.SaveChanges();
         Session["message"] = "you added succesfully to game " + id;
         return(RedirectToAction("ChooseGame", "Home"));
     }
 }
        public ActionResult login(string username, string password)
        {
            User usr = _context.Users.Where(u => u.UserName == username && u.Password == password).FirstOrDefault();

            if (usr != null)
            {
                _context.Users.Where(u => u.UserName == username && u.Password == password).First().Online = 1;

                /*_context.Users.Remove(usr);
                 * _context.SaveChanges();
                 * usr.Online = 1;
                 * _context.Users.Add(usr);
                 */
                _context.SaveChanges();
                Session["username"]      = _context.Users.Where(u => u.UserName == usr.UserName).First().UserName;
                Session["designedGame"]  = _context.DesignedGames.Where(d => d.DesignerUser == usr.UserName).ToList();
                Session["finishedGame1"] = _context.FinishedGames.Where(d => d.Player1User == usr.UserName).ToList();
                Session["finishedGame2"] = _context.FinishedGames.Where(d => d.Player2User == usr.UserName).ToList();
                Session["usr"]           = usr;
                Session["mean"]          = _context.Users.Where(u => u.UserName == usr.UserName).First().RateMean;
                Session["all"]           = _context.Users.Where(u => u.UserName == usr.UserName).First().RateNum;
                Session["win"]           = _context.Users.Where(u => u.UserName == usr.UserName).First().WinNum;
                return(RedirectToAction("Index", "Home"));
            }
            else if (_context.Admins.Where(u => u.Username == username && u.Password == password).Any())
            {
                return(RedirectToAction("AdminIndex", "Home"));
            }
            else
            {
                return(RedirectToAction("login", "Login"));
            }
        }
Ejemplo n.º 3
0
        public ActionResult AddFriend1(string friend)
        {
            Friend f = new Friend();

            f.Username       = Session["username"].ToString();
            f.UsernameFriend = friend;
            db.Friends.Add(f);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public ActionResult AcceptGameReview(int id)
        {
            GameComment com = db.CommentGames.Find(id);

            db.CommentGames.Remove(com);
            db.SaveChanges();
            (db.DesignedGames.Where(x => x.Id == com.GameId).First()).Comments.Add(com);
            //db.SaveChanges();
            return(RedirectToAction("GameReviewAdminIndex"));
        }