예제 #1
0
        public IActionResult Post([FromBody] TeamModelIn teamIn)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Team team = teamIn.TransformToEntity();
                    team = teamService.CreateTeam(team);
                    TeamModelOut modelOut = new TeamModelOut(team);

                    return(CreatedAtRoute("Get", new { id = team.TeamId }, modelOut));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (NotUniqueException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(BadRequest("Ha ocurrido un error" + ex.Message));
            }
        }
예제 #2
0
 public IActionResult Put(int id, [FromBody] TeamModelIn modelIn)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Team team = modelIn.TransformToEntity();
             teamService.UpdateTeam(id, team);
             return(Ok("El equipo ha sido modificado"));
         }
         else
         {
             return(BadRequest(ModelState));
         }
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex.Message));
     }catch (NotExistsException ex)
     {
         return(BadRequest(ex.Message));
     }catch (NotUniqueException ex)
     {
         return(BadRequest(ex.Message));
     }
 }