public Result <FootballTeamDto> AddFootballTeam(AddFootballTeamDto teamDto) { Result <FootballTeamDto> result = new Result <FootballTeamDto>(); if (teamDto == null) { result.SetError("Please provide a team to add!"); return(result); } try { FootballTeamDto newTeamDto = this.teamsRepository.AddTeam(teamDto); result.SetSuccess("Team added successfully."); return(result.SetData(newTeamDto)); } catch (Exception ex) { result.SetError(ex.Message); return(result); } }
public FootballTeamDto AddTeam(AddFootballTeamDto teamToAdd) { FootballTeam team = Mapper.Map <AddFootballTeamDto, FootballTeam>(teamToAdd); this.context.FootballTeams.Add(team); this.context.SaveChanges(); FootballTeamDto addedTeam = Mapper.Map <FootballTeam, FootballTeamDto>(team); return(addedTeam); }
public ActionResult AddFootballTeam(AddFootballTeamViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } // Generate the token and send it AddFootballTeamDto teamToAdd = Mapper.Map <AddFootballTeamViewModel, AddFootballTeamDto>(viewModel); Result <FootballTeamDto> result = this.service.AddFootballTeam(teamToAdd); if (result.IsError) { ModelState.AddModelError("", $"Error: { result.Message }"); } return(RedirectToAction("FootballTeams", "FootballTeam")); }