public async Task <bool> Handle(CreateSpeciesRequest message, IOutboundPort <NewEntityResponse <int> > outputPort) { var species = _entityFactory.GetSpeciesBuilder() .SetName(message.Name) .SetScientificName(message.ScientificName) .SetLatitude(message.Latitude) .SetLongitude(message.Longitude) .Build(); // validate some stuff: if (string.IsNullOrWhiteSpace(species.Name) || string.IsNullOrEmpty(species.ScientificName) || Math.Abs(species.DefaultLatitude) > 90.0 || Math.Abs(species.DefaultLongitude) > 180.0) { return(false); } var response = new NewEntityResponse <int> { Id = await _petStore.Create(species) }; outputPort.Handle(response); return(true); }
public async Task AddAsync(CreateSpeciesRequest request) { if (string.IsNullOrEmpty(request.Name)) { throw new BadRequestException("Imię nie może być puste."); } await _speciesRepository.AddAsync(new Species() { Name = request.Name }); }
public async Task <IActionResult> CreateNewSpecies([FromBody] CreateSpeciesRequest model) { if (!ModelState.IsValid || string.IsNullOrWhiteSpace(model.Name) || string.IsNullOrEmpty(model.ScientificName) || Math.Abs(model.Latitude) > 90.0 || Math.Abs(model.Longitude) > 180.0) { return(BadRequest(ModelState)); } var port = new BasicPresenter <NewEntityResponse <int> >(); var success = await _addSpecies.Handle(model, port); return((success) ? new OkObjectResult(port.Response.Id) : BadRequest()); }
public async Task <IActionResult> Create([FromBody] CreateSpeciesRequest request) { await _speciesService.AddAsync(request); return(Ok()); }