public IActionResult EditMaterialUnit(int nID)
        {
            var result = new cListMaterialUnit();
            cTB_Material_Unit EditMaterialUnit = new cTB_Material_Unit();

            try
            {
                PTTGSP_DWSContext db = new PTTGSP_DWSContext();

                var lstMaterial_unit = db.TB_Material_Unit.Where(w => !w.IsDel && w.nUnitID == nID).ToList();
                EditMaterialUnit = (from a in lstMaterial_unit.Where(w => !w.IsDel)
                                    select new cTB_Material_Unit
                {
                    nUnitID = a.nUnitID,
                    sName = a.sName,
                    sDetail = a.sDetail,
                    bStatus = a.IsActive,
                    sStatus_Name = a.IsActive ? "ใช้งาน" : "ไม่ใช้งาน",
                    dUpdate = a.dUpdate,
                    sUpdate = a.dUpdate.ToString("dd/MM/yyyy", culture),
                }).FirstOrDefault();
            }
            catch (Exception e)
            {
                result.sStatus = SysFunc.process_Error;
                result.sMsg    = e.Message;
            }

            return(Ok(EditMaterialUnit));
        }
        public cListMaterialUnit GetListMaterialUnit(string txtSearch, string sIsActive)
        {
            var result = new cListMaterialUnit();

            try
            {
                PTTGSP_DWSContext db = new PTTGSP_DWSContext();

                var lstMaterial_unit = db.TB_Material_Unit.Where(w => !w.IsDel).ToList();
                var lstMaterial      = db.TB_Materials.Where(w => !w.IsDel).ToList();
                var Meterial_Unit    = lstMaterial_unit.Select(s => new lstMaterial_unit
                {
                    nUnitID      = s.nUnitID,
                    sName        = s.sName,
                    sDetail      = s.sDetail,
                    bStatus      = s.IsActive,
                    sStatus_Name = s.IsActive ? "ใช้งาน" : "ไม่ใช้งาน",
                    dUpdate      = s.dUpdate,
                    sUpdate      = s.dUpdate.ToString("dd/MM/yyyy", culture),
                    IsUse        = lstMaterial.Where(w => w.nUnitID == s.nUnitID).FirstOrDefault() == null ? false : true
                }).ToList();

                if (!string.IsNullOrEmpty(txtSearch) && txtSearch != "none")
                {
                    Meterial_Unit = Meterial_Unit.Where(item => item.sName.Trim().ToLower().Contains(txtSearch.Trim().ToLower())).ToList();
                }
                if (!string.IsNullOrEmpty(sIsActive))
                {
                    var isActive = sIsActive == "1";
                    Meterial_Unit = Meterial_Unit.Where(a => a.bStatus == isActive).ToList();
                }

                result.lstMaterial_unit = Meterial_Unit.ToList();
            }
            catch (Exception e)
            {
                result.sStatus = SysFunc.process_Error;
                result.sMsg    = e.Message;
            }
            return(result);
        }