PostPenalty([FromForm] PenaltyRequest penaltyRequest) { if (!await CheckIsUserAuthorizedForAction (penaltyRequest.Id, penaltyRequest.Token)) { return(BadRequest("You have not enough permissions for this action")); } if (penaltyRequest.CarId == null) { return(BadRequest("Cannot create penalty for empty CarId")); } var car = await _carService.GetById(penaltyRequest.CarId); if (car == null) { return(BadRequest($"The car with id {penaltyRequest.CarId} not exist")); } var penalty = _customMapper .PenaltyRequestToPenalty(penaltyRequest); await _penaltyRepository.Create(penalty); await _penaltyRepository.SaveChangesAsync(); return(Created( ApiRoutes.PenaltiesRoutes.Create, new Response <PenaltyResponse>( _customMapper.PenaltyToPenaltyResponse(penalty)))); }