Skip to content

Instantly share code, notes, and snippets.

@NimzyMaina
Created June 8, 2020 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NimzyMaina/2951fd59859cf47a6cc9038e0ec10e68 to your computer and use it in GitHub Desktop.
Save NimzyMaina/2951fd59859cf47a6cc9038e0ec10e68 to your computer and use it in GitHub Desktop.
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using TempConvert.Models;
using TempConvert.Interfaces;
using TempConvert.Repositories;
namespace TempConvert.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TempController : ControllerBase
{
private readonly ITempConvertRepository _temp;
public TempController(ITempConvertRepository temp)
{
_temp = temp;
}
[HttpPost("celsius")]
public async Task<IActionResult> Celsius(ConvertRequest model)
{
var res = await _temp.FahrenheitToCelsiusAsync(model.Value);
return Ok(new
{
Success = true,
Temp = $"{model.Value} degrees fahrenheit is == to {res} degrees celsius"
});
}
[HttpPost("fahrenheit")]
public async Task<IActionResult> Fahrenheit(ConvertRequest model)
{
var res = await _temp.CelsiusToFahrenheitAsync(model.Value);
return Ok(new
{
Success = true,
Temp = $"{model.Value} degrees celsius is == to {res} degrees fahrenheit"
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment