Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using CalcApi.Models;
using Microsoft.AspNetCore.Mvc;
namespace CalcApi.Controllers
{
[Route("api/calc")]
[ApiController]
public class CalcController : ControllerBase
{
[HttpPost("add")]
public IActionResult AddNumbers([FromBody]NumbersModel numbersModel)
{
return Ok(numbersModel.NumberOne + numbersModel.NumberTwo);
}
[HttpPost("subtract")]
public IActionResult SubtractNumbers([FromBody]NumbersModel numbersModel)
{
return Ok(numbersModel.NumberOne - numbersModel.NumberTwo);
}
[HttpPost("multiply")]
public IActionResult MultiplyNumbers([FromBody]NumbersModel numbersModel)
{
return Ok(numbersModel.NumberOne * numbersModel.NumberTwo);
}
[HttpPost("divide")]
public IActionResult DivideNumbers([FromBody]NumbersModel numbersModel)
{
if (numbersModel.NumberTwo == 0)
return BadRequest("Divisor cannot be zero");
return Ok(numbersModel.NumberOne / numbersModel.NumberTwo);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.