示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            ChallongeApi challongeApi = new ChallongeApi(new System.Net.Http.HttpClient(), null);


            challongeApi.ApiKey = "QmEFdJ0xtKy6TqcXoXm0YiTxXuONlYBxoYaC1WHM";

            Models.TournamentElement cr = null;

            try
            {
                cr = challongeApi.Tournaments.PostTournament(new Models.CreateTournament()
                {
                    Url = "eerrr"
                });
            }
            catch (HttpOperationException e)
            {
                var errors = Errors.FromJson(e.Response.Content);
                throw;
            }


            var c = challongeApi.Tournaments.GetTournament("692tf7fz", true, true);

            Console.ReadKey();
        }
示例#2
0
        public async Task <ActionResult> RegisterChal(RegisterChalViewModel model)
        {
            if (ModelState.IsValid)
            {
                ChallongeApi api = new ChallongeApi();
                api.setCredentials(model.Username, model.ApiKey);
                var emailcheck = db.Users.Where(u => u.Email == model.Email).ToList();
                if (emailcheck.Count() == 0)
                {
                    if (api.setCredentials(api.getCredentials().Item1, api.getCredentials().Item2))
                    {
                        var user = new ApplicationUser
                        {
                            UserName = model.Username,
                            Email    = model.Email
                        };

                        user.ApiKey = model.ApiKey;

                        var result = await UserManager.CreateAsync(user, model.ApiKey);

                        if (result.Succeeded)
                        {
                            await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid Challonge username or password.");
                        return(View(model));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "An account with that email address already exists.");
                    return(View(model));
                }
            }
            return(View(model));
        }