Ejemplo n.º 1
0
        public async void TestForAddLeague()
        {
            var options = new DbContextOptionsBuilder <LeagueContext>()
                          .UseInMemoryDatabase(databaseName: "p3LogicAddLeague")
                          .Options;

            using (var context = new LeagueContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repo  r     = new Repo(context, new NullLogger <Repo>());
                Logic logic = new Logic(r, new NullLogger <Repo>());
                var   sport = new Sport
                {
                    SportID   = 35,
                    SportName = "basketball"
                };

                r.Sports.Add(sport);
                await r.CommitSave();

                var leagueDto = new CreateLeagueDto
                {
                    LeagueName = "sports",
                    SportName  = sport.SportName
                };

                var newLeague = await logic.AddLeague(leagueDto);

                Assert.Contains <League>(newLeague, context.Leagues);
            }
        }
Ejemplo n.º 2
0
        public static async Task <GetLeagueResponse> CreateLeague(CreateLeagueDto createLeagueDto, string accessToken)
        {
            Uri address = new Uri(AppConfig.BaseUrl + AppConfig.OrganizerCreateLeague);
            var client  = new HttpClient();

            client.DefaultRequestHeaders.Add("x-access-token", accessToken);
            var content = new StringContent(JsonConvert.SerializeObject(createLeagueDto), Encoding.UTF8, "application/json");

            try
            {
                var result = await client.PostAsync(address, content).ConfigureAwait(false);

                if (result.IsSuccessStatusCode)
                {
                    var jsonResponse = await result.Content.ReadAsStringAsync();

                    var response = Newtonsoft.Json.JsonConvert
                                   .DeserializeObject <dynamic>(jsonResponse);
                    var serilize = JsonConvert.SerializeObject(response.response);
                    var league   = JsonConvert.DeserializeObject <GetLeagueResponse>(serilize);
                    return(league);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                throw e.InnerException;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds league with league name and sport name
        /// Adds the sport to the db if it doesn't exist
        /// </summary>
        /// <param name="cld"></param>
        /// <returns></returns>
        public async Task <League> AddLeague(CreateLeagueDto cld)
        {
            Sport sport = new Sport {
                SportName = cld.SportName
            };

            if (await SportExists(cld.SportName) == false)
            {
                _repo.Sports.Add(sport);
                await _repo.CommitSave();
            }

            if (await LeagueExists(cld.LeagueName) == false)
            {
                League league = new League
                {
                    LeagueName = cld.LeagueName,
                    SportID    = sport.SportID,
                };
                _repo.Leagues.Add(league);
                await _repo.CommitSave();

                return(league);
            }
            return(null);
        }
 public async Task <IActionResult> CreateLeague([FromBody] CreateLeagueDto cld)
 {
     if (await _logic.LeagueExists(cld.LeagueName) == true)
     {
         return(Conflict("League with that name already exists."));
     }
     return(Ok(await _logic.AddLeague(cld)));
 }
        public void ValidateCreateLeagueDto()
        {
            var league = new CreateLeagueDto()
            {
                LeagueName = "sports",
                SportName  = "basketball"
            };

            var errorcount = ValidateModel(league).Count;

            Assert.Equal(0, errorcount);
        }
        public async void TestForCreateLeague()
        {
            var options = new DbContextOptionsBuilder <LeagueContext>()
                          .UseInMemoryDatabase(databaseName: "p3LeagueControllerCreateLeague")
                          .Options;

            using (var context = new LeagueContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repo             r                = new Repo(context, new NullLogger <Repo>());
                Logic            logic            = new Logic(r, new NullLogger <Repo>());
                LeagueController leagueController = new LeagueController(logic);
                var sport = new Sport
                {
                    SportID   = 35,
                    SportName = "basketball"
                };

                r.Sports.Add(sport);
                await r.CommitSave();

                var leagueDto = new CreateLeagueDto
                {
                    LeagueName = "sports",
                    SportName  = sport.SportName
                };

                var createLeague = await leagueController.CreateLeague(leagueDto);

                Assert.IsAssignableFrom <League>((createLeague as OkObjectResult).Value);
                var createLeague2 = await leagueController.CreateLeague(leagueDto);

                Assert.IsAssignableFrom <string>((createLeague2 as ConflictObjectResult).Value);
            }
        }
Ejemplo n.º 7
0
        async Task SaveLeague()
        {
            IsBusy = true;
            if (String.IsNullOrWhiteSpace(SelectedSport.Name) || String.IsNullOrWhiteSpace(SelectedSport.Id))
            {
                UserDialogs.Instance.Alert("Please Select a Sport", "Wrong Input");
            }
            else if (String.IsNullOrWhiteSpace(SelectedLeagueType.Name) || String.IsNullOrWhiteSpace(SelectedLeagueType.Id))
            {
                UserDialogs.Instance.Alert("Please Select a League Type", "Wrong Input");
            }
            else if (String.IsNullOrWhiteSpace(LeagueName))
            {
                UserDialogs.Instance.Alert("Please enter a Name", "Wrong Input");
            }
            else if (selectedStartDate > selectedEndDate)
            {
                UserDialogs.Instance.Alert("Start date can't be larger than End date", "Wrong Input");
            }
            else
            {
                var token = Newtonsoft.Json.JsonConvert.DeserializeObject <Token>(Settings.Token);

                var organizerCity = Cities.FirstOrDefault(c => c.Id == token.Organizer.CityRefId);

                var createLeagueDto = new CreateLeagueDto
                {
                    Name           = LeagueName,
                    Description    = Description,
                    LeagueType     = SelectedLeagueType,
                    Organizer      = token.Organizer,
                    Requirements   = Requirements,
                    RecLeagueEnd   = SelectedEndDate,
                    RecLeagueStart = SelectedStartDate,
                    Sport          = SelectedSport,
                    City           = organizerCity
                };

                var response = await OrganizerService.CreateLeague(createLeagueDto, token.AuthToken);

                if (response.Success)
                {
                    ClearAddOrganizerPage();

                    await Navigation.PopAsync();

                    Leagues = new ObservableCollection <League>(response.Leagues);

                    var notificator = DependencyService.Get <IToastNotificator>();

                    var options = new NotificationOptions()
                    {
                        Title       = "Success",
                        Description = "League has been Added",
                    };

                    var result = await notificator.Notify(options);
                }
                else
                {
                    UserDialogs.Instance.Alert("An error occured while adding the league!", "Error");
                }
            }
            IsBusy = false;
        }