public ActionResult Edit(int team_id) { string errorMsg = String.Empty; if (TempData.ContainsKey("error")) { errorMsg = TempData["error"].ToString(); } TeamsModel team = new TeamsModel(); TeamsVm model = new TeamsVm(); try { team = _teamService.GetTeam(team_id); } catch (Exception e) { TempData["error"] = $"Problems with getting information from database (services). {e.Message}"; return(RedirectToAction("Index")); } model.Id = team.Id; model.Name = team.Name; return(View("Edit", model)); }
public async Task <TeamViewModel> GetTeam(int teamId) { var team = await _teamsService.GetTeam(teamId); if (team == null) { throw new ApiException(404, "Team with this id is not found", ErrorCode.NotFound); } if (!team.UserTeams.Select(ut => ut.User).Any(u => u.Id == _currentUser.Id)) { throw new ApiException(401, "You are not authorized for this resource", ErrorCode.AuthError); } return(_mapper.Map <TeamViewModel>(team)); }