using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using WorkFlowCheck.Web.Services.Interfaces;

namespace WorkFlowCheck.Web.Pages.BaseStock.Locations
{
    [Authorize]
    public class LocationsPageModel : PageModel
    {
        private readonly ILogger<IndexModel> _logger;
        private readonly IBaseStockService _baseStockService;
        public LocationsPageModel(ILogger<IndexModel> logger, IBaseStockService baseStockService)
        {
            _logger = logger;
            _baseStockService = baseStockService;
        }
        public async Task OnGet()
        {
        }
        public async Task<JsonResult> OnGetLoadLocations()
        {
            var results = await _baseStockService.GetAllLocations();
            return new JsonResult(new { data = results });
        }
        public async Task<JsonResult> OnGetDeleteLocation(int id)
        {
            var isSuccess = await _baseStockService.DeleteLocation(id);
            return new JsonResult(new { result = isSuccess });
        }
    }
}
