public async Task <IActionResult> ShowLeague(string id) { User user = _SessionHelper.GetSessionUser(HttpContext); LeagueViewModel leagueViewModel = new LeagueViewModel(); try { // Get League string uri = "/League/GetLeague/"; var response = await _APIhelper.GetLeagueAsync(string.Concat(uri, id)); if (response.GetType() == typeof(Dictionary <string, string>)) { var dict = response as Dictionary <string, string>; ViewBag.Error = dict["Content"]; } leagueViewModel.League = response as League; leagueViewModel.User = user; leagueViewModel.Advert = await _Adhelper.ShowAd(); return(View("ShowLeague", leagueViewModel)); } catch (Exception ex) { ViewBag.Error = ex.Message; return(View("ShowLeague", leagueViewModel)); } }
public virtual ActionResult Edit(LeagueViewModel model) { if (ModelState.IsValid) { var league = _leagueService.GetById(model.LeagueId); league.Country = model.Country; league.DescriptionName = model.DescriptionName; league.Name = model.Name; if (model.Image != null) { var imageManager = new ImageManager(model.Image, ImageFolder.Leagues, string.Empty); if (!string.IsNullOrEmpty(league.ImagePath)) { RemoveImage(imageManager, league.ImagePath); } if (UploadImage(imageManager)) { league.ImagePath = imageManager.FilePath; } } _leagueService.Update(league); return(RedirectToAction(MVC.Admin.Leagues.Index())); } return(View(model)); }
public async Task <IActionResult> Create(LeagueViewModel model) { if (ModelState.IsValid) { var currentUser = await User.GetApplicationUser(_userManager); var league = new League { Id = Guid.NewGuid(), Name = model.Name, CreatedByUser = currentUser }; _context.League.Add(league); _context.LeaguePlayers.Add(new LeaguePlayer { Id = Guid.NewGuid(), League = league, User = currentUser }); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> ShowLeagueStats(int TipTypeId, int LeagueId) { decimal TotalPlayed = await leagueRepository.GetLeagueTotalPlayed(LeagueId, TipTypeId); decimal Wins = await leagueRepository.GetLeagueWins(LeagueId, TipTypeId); decimal Odds = await leagueRepository.GetLeagueAverageOdds(LeagueId, TipTypeId); decimal Percentage = PercentageCalculator.CalculatePercentage(TotalPlayed, Wins); decimal Roi = PercentageCalculator.CalculateRoi(TotalPlayed, Wins, Odds); LeagueViewModel lVM = new LeagueViewModel { LeagueTotalPlayed = TotalPlayed, LeagueWins = Wins, LeaguePercentage = Percentage, LeagueAverageOdds = Odds, LeagueRoi = Roi, League = await leagueRepository.GetLeagueByIdAsync(LeagueId), Predictions = await leagueRepository.GetPredictionsByLeagueAndTipType(LeagueId, TipTypeId), TipStats = await repository.GetTipStatsByLeague(TipTypeId, LeagueId), ControllerName = "Statistics", TipTypeId = TipTypeId }; ViewData["TipTypeId"] = TipTypeId; return(View("League", lVM)); }
public IActionResult Create(LeagueViewModel league, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var newLeague = new League { Name = league.Name, MaxNumberFranchises = league.MaxSize, IsPrivate = league.IsPrivate, CommissionerId = _userManager.GetUserId(User), Points = 0, Value = 0 }; //league.CommissionerId = _owners.GetOwnerId( Convert.ToInt32( _userManager.GetUserId( User ) ) ); _leagues.Add(newLeague); if (returnUrl != null) { Redirect(returnUrl); } else { return(RedirectToAction(nameof(Index))); } } return(View(league)); }
public async Task <IActionResult> Create(LeagueViewModel model) { if (ModelState.IsValid) { var path = string.Empty; if (model.LogoFile != null) { path = await _imageHelper.UploadImageAsync(model.LogoFile, "Leagues"); } var league = _converterHelper.ToLeagueEntity(model, path, true); _context.Add(league); try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "Esta Liga ya existe"); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } } return(View(model)); }
public async Task <bool> DeleteLeaguesAsync(List <string> leagueIDsToDelete, CancellationToken ct = default(CancellationToken)) { List <bool> dbOperation = new List <bool>(); // we do not actually want to delete the league rather just mark it as inactive foreach (string deleteID in leagueIDsToDelete) { // unassign teams. Perhaps instead of unassigning, simply leave them? List <TeamViewModel> teamsToUnassign = await GetTeamsByLeagueId(deleteID, ct); await UnassignTeamsAsync(teamsToUnassign.Select(t => t.Id).ToList(), ct); List <LeagueSessionScheduleViewModel> sessionsToDeactive = await GetAllSessionsByLeagueIdAsync(deleteID, ct); // deactive this session foreach (LeagueSessionScheduleViewModel session in sessionsToDeactive) { // only update sessions that active if (session.Active == true) { session.Active = false; dbOperation.Add(await UpdateSessionScheduleAsync(session, ct)); } } // marking individual matches and match results as inactive for deleted leagues // may be unecessary, since we need to be filtering out to display only those sessions // and leagues that are active LeagueViewModel leagueToDelete = await GetLeagueByIdAsync(deleteID, ct); leagueToDelete.Active = false; dbOperation.Add(await UpdateLeagueAsync(leagueToDelete, ct)); } return(dbOperation.All(op => op == true)); }
// PUT api/<controller>/5 public HttpResponseMessage Put(LeagueViewModel viewModel) { try { if (ModelState.IsValid) { var league = _leagueService.GetLeague(viewModel.Id); var leagueType = _leagueTypeService.GetLeagueType(viewModel.LeagueTypeId); league.Name = viewModel.Name; league.LeagueType = leagueType; _leagueService.SaveLeague(league); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Invalid Model")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ActionResult Create() { var user = System.Web.HttpContext.Current.GetCurrentUser(); LeagueViewModel model = LeagueExtensions.CreateNewLeague(user.UserId); return(View(model)); }
public virtual ActionResult Create(LeagueViewModel model) { if (ModelState.IsValid) { var league = new League() { Name = model.Name, Country = model.Country, DescriptionName = model.DescriptionName }; if (model.Image != null) { var imageManager = new ImageManager(model.Image, ImageFolder.Leagues, string.Empty); if (UploadImage(imageManager)) { league.ImagePath = imageManager.FilePath; } } _leagueService.Create(league); return(RedirectToAction(MVC.Admin.Leagues.Index())); } return(View(model)); }
public ActionResult Create() { LeagueViewModel model = new LeagueViewModel(); PopulateStaticData(model); return(View(model)); }
public async Task <List <LeagueSessionScheduleViewModel> > GetAllActiveSessionsAsync(CancellationToken ct = default(CancellationToken)) { // this will ensure that whenever we retrieve sessions we always check to see they are active or not // await this.UpdateActiveSessionsAsync(); List <LeagueSessionScheduleViewModel> activeSessions = LeagueSessionScheduleConverter.ConvertList(await this._sessionScheduleRepository.GetAllActiveSessionsAsync(ct)); HashSet <TeamViewModel> teams = new HashSet <TeamViewModel>(); // for each session loop through all matches and include the team. EF is not returning teams for some reason. HomeTeam or AwayTeam foreach (LeagueSessionScheduleViewModel session in activeSessions) { foreach (MatchViewModel match in session.Matches) { TeamViewModel awayTeam = null; TeamViewModel homeTeam = null; // if the match has a bye, AwayTeamId won't be set if (match.AwayTeamId != null) { awayTeam = await this.GetTeamByIdAsync(match.AwayTeamId, ct); } // if the match has a bye, HomeTeamId won't be set if (match.HomeTeamId != null) { homeTeam = await this.GetTeamByIdAsync(match.HomeTeamId, ct); } match.AwayTeamName = awayTeam?.Name ?? "BYE"; match.HomeTeamName = homeTeam?.Name ?? "BYE"; match.MatchResult.SessionId = session.Id; // stash retrieved teams so we don't have to hit the database again to retrieve team names teams.Add(awayTeam); teams.Add(homeTeam); } // teamSession.teamName is used by the front end scoreboard to avoid having dependency on sport types store. Before // /scoreboards route expected sport types store to have values, but if user navigates straight to scoreboards then // we cannot display a filter to allow user to filter by team name easily foreach (TeamSessionViewModel teamSession in session.TeamsSessions) { teamSession.TeamName = teams.Where(t => t?.Id == teamSession.TeamId).FirstOrDefault()?.Name; } LeagueViewModel league = await GetLeagueByIdAsync(session.LeagueID, ct); // these properties are not set by converters because they do not belong on the model session.LeagueName = league?.Name; SportTypeViewModel sportType = await GetSportTypeByIdAsync(league.SportTypeID, ct); // these properties are not set by converters because they do not belong on the model session.SportTypeID = sportType?.Id; session.SportTypeName = sportType?.Name; } return(activeSessions); }
public LeagueEntity ToLeagueEntity(LeagueViewModel model, string path, bool isNew) { return(new LeagueEntity { Id = isNew ? 0 : model.Id, LogoPath = path, Name = model.Name }); }
public ActionResult Edit(int id) { LeagueViewModel model = new LeagueViewModel(); model.League = leagueService.Get(id); PopulateStaticData(model); return(View(model)); }
public async Task <ActionResult <LeagueViewModel> > GetLeagueById(string id, CancellationToken ct = default(CancellationToken)) { LeagueViewModel league = await this._supervisor.GetLeagueByIdAsync(id, ct); if (league == null) { return(BadRequest(Errors.AddErrorToModelState(ErrorCodes.LeagueRetrieval, ErrorDescriptions.LeagueNotFound, ModelState))); } return(new JsonResult(league)); }
public async Task <ActionResult <LeagueViewModel> > Create([FromBody] LeagueViewModel newLeague, CancellationToken ct = default(CancellationToken)) { newLeague = await this._supervisor.AddLeagueAsync(newLeague, ct); if (newLeague == null) { return(BadRequest(Errors.AddErrorToModelState(ErrorCodes.LeagueAdd, ErrorDescriptions.LeagueAddFailure, ModelState))); } return(new JsonResult(newLeague)); }
public ActionResult AddLeague(LeagueViewModel leagueModel) { if (ModelState.IsValid) { var leagueDataModel = MappingService.MappingProvider.Map <League>(leagueModel); this.leagueService.Add(leagueDataModel); } this.TempData[GlobalConstants.SuccessMessage] = string.Format("League {0} added successfully!", leagueModel.Name); return(this.RedirectToAction <LeaguesGridController>(action => action.Index())); }
private LeagueViewModel Map(League league) { var viewModel = new LeagueViewModel(); viewModel.Id = league.Id; viewModel.Name = league.Name; viewModel.StartDate = league.StartDate; viewModel.EndDate = league.EndDate; viewModel.Users = league.Users.Select(MapUsers); viewModel.LeagueTypeId = league.LeagueType.Id; return(viewModel); }
// GET: League public IActionResult Index() { var leagues = _leagueRepository.GetAllLeagues().OrderBy(l => l.Name); var leagueViewModel = new LeagueViewModel() { Title = "Manage Leagues", Leagues = leagues.ToList() }; return(View(leagueViewModel)); }
public static LeagueViewModel Convert(League league) { LeagueViewModel model = new LeagueViewModel(); model.Id = league.Id; model.Selected = league.Selected; model.Active = league.Active; model.SportTypeID = league.SportTypeID; model.Teams = league.Teams == null ? null : TeamConverter.ConvertList(league.Teams); model.Type = league.Type; model.Name = league.Name; return(model); }
public IActionResult Create([Bind("Name")] LeagueViewModel leagueViewModel) { if (ModelState.IsValid) { var league = new League() { Name = leagueViewModel.Name }; _leagueRepository.Add(league); _leagueRepository.Save(); return(RedirectToAction("Index")); } return(View(leagueViewModel)); }
public ActionResult AddLeague() { var countriesList = this.countryService.GetAll() .Select(c => new SelectListItem() { Text = c.Name, Value = c.Name }); var leagueViewModel = new LeagueViewModel() { CountriesSelectList = countriesList }; return(this.PartialView(PartialViews.AddLeague, leagueViewModel)); }
public void Create_ReturnsRedirectToIndex_WhenModelIsValid() { //Arrange var leagueViewModel = new LeagueViewModel(); //Act var result = _leagueController.Create(leagueViewModel); //Assert Assert.NotNull(result); var redirectResult = Assert.IsAssignableFrom <RedirectToActionResult>(result); Assert.Null(redirectResult.ControllerName); Assert.Equal("Index", redirectResult.ActionName); }
public void Create_ReturnsLeagueViewModelCreate_WhenModelIsNotValid() { //Arrange var leagueViewModel = new LeagueViewModel(); _leagueController.ModelState.AddModelError("Name", "Required"); //Act var result = _leagueController.Create(leagueViewModel); //Assert Assert.NotNull(result); var viewResult = Assert.IsAssignableFrom <ViewResult>(result); var viewModel = Assert.IsAssignableFrom <LeagueViewModel>(viewResult.ViewData.Model); }
public ActionResult Create(LeagueViewModel model) { if (ModelState.IsValid) { // TODO Refactor at some point model.League.Season = competitionService.GetSeasons(s => s.Id == model.SeasonId)[0]; leagueService.Insert(model.League); leagueService.Commit(); SuccessMessage(FormMessages.SaveSuccess); return(RedirectToAction("Index")); } PopulateStaticData(model); return(View(model)); }
public async Task <LeagueViewModel> AddLeagueAsync(LeagueViewModel newLeague, CancellationToken ct = default(CancellationToken)) { League league = new League() { Name = newLeague.Name, Selected = newLeague.Selected, SportTypeID = newLeague.SportTypeID, Type = newLeague.Type }; league = await this._leagueRepository.AddAsync(league, ct); newLeague.Id = league.Id; return(newLeague); }
public static List <LeagueViewModel> ConvertList(IEnumerable <League> leagues) { return(leagues.Select(league => { LeagueViewModel model = new LeagueViewModel(); model.Id = league.Id; model.Selected = league.Selected; model.Active = league.Active; model.SportTypeID = league.SportTypeID; model.Teams = league.Teams == null ? null : TeamConverter.ConvertList(league.Teams); model.Type = league.Type; model.Name = league.Name; return model; }).ToList()); }
// GET: League/Edit/id public IActionResult Edit(int id) { var league = _leagueRepository.GetLeagueById(id); if (league == null) { return(NotFound()); } var viewModel = new LeagueViewModel() { Name = league.Name, Id = league.Id }; return(View(viewModel)); }
public async Task <bool> UpdateLeagueAsync(LeagueViewModel leagueToUpdate, CancellationToken ct = default(CancellationToken)) { League league = await this._leagueRepository.GetByIdAsync(leagueToUpdate.Id, ct); if (league == null) { return(false); } // only update those properties which have been set on the incoming league league.Selected = league.Selected; league.SportTypeID = leagueToUpdate.SportTypeID ?? league.SportTypeID; league.Type = leagueToUpdate.Type ?? league.Type; league.Name = leagueToUpdate.Name ?? league.Name; league.Active = leagueToUpdate.Active; return(await this._leagueRepository.UpdateAsync(league, ct)); }
// GET: Leagues/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } LeagueEntity leagueEntity = await _context.Leagues.FindAsync(id); if (leagueEntity == null) { return(NotFound()); } LeagueViewModel model = _converterHelper.ToLeagueViewModel(leagueEntity); return(View(model)); }