public Task <ActionResult <GiftAidResponse> > GetGiftAid([FromQuery] GiftAidRequest model, CancellationToken cancellation) { if (!ModelState.IsValid) { var error = BuildErrorMessage(); return(Task.FromResult <ActionResult <GiftAidResponse> >(BadRequest(error))); } cancellation.ThrowIfCancellationRequested(); var giftAid = _calculator.Calculate(model.Amount); var result = new GiftAidResponse(model.Amount, giftAid); return(Task.FromResult <ActionResult <GiftAidResponse> >(Ok(result))); }
public IActionResult GetGiftAidAmount([FromQuery] GiftAidRequest request) { var validationResult = ValidateOperation(request.Amount); if (validationResult.StatusCode != 200) { return(validationResult); } var response = new GiftAidResponse { DonationAmount = Math.Round(request.Amount, 2), GiftAidAmount = _giftAidCalculator.CalculateGiftAid(request.Amount) }; return(Ok(response)); }
public IActionResult CalculateGiftAid([FromQuery][Required()] decimal amount) { var giftAid = _service.CalculateGiftAidAmount(amount); if (giftAid.IsFailure) { return(BadRequest(giftAid.Error)); } var response = new GiftAidResponse() { DonationAmount = amount, GiftAidAmount = giftAid.Value }; return(Ok(response)); }
public IActionResult Get([FromQuery] decimal?amount) { if (!amount.HasValue) { return(BadRequest()); } if (amount < 2 || amount > 100000) { return(BadRequest("The input must be more the 2 but less that 100000")); } var response = new GiftAidResponse { DonationAmount = amount.Value, GiftAidAmount = _calculator.CalculateGiftAid(amount.Value) }; return(Ok(response)); }