Ejemplo n.º 1
0
        //******************REF COUNTY ****************************************
        public static int InsertOrUpdateT_WQX_REF_COUNTY(global::System.String sTATE_CODE, global::System.String cOUNTY_CODE, global::System.String cOUNTY_NAME, global::System.Boolean? UsedInd)
        {
            using (OpenEnvironmentEntities ctx = new OpenEnvironmentEntities())
            {
                try
                {
                    Boolean insInd = true;
                    T_WQX_REF_COUNTY a = new T_WQX_REF_COUNTY();

                    if (ctx.T_WQX_REF_COUNTY.Any(o => o.STATE_CODE == sTATE_CODE && o.COUNTY_CODE == cOUNTY_CODE))
                    {
                        //update case
                        a = (from c in ctx.T_WQX_REF_COUNTY
                             where c.STATE_CODE == sTATE_CODE
                             && c.COUNTY_CODE == cOUNTY_CODE
                             select c).FirstOrDefault();
                        insInd = false;
                    }

                    a.STATE_CODE = sTATE_CODE;
                    a.COUNTY_CODE = cOUNTY_CODE;
                    a.COUNTY_NAME = cOUNTY_NAME;

                    if (UsedInd != null) a.USED_IND = UsedInd;

                    a.UPDATE_DT = System.DateTime.Now;
                    a.ACT_IND = true;

                    if (insInd) //insert case
                    {
                        if (UsedInd == null) a.USED_IND = true;
                        ctx.AddToT_WQX_REF_COUNTY(a);
                    }
                    ctx.SaveChanges();
                    return 1;
                }
                catch (Exception ex)
                {
                    return 0;
                }
            }
        }