public async Task <IActionResult> Edit(UserRosterViewModel model) { var formation = model.Roster.Formation; var matchday = this.matchdaysService .GetCurrentMatchday <Matchday>(); var roster = this.rostersService .GetCurrentUserRoster(User.Identity.Name); var result = await this.rostersService .SetNewFormationAsync(formation, roster.Id); if (!result.Succeeded) { return(RedirectToAction( ActionConstants.Error, PagesConstants.Home, new { area = "", errorMessage = result.Error })); } var editRosterModel = new EditRosterViewModel { Formation = formation, Matchday = roster.Matchday, Goalkeepers = roster.Players.Where(x => x.Position == PlayerPosition.Goalkeeper).ToList(), Attackers = roster.Players.Where(x => x.Position == PlayerPosition.Attacker).ToList(), Midfielders = roster.Players.Where(x => x.Position == PlayerPosition.Midfielder).ToList(), Defenders = roster.Players.Where(x => x.Position == PlayerPosition.Defender).ToList() }; return(View(editRosterModel)); }
public async Task <IActionResult> Edit(EditRosterViewModel editRosterModel) { var formation = editRosterModel.Formation; var players = editRosterModel.Goalkeepers .Concat(editRosterModel.Defenders) .Concat(editRosterModel.Midfielders) .Concat(editRosterModel.Attackers) .ToList(); var rosterId = players.First().RosterId; var result = await this.rostersService.EditAsync(players); if (!result.Succeeded) { return(RedirectToAction( ActionConstants.Error, PagesConstants.Home, new { area = "", errorMessage = result.Error })); } return(RedirectToAction( ActionConstants.Index, PagesConstants.Rosters)); }