using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using System;
using WK_KLI_LAPS_Service.App_Data;
using WK_KLI_LAPS_Service.Models.Master;

namespace WK_KLI_LAPS_Service.Controllers.Master.MipTopic3
{
    [EnableCors("CorsPolicy")]
    [Authorize]
    [ApiController]
    [Route("api/[controller]")]
    public class MipTopic3ApiController : ControllerBase
    {
        CommonRepository oCommonRepository = new CommonRepository();

        private IMipTopic3Service _MipTopic3services;
        public MipTopic3ApiController(IMipTopic3Service MipTopic3Services)
        {
            _MipTopic3services = MipTopic3Services;

        }


        [Authorize]
        [HttpGet]
        //Code to retrieve all data
        public IActionResult GetAll()
        {
            var _list = _MipTopic3services.GetAll();
            return Ok(_list);
        }

        [Authorize]
        [HttpGet("GetActiveMipTopic3")]
        //Code to retrieve active data
        public IActionResult GetActiveMipTopic3()
        {
            var _list = _MipTopic3services.GetActiveMipTopic3();
            return Ok(_list);
        }
        //Code to add new record
        [Authorize]
        [HttpPost("Add")]
        public IActionResult Add([FromBody] miptopic3Model omiptopic3Model)
        {

            int retval = 0;
            try
            {
                retval = _MipTopic3services.Add(omiptopic3Model);
                return Ok(retval);
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }

        }
        //Code to update specific record
        [Authorize]
        [HttpPost("Update")]
        public IActionResult Update([FromBody] miptopic3Model omiptopic3Model)
        {
            int retval = 0;
            try
            {
                retval = _MipTopic3services.Edit(omiptopic3Model);
                return Ok(retval);
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }

        }


        //Code to activate or deactivate specific record
        [Authorize]
        [HttpPost("activeordeactive")]
        public IActionResult Delete([FromBody] miptopic3Model omiptopic3Model)
        {
            int retval = 0;
            try
            {
                retval = _MipTopic3services.Delete(omiptopic3Model);
                return Ok(retval);
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }
        }
    }
}