Ejemplo n.º 1
0
        public IHttpActionResult CreateTeam(FootballTeamModel team)
        {
            var mappedTeam = FootballTeamMapping.Map(team);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(Ok(_teamService.CreateTeam(mappedTeam)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([FromBody] FootballTeamModel model)
        {
            var teamId = await _teamService.Create(model);

            Uri getDetailUri = new Uri(Url.AbsoluteAction("Get", "Team", new { id = teamId }));

            return(Created(getDetailUri, new
            {
                id = teamId.ToString("N")
            }));
        }
Ejemplo n.º 3
0
        public Task Update(Guid id, FootballTeamModel model)
        {
            CheckExist(id);
            var teamEntity = _teamRepository.Get(x => x.Id == id).Single();

            teamEntity.Coach   = model.Coach;
            teamEntity.Country = model.Country;
            teamEntity.Name    = model.Name;
            _teamRepository.Update(teamEntity, x => x.Coach, x => x.Country, x => x.Name);
            _unitOfWork.SaveChanges();
            return(Task.CompletedTask);
        }
Ejemplo n.º 4
0
        public async Task <Guid> Create(FootballTeamModel model)
        {
            var entity = new FootballTeamEntity()
            {
                Name    = model.Name,
                Country = model.Country,
                Coach   = model.Coach
            };

            _teamRepository.Add(entity);
            await _unitOfWork.SaveChangesAsync();

            return(entity.Id);
        }
Ejemplo n.º 5
0
        public static FootballTeam Map(FootballTeamModel team)
        {
            var config = new DefaultMapConfig();
            var result = config.ConvertUsing((FootballTeamModel source) =>
                                             new FootballTeam()
            {
                TeamName    = source.TeamName,
                WinsCount   = source.WinsCount,
                LossesCount = source.LossesCount
            });

            var team1 = ObjectMapperManager
                        .DefaultInstance
                        .GetMapper <FootballTeamModel, FootballTeam>(result)
                        .Map(new FootballTeamModel()
            {
                TeamName    = team.TeamName,
                WinsCount   = team.WinsCount,
                LossesCount = team.LossesCount
            });

            return(team1);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Update(Guid id, [FromBody] FootballTeamModel model)
        {
            await _teamService.Update(id, model);

            return(NoContent());
        }