using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Transactions; using Microsoft.AspNetCore.Mvc; using ProRestaurant.Models.Accounts; using ProRestaurant.Repository.Accounts; namespace ProRestaurant.Controllers.Accounts { [Route("api/[controller]")] [ApiController] public class UserController : ControllerBase { private readonly IUserRepository repo; public UserController(IUserRepository Repo) { repo = Repo; } [HttpGet("GetCustomers")] public IActionResult GetCustomers() { return new OkObjectResult(repo.Get(u => u.SystemRole == Classes.SystemRole.Customer)); } [HttpGet("{id}")] public IActionResult Get(int id) { return new OkObjectResult(repo.GetUser(id)); } [HttpGet("GetUserAddress/{id}")] public IActionResult GetUserAddress(int id) { return new OkObjectResult(repo.GetUserAddress(id)); } [HttpPut] public IActionResult Put([FromBody] User user) { if (user != null) { using (var scope = new TransactionScope()) { repo.Update(user); scope.Complete(); return new OkResult(); } } return new NoContentResult(); } } }