// GET: /Game/
        public ActionResult Index(int? id)
        {
            ProfileViewModel profile = TempData["profileData"] as ProfileViewModel;
            if (profile == null)
            {
                ProfileViewModel newProfile = new ProfileViewModel();
                newProfile.Nick = NicknamesHelper.GetRandomNick();
                newProfile.Avatar = AvatarsHelper.GetRandomAvatar();
                CookieManager.WriteCookie(this.HttpContext, CookieManager.UserCookieName, newProfile.Nick);
                CookieManager.WriteCookie(this.HttpContext, CookieManager.AvatarCookieName, newProfile.Avatar);
                return View(newProfile);
                //if (this.HttpContext.HasCookie(CookieManager.UserCookieName))
                //{
                //    ProfileViewModel vm = new ProfileViewModel();
                //    vm.Nick = this.HttpContext.GetCookieValue(CookieManager.UserCookieName);

                //    if (this.HttpContext.HasCookie(CookieManager.AvatarCookieName))
                //    {
                //        vm.Avatar = this.HttpContext.GetCookieValue(CookieManager.AvatarCookieName);
                //        return View(vm);
                //    }
                //    else
                //    {
                //        vm.Avatar = AvatarsHelper.GetRandomAvatar();
                //        return View(vm);
                //    }
                //}
                //else
                //{
                //    //redirect to index page
                //    return RedirectToAction("Index", "Home", null);
                //}
            }
            return View(profile);
        }
        public ActionResult Index()
        {
            string cookieNick = string.Empty;
            string avatarNick = string.Empty;

            if (this.HttpContext.HasCookie(CookieManager.UserCookieName))
            {
                cookieNick = this.HttpContext.GetCookieValue(CookieManager.UserCookieName);
            }
            else
            {
                cookieNick = NicknamesHelper.GetRandomNick();
            }

            if (this.HttpContext.HasCookie(CookieManager.AvatarCookieName))
            {
                avatarNick = this.HttpContext.GetCookieValue(CookieManager.AvatarCookieName);
            }
            else
            {
                avatarNick = AvatarsHelper.GetRandomAvatar();
            }

            FormsAuthentication.SetAuthCookie(cookieNick, true);
            ProfileViewModel viewModel = new ProfileViewModel(cookieNick, avatarNick, this.GetAvatarList());

            return View(viewModel);
        }
 public ActionResult Index(ProfileViewModel profile)
 {
     if (profile == null || string.IsNullOrEmpty(profile.Nick) || string.IsNullOrEmpty(profile.Avatar) || GameHub.NickIsInUse(profile.Nick))
     {
         profile.AvatarsList = this.GetAvatarList();
         profile.Nick = NicknamesHelper.GetRandomNick();
         profile.Avatar = AvatarsHelper.GetRandomAvatar();
         return View(profile);
     }
     else
     {
         CookieManager.WriteCookie(this.HttpContext, CookieManager.UserCookieName, profile.Nick);
         CookieManager.WriteCookie(this.HttpContext, CookieManager.AvatarCookieName, profile.Avatar);
         TempData["profileData"] = profile;
         return RedirectToAction("Index", "Game");
     }
 }
 public ActionResult Randomize()
 {
     ProfileViewModel profile = new ProfileViewModel();
     profile.AvatarsList = this.GetAvatarList();
     profile.Nick = NicknamesHelper.GetRandomNick();
     profile.Avatar = AvatarsHelper.GetRandomAvatar();
     CookieManager.WriteCookie(this.HttpContext, CookieManager.UserCookieName, profile.Nick);
     CookieManager.WriteCookie(this.HttpContext, CookieManager.AvatarCookieName, profile.Avatar);
     TempData["profileData"] = profile;
     return RedirectToAction("Index", "Game");
 }