public async Task <ActionResult <TeamSeason> > PostLeague(LeagueModel model) { try { var location = _linkGenerator.GetPathByAction("GetLeague", "Leagues", new { id = -1 }); if (string.IsNullOrWhiteSpace(location)) { return(BadRequest("Could not use ID")); } var league = _mapper.Map <League>(model); await _leagueRepository.AddAsync(league); if (await _sharedRepository.SaveChangesAsync() > 0) { return(Created(location, _mapper.Map <LeagueModel>(league))); } return(BadRequest()); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, Settings.DatabaseFailureString)); } }
public ActionResult <LeagueReadDto> GetLeagueById() { try { string leagueId = RouteData.Values["id"].ToString(); string userId = User.Identity.Name; int organisationId = _leagueService.GetOrganisationId(int.Parse(leagueId)); bool hasAccess = _leagueService.CheckLeagueAccess(int.Parse(userId), organisationId); if (!hasAccess) { return(Forbid()); } LeagueModel leagueModel = _leagueService.GetLeagueById(int.Parse(leagueId)); if (leagueModel == null) { return(NotFound()); } return(Ok(_mapper.Map <LeagueReadDto>(leagueModel))); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
private List <LeagueModel> processLeagues(IDocument response) { var leagues = new LeagueModels(); IDocument document = response; IHtmlCollection <IElement> leagueListTable = document.QuerySelectorAll("table tr:not(.LSport)"); foreach (IElement row in leagueListTable) { var league = new LeagueModel(); var cols = row.QuerySelectorAll("td"); cols.Each((td, index) => { var href = ""; var anchor = td.FirstElementChild; if (anchor != null) { href = anchor.GetAttribute("href"); } switch (index) { case 0: league.Title = td.TextContent; break; case 1: league.Fixture = href; break; case 2: league.Standing = href; break; } }); leagues.Add(league); } return(leagues); }
private void processLeagues(Task <string> response) { Leagues.ClearItems(); CQ dom = response.Result; var table = dom["table tr:not(.LSport)"]; var results = from row in table select row; foreach (var row in table) { var league = new LeagueModel(); CQ rowDom = row.Render(); var cols = rowDom["td"]; cols.ForEach((td, index) => { CQ text = td.Render(); var href = ""; var anchor = td.FirstChild; anchor.TryGetAttribute("href", out href); switch (index) { case 0: league.Title = anchor.Render().Replace("\t", "").Replace("\n", ""); break; case 1: league.Fixture = href; break; case 2: league.Standing = href; break; } }); Leagues.AddOnUIThread(league); } }
public void Initialize(int leagueID) { if (leagueID != 0) { LeagueDetails = DAL.Instance().GetLeague(leagueID); } }
public ActionResult DeleteLeagueById(int leagueId) { try { string userId = User.Identity.Name; LeagueModel league = _leagueService.GetLeagueById(leagueId); if (league == null) { return(NotFound()); } bool hasAccess = _leagueService.CheckLeagueAccess(int.Parse(userId), league.OrganisationId); if (!hasAccess) { return(Forbid()); } _leagueService.DeleteLeague(league); _leagueService.SaveChanges(); return(NoContent()); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
private void Get_Ligas() { // получить текущие лиги JToken leaguesJson = api.GetLeagues(); List <JToken> leagues = ApiModel.Parse(leaguesJson, "Sports League"); // записать их в свойство объекта LeaguesList foreach (JToken league in leagues) { LeagueModel leagueModel = new LeagueModel(); leagueModel.LeagueId = (long)league.SelectToken("LeagueId"); leagueModel.LeagueName = (string)league.SelectToken("LeagueName"); leagueModel.MarketTypeId = (int)league.SelectToken("MarketTypeId"); leagueModel.Since = (ulong)league.SelectToken("Since"); leagueModel.ListGames = new List <Game>(); leaguesList.Add(leagueModel); if (Ligs.IndexOf(leagueModel.LeagueName) < 0) // только новое имя лиги { Ligs.Add(leagueModel.LeagueName); } } // leaguesList.Clear(); // if read only ligas leaguesList.Sort((a, b) => a.LeagueName.CompareTo(b.LeagueName)); Ligs.Sort(); Lab.Content = "In Running" + " (" + Ligs.Count.ToString() + ")"; Ligas.Clear(); // new ? impossible rewrite for (int g = 0; g <= Ligs.Count - 1; g++) { Ligas.Add(new MyStr(Ligs[g])); } // return Ligass; }
public async Task <ActionResult <LeagueModel> > PostLeagueModelItem(LeagueModel item) { _context.LeagueModel.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetLeagueModelAllItems), new { id = item.Id }, item)); }
public async Task GetLeague_WhenExceptionIsCaught_ShouldReturnInternalServerError() { // Arrange var leagueRepository = A.Fake <ILeagueRepository>(); League?league = new League(); A.CallTo(() => leagueRepository.GetLeagueAsync(A <int> .Ignored)).Throws <Exception>(); var sharedRepository = A.Fake <ISharedRepository>(); var mapper = A.Fake <IMapper>(); LeagueModel?leagueModel = new LeagueModel(); A.CallTo(() => mapper.Map <LeagueModel>(A <League> .Ignored)).Returns(leagueModel); var linkGenerator = A.Fake <LinkGenerator>(); var testController = new LeaguesController(leagueRepository, sharedRepository, mapper, linkGenerator); int id = 1; // Act var result = await testController.GetLeague(id); // Assert result.Result.ShouldBeOfType <ObjectResult>(); ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError); ((ObjectResult)result.Result).Value.ShouldBe("Database failure"); }
public void CreateLeague(LeagueModelCreate leagueModelCreate) { if (leagueModelCreate == null) { throw new ArgumentNullException(nameof(leagueModelCreate)); } DateTime now = DateTime.Now; LeagueModel leagueModel = new LeagueModel(); leagueModel.Name = leagueModelCreate.Name; leagueModel.OrganisationId = leagueModelCreate.OrganisationId; leagueModel.TypeOfLeague = leagueModelCreate.TypeOfLeague; leagueModel.UpTo = leagueModelCreate.UpTo; leagueModel.Created_at = now; if (leagueModelCreate.HowManyRounds != null) { leagueModel.HowManyRounds = leagueModelCreate.HowManyRounds; } else { leagueModel.HowManyRounds = 2; } _context.Leagues.Add(leagueModel); _context.SaveChanges(); }
public async Task PutLeague_WhenLeagueIsFoundAndNotSaved_ShouldReturnBadRequestResult() { // Arrange var leagueRepository = A.Fake <ILeagueRepository>(); League?league = new League(); A.CallTo(() => leagueRepository.GetLeagueAsync(A <int> .Ignored)).Returns(league); var sharedRepository = A.Fake <ISharedRepository>(); A.CallTo(() => sharedRepository.SaveChangesAsync()).Returns(0); var mapper = A.Fake <IMapper>(); var returnModel = new LeagueModel(); A.CallTo(() => mapper.Map <LeagueModel>(league)).Returns(returnModel); var linkGenerator = A.Fake <LinkGenerator>(); var testController = new LeaguesController(leagueRepository, sharedRepository, mapper, linkGenerator); int id = 1; var model = new LeagueModel(); // Act var result = await testController.PutLeague(id, model); // Assert A.CallTo(() => leagueRepository.GetLeagueAsync(id)).MustHaveHappenedOnceExactly(); A.CallTo(() => mapper.Map(model, league)).MustHaveHappenedOnceExactly(); A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => mapper.Map <LeagueModel>(league)).MustNotHaveHappened(); result.Result.ShouldBeOfType <BadRequestResult>(); }
public async Task GetLeague_WhenLeagueIsNotNull_ShouldReturnLeagueModelOfDesiredLeague() { // Arrange var leagueRepository = A.Fake <ILeagueRepository>(); League?league = new League(); A.CallTo(() => leagueRepository.GetLeagueAsync(A <int> .Ignored)).Returns(league); var sharedRepository = A.Fake <ISharedRepository>(); var mapper = A.Fake <IMapper>(); LeagueModel?leagueModel = new LeagueModel(); A.CallTo(() => mapper.Map <LeagueModel>(A <League> .Ignored)).Returns(leagueModel); var linkGenerator = A.Fake <LinkGenerator>(); var testController = new LeaguesController(leagueRepository, sharedRepository, mapper, linkGenerator); int id = 1; // Act var result = await testController.GetLeague(id); // Assert A.CallTo(() => leagueRepository.GetLeagueAsync(id)).MustHaveHappenedOnceExactly(); A.CallTo(() => mapper.Map <LeagueModel>(league)).MustHaveHappenedOnceExactly(); result.Value.ShouldBeOfType <LeagueModel>(); }
public IActionResult GetLeagueMatchups(LeagueModel league) { var chosenLeague = _context.LeagueModel.First(a => a.Name == league.Name); var viewModel = new ScoreViewModel(_context.MatchupModel.ToList().Where(a => a.LeagueId == chosenLeague.Id).ToList(), _context.LeagueModel.ToList()); return(View("ScoreView", viewModel)); }
public async Task PutLeague_WhenLeagueIsNotFound_ShouldReturnNotFoundResult() { // Arrange var leagueRepository = A.Fake <ILeagueRepository>(); League?league = null; A.CallTo(() => leagueRepository.GetLeagueAsync(A <int> .Ignored)).Returns(league); var sharedRepository = A.Fake <ISharedRepository>(); var mapper = A.Fake <IMapper>(); var linkGenerator = A.Fake <LinkGenerator>(); var testController = new LeaguesController(leagueRepository, sharedRepository, mapper, linkGenerator); int id = 1; var model = new LeagueModel(); // Act var result = await testController.PutLeague(id, model); // Assert A.CallTo(() => leagueRepository.GetLeagueAsync(id)).MustHaveHappenedOnceExactly(); result.Result.ShouldBeOfType <NotFoundObjectResult>(); ((NotFoundObjectResult)result.Result).Value.ShouldBe($"Could not find league with ID of {id}"); }
public IActionResult CreateLeague([FromBody] LeagueModel teamModel) { var command = new CreateLeagueCommand(teamModel); CommandDispatcher.Handle(command); return(Ok()); }
public async Task <ActionResult <LeagueModel> > PutLeague(int id, LeagueModel model) { try { var league = await _leagueRepository.GetLeagueAsync(id); if (league is null) { return(NotFound($"Could not find league with ID of {id}")); } _mapper.Map(model, league); if (await _sharedRepository.SaveChangesAsync() > 0) { return(_mapper.Map <LeagueModel>(league)); } return(BadRequest()); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, Settings.DatabaseFailureString)); } }
public async Task <IHttpActionResult> Summary(int id, int value) { var league = leagueRepository.GetById(id); var leagueMatches = leagueMatchRepository.GetMany(lm => lm.LeagueId == id && lm.TossDone == true).OrderBy(lm => lm.MatchDate).ToList(); var isMyLeague = value == league.Creator; var CompUser = userRepository.GetById((isMyLeague ? league.Competitor : league.Creator)); swapValues(leagueMatches, isMyLeague); LeagueModel result = new LeagueModel() { LeagueId = league.LeagueId, Name = league.Name.Trim(), Points = (isMyLeague ? league.Points : league.Points * -1), SummaryMatches = leagueMatches, Accepted = league.Accepted, Competitor = league.Competitor.ToString().Trim(), CompetitorName = CompUser.UserName.Trim(), CompetitorPoint = (isMyLeague ? league.CompetitorPoint : league.CreatorPoint), Creator = league.Creator, CreatorPoint = (isMyLeague ? league.CreatorPoint : league.CompetitorPoint), IsMyLeague = isMyLeague, CompetitorFBId = CompUser.FacebookId.Trim(), }; return(Ok(result)); }
public IActionResult DeleteLeague([FromBody] LeagueModel leagueModel) { var command = new DeleteLeagueCommand(leagueModel); CommandDispatcher.Handle(command); return(Ok()); }
public void DeleteLeague(LeagueModel leagueModel) { if (leagueModel == null) { throw new ArgumentNullException(nameof(leagueModel)); } _context.Leagues.Remove(leagueModel); }
public void Update(LeagueModel model) { LeagueId = model.LeagueId; Name = model.Name; Host = model.Host; Type = model.Type; BuyIn = model.BuyIn; }
public List <StandingsModel> GetStandings(LeagueModel league) { Task <IDocument> task = BrowsingContext.New(AppState.config).OpenAsync($"{AppState.baseURL}{league.Standing}"); task.Wait(); return(processStandings(task.Result)); }
public ActionResult DeleteConfirmed(int id) { LeagueModel leagueModel = db.LeagueModels.Find(id); db.LeagueModels.Remove(leagueModel); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IHttpActionResult> Post(LeagueModel model) { //Add New League String compid = model.Competitor.ToString(); var appUser = userRepository.GetMany(u => u.FacebookId == compid).FirstOrDefault(); var creator = userRepository.GetById(model.Creator); var obj = new League { Name = model.Name, Competitor = appUser.UserId, Creator = model.Creator, CreateDate = DateTime.Now.Date, Accepted = 0, TournamentId = 1 }; var league = leagueRepository.Add(obj); unitofWork.SaveChanges(); //Insert Matches for League var matches = matchRepository.GetMany(m => m.TournamentId == 1).ToList(); foreach (var match in matches) { LeagueMatch lm = new LeagueMatch() { LeagueId = league.LeagueId, MatchDate = match.MatchDate, TeamId1 = match.TeamId1, TeamId2 = match.TeamId2, Toss = 0, TossDone = false, Venue = match.Venue, MatchId = match.MatchId, TeamName1 = teamRepository.GetById(match.TeamId1).ShortName, TeamName2 = teamRepository.GetById(match.TeamId2).ShortName }; leagueMatchRepository.Add(lm); } unitofWork.SaveChanges(); Notification notif = new Notification() { Title = creator.UserName, Message = "New Challange from " + creator.UserName + "- " + league.Name, Payload = new ChallangePayload() { leagueId = league.LeagueId, Tag = "LEAGUE_CHALLANGE", userId = model.Creator } }; NotificationHelper.sendNotification(appUser.DeviceToken, notif); return(Ok(league)); }
public override async Task SetDataFromServer(UpdateType crud) { if (crud == UpdateType.Update) { leagueModel = await leagueInteractor.GetEntityById(Url, "Error during getting league", EntityId); } SetTableViewModel(); }
public async Task AddLeague() { var payload = new LeagueModel { UserId = 1, Name = "Super 12", Location = "ZA" }; var response = await _client.PostAsync($"api/v1/RugbyManager/AddLeague", new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json")); response.StatusCode.Should().Be(System.Net.HttpStatusCode.OK); }
private void SetSelectedLeague() { foreach (var row in LeaguesList) { if (row.League.LeagueID.Equals(TeamDetails.Team.LeagueID)) { SelectedLeague = row; } } }
public ActionResult Edit([Bind(Include = "LeagueId,LeagueName,Description,Seasons")] LeagueModel leagueModel) { if (ModelState.IsValid) { db.Entry(leagueModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(leagueModel)); }
public async Task <IActionResult> CreateLeague(LeagueModel model) { var result = await _administratorService.CreateLeague(model, _context); if (result == 1) { return(View("PlayersError")); } return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "LeagueId,LeagueName,Description,Seasons")] LeagueModel leagueModel) { if (ModelState.IsValid) { db.LeagueModels.Add(leagueModel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(leagueModel)); }
private void SetDefaultSelectedLeague() { foreach (var row in LeaguesList) { if (row.League.LeagueName == AppResources.NoLeague) { SelectedLeague = row; break; } } }