Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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"));
        }