Created
February 27, 2021 05:29
-
-
Save bbachi/2ca1475fb28be43efe7c4d3fca81b35c to your computer and use it in GitHub Desktop.
Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.Extensions.Logging; | |
namespace angular_dotnet_example.Controllers | |
{ | |
[ApiController] | |
public class UsersController : ControllerBase | |
{ | |
private readonly ILogger<UsersController> _logger; | |
static readonly Models.IUserRepository repository = new Models.UserRepository(); | |
public UsersController(ILogger<UsersController> logger) | |
{ | |
_logger = logger; | |
} | |
[HttpGet] | |
[Route("api/users")] | |
public IEnumerable<Models.UserModel> GetAllUsers() | |
{ | |
return repository.GetAll(); | |
} | |
[HttpPost] | |
[Route("api/user")] | |
[Consumes("application/json")] | |
public Models.UserModel PostUser(Models.UserModel item) | |
{ | |
return repository.Add(item); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment