Ejemplo n.º 1
0
 public void GetLeagueTest()
 {
     BattleNetProfile target;
     target = new BattleNetProfile( @"http://eu.battle.net/sc2/ru/profile/267901/1/Zakk/" );
     target.DownloadData();
     Assert.AreEqual( "diamond_1", target.GetLeague(), true );
 }
Ejemplo n.º 2
0
        public ActionResult Edit(FormCollection collection)
        {
            try
            {
                var profile = profileRepository.GetProfile( profileRepository.GetUserId( User.Identity.Name ) );
                profile.first_name = Request.Form["first_name"];
                profile.last_name = Request.Form["last_name"];
                profile.details = Request.Form["details"];
                profile.country_id = Convert.ToInt32( Request.Form["country_id"] );

                var profileUrl = Request.Form["profile_url"];
                if (!String.IsNullOrEmpty( profileUrl ))
                {
                    var bnetProfile = new BattleNetProfile( profileUrl );
                    if (!bnetProfile.IsValidUrl())
                        return RedirectToAction( "Edit" );

                    bnetProfile.DownloadData();

                    profile.profile_url = profileUrl;
                    profile.bnet_name = bnetProfile.GetPlayerName();
                    profile.bnet_server = bnetProfile.GetServer();
                    profile.league = bnetProfile.GetLeague();
                    profile.race = bnetProfile.GetRace();
                    profile.avatar_style =
                        bnetProfile.GetPortraitHtmlStyle( @"/Content/img/bnet/" );
                    profile.achievements = bnetProfile.GetAchievementPoints();
                    profile.rank = bnetProfile.GetRank();
                    bnetProfile.GetStats();
                    profile.points = bnetProfile.Points;
                    profile.wins = Convert.ToInt32( bnetProfile.Wins );
                    profile.loses = Convert.ToInt32( bnetProfile.Loses );
                    profile.win_rate = bnetProfile.Percent;
                    profile.synchronized_at = DateTime.UtcNow;
                }
                else
                {
                    profile.profile_url = "";
                }

                profileRepository.Save();

                return RedirectToAction( "" );
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 3
0
        public ActionResult ReloadBnetData( String username )
        {
            var userProfile = userRepository.GetUserProfile( username );
            if (String.IsNullOrEmpty( userProfile.profile_url ))
                return Json( new {result = "profile_url_is_empty"}, JsonRequestBehavior.AllowGet );

            var bnetProfile = new BattleNetProfile( userProfile.profile_url );
            if (!bnetProfile.IsValidUrl())
                return Json( new { result = "profile_url_is_empty" }, JsonRequestBehavior.AllowGet );

            bnetProfile.DownloadData();
            userProfile.race = bnetProfile.GetRace();
            userProfile.bnet_name = bnetProfile.GetPlayerName();
            userProfile.bnet_server = bnetProfile.GetServer();
            userProfile.league = bnetProfile.GetLeague();
            userProfile.avatar_style = bnetProfile.GetPortraitHtmlStyle( @"/Content/img/bnet/" );
            userProfile.achievements = bnetProfile.GetAchievementPoints();
            userProfile.rank = bnetProfile.GetRank();
            bnetProfile.GetStats();
            userProfile.points = bnetProfile.Points;
            userProfile.wins = Convert.ToInt32( bnetProfile.Wins );
            userProfile.loses = Convert.ToInt32( bnetProfile.Loses );
            userProfile.win_rate = bnetProfile.Percent;
            userProfile.synchronized_at = DateTime.UtcNow;
            userRepository.Save();

            return Json( new { result = "ok" }, JsonRequestBehavior.AllowGet );
        }