Пример #1
0
 public async Task <ActionResult <TeamModel> > Post(TeamModel model)
 {
     try
     {
         var team = _mapper.Map <Team>(model);
         if (await _repository.GetTeamByNameAsync(team.Name) != null)
         {
             return(StatusCode(StatusCodes.Status409Conflict, "Team with same name already exists!"));
         }
         _repository.Add(team);
         var stats = new Statistics {
             Goals = 0,
             Games = 0,
             Wins  = 0,
             Draws = 0,
             Loses = 0,
             Team  = team.Name
         };
         _repository.Add(stats);
         if (await _repository.SaveChangesAsync())
         {
             var location = _linkGenerator.GetPathByAction(HttpContext,
                                                           "Get",
                                                           values: new { id = team.TeamId });
             return(Created(location, _mapper.Map <TeamModel>(team)));
         }
     }
     catch (Exception)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure!"));
     }
     return(BadRequest());
 }