public CResutlWebMethod SetOrder(string sOrder, int nCategoryID)
        {
            CResutlWebMethod  result = new CResutlWebMethod();
            PTTGSP_DWSContext db     = new PTTGSP_DWSContext();

            result.sStatus = STFunction.process_Success();
            List <TB_Material_Category> listtb_material_category = db.TB_Material_Category.ToList();

            TB_Material_Category tb_material_category = listtb_material_category.FirstOrDefault(w => w.nCategoryID == nCategoryID);

            if (tb_material_category != null)
            {
                tb_material_category.nOrder = sOrder.ToInt();

                int n             = 0;
                var lstItem_OTHER = listtb_material_category.Where(w => w.nCategoryID != nCategoryID && w.IsDel == false).OrderBy(o => o.nOrder).ToList();
                lstItem_OTHER.ForEach(i =>
                {
                    n += 1;
                    if (n == sOrder.ToInt())
                    {
                        n += 1;
                    }
                    i.nOrder = n;
                });

                db.SaveChanges();
            }
            else
            {
                result.sMsg    = "ไม่พบข้อมูลไม่ถูกต้อง";
                result.sStatus = STFunction.process_Warning();
            }
            return(result);
        }
        public IActionResult Savedata(V_Material_Category oV_Material_Category)
        {
            CResutlWebMethod result = new CResutlWebMethod();

            PTTGSP_DWSContext db = new PTTGSP_DWSContext();

            result.sStatus = STFunction.process_Success();

            try
            {
                if (!db.V_Material_Category.Any(w => w.sCategoryName.ToLower().Trim() == oV_Material_Category.sCategoryName.ToLower().Trim() && w.nCategoryID != oV_Material_Category.nCategoryID))
                {
                    if (!db.V_Material_Category.Any(w => w.sCategoryCode.ToLower().Trim() == oV_Material_Category.sCategoryCode.ToLower().Trim() && w.nCategoryID != oV_Material_Category.nCategoryID))
                    {
                        TB_Material_Category otb_material_category = db.TB_Material_Category.Where(w => w.nCategoryID == oV_Material_Category.nCategoryID).FirstOrDefault();

                        if (otb_material_category == null)
                        {
                            otb_material_category         = new TB_Material_Category();
                            otb_material_category.dCreate = DateTime.Now;
                            db.TB_Material_Category.Add(otb_material_category);
                        }
                        otb_material_category.nGroupID      = oV_Material_Category.nGroupID.ToInt();
                        otb_material_category.sCategoryCode = oV_Material_Category.sCategoryCode;
                        otb_material_category.sName         = oV_Material_Category.sCategoryName;
                        otb_material_category.sDetail       = oV_Material_Category.sDetail;
                        otb_material_category.nOrder        = oV_Material_Category.nOrder;
                        otb_material_category.IsActive      = oV_Material_Category.IsActive;

                        otb_material_category.dUpdate = DateTime.Now;

                        db.SaveChanges();
                    }
                    else
                    {
                        result.sMsg    = "รหัสประเภทวัสดุนี้มีในระบบแล้ว";
                        result.sStatus = STFunction.process_Warning();
                    }
                }
                else
                {
                    result.sMsg    = "ชื่อประเภทวัสดุนี้มีในระบบแล้ว";
                    result.sStatus = STFunction.process_Warning();
                }
            }
            catch (Exception e)
            {
                result.sStatus = STFunction.process_Failed();
                result.sMsg    = e.ToString();
            }
            return(Ok(result));
        }