public async Task <IActionResult> PostAsync([FromBody] AdminKeyProtected <Demand> adminKeyProtectedDemand) { NullCheck.ThrowIfNull <Demand>(adminKeyProtectedDemand); // This is a temporary solution until #103 is done. if (!_adminKey.Equals(adminKeyProtectedDemand.adminKey, StringComparison.InvariantCulture)) { return(StatusCode(403)); } Demand demand = adminKeyProtectedDemand.data; try { _mailInputValidatorService.validateMail(demand.provider.mail); _resourceDemandInputValidatorService.ValidateForDemandInsertion(demand); var token = await _resourceDemandUpdateService.InsertAsync(demand); return(Ok(token)); } catch (UnknownAdressException e) { return(BadRequest(e.Message)); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
public void InsertDemand_AllowedInputs() { // The captain hook demand Demand demand = _captainHookGenerator.GenerateDemand(); _service.ValidateForDemandInsertion(demand); // With minimal data Demand demand2 = new Demand() { provider = new Provider() { organisation = "test", name = "name", mail = "*****@*****.**" }, consumables = new List <Consumable>() { new Consumable() { category = "MASKE", amount = 10, unit = "Stück" } } }; _service.ValidateForDemandInsertion(demand2); }