/// <summary>
 /// Deprecated Method for adding a new object to the T_ATTAINS_ASSESS_UNITS EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToT_ATTAINS_ASSESS_UNITS(T_ATTAINS_ASSESS_UNITS t_ATTAINS_ASSESS_UNITS)
 {
     base.AddObject("T_ATTAINS_ASSESS_UNITS", t_ATTAINS_ASSESS_UNITS);
 }
 /// <summary>
 /// Create a new T_ATTAINS_ASSESS_UNITS object.
 /// </summary>
 /// <param name="aTTAINS_ASSESS_UNIT_IDX">Initial value of the ATTAINS_ASSESS_UNIT_IDX property.</param>
 /// <param name="aTTAINS_REPORT_IDX">Initial value of the ATTAINS_REPORT_IDX property.</param>
 /// <param name="aSSESS_UNIT_ID">Initial value of the ASSESS_UNIT_ID property.</param>
 public static T_ATTAINS_ASSESS_UNITS CreateT_ATTAINS_ASSESS_UNITS(global::System.Int32 aTTAINS_ASSESS_UNIT_IDX, global::System.Int32 aTTAINS_REPORT_IDX, global::System.String aSSESS_UNIT_ID)
 {
     T_ATTAINS_ASSESS_UNITS t_ATTAINS_ASSESS_UNITS = new T_ATTAINS_ASSESS_UNITS();
     t_ATTAINS_ASSESS_UNITS.ATTAINS_ASSESS_UNIT_IDX = aTTAINS_ASSESS_UNIT_IDX;
     t_ATTAINS_ASSESS_UNITS.ATTAINS_REPORT_IDX = aTTAINS_REPORT_IDX;
     t_ATTAINS_ASSESS_UNITS.ASSESS_UNIT_ID = aSSESS_UNIT_ID;
     return t_ATTAINS_ASSESS_UNITS;
 }
        public static int InsertOrUpdateATTAINS_ASSESS_UNITS(int? aTTAINS_ASSESS_UNIT_IDX, int? aTTAINS_REPORT_IDX, string aSSESS_UNIT_ID, string aSSESS_UNIT_NAME, 
            string lOCATION_DESC, string aGENCY_CODE, string sTATE_CODE, string aCT_IND, string wATER_TYPE_CODE, decimal? wATER_SIZE, string wATER_UNIT_CODE,
            string uSE_CLASS_CODE, string uSE_CLASS_NAME, String cREATE_USER = "******")
        {
            using (OpenEnvironmentEntities ctx = new OpenEnvironmentEntities())
            {
                Boolean insInd = false;
                try
                {
                    if (aTTAINS_ASSESS_UNIT_IDX == -1) aTTAINS_ASSESS_UNIT_IDX = null;

                    T_ATTAINS_ASSESS_UNITS a = null;

                    if (aTTAINS_ASSESS_UNIT_IDX != null)
                        a = (from c in ctx.T_ATTAINS_ASSESS_UNITS
                             where c.ATTAINS_ASSESS_UNIT_IDX == aTTAINS_ASSESS_UNIT_IDX
                             select c).FirstOrDefault();

                    if (a == null)
                    {
                        a = new T_ATTAINS_ASSESS_UNITS();
                        insInd = true;
                    }

                    if (aTTAINS_REPORT_IDX != null) a.ATTAINS_REPORT_IDX = aTTAINS_REPORT_IDX.ConvertOrDefault<int>();
                    if (aSSESS_UNIT_ID != null) a.ASSESS_UNIT_ID = aSSESS_UNIT_ID;
                    if (aSSESS_UNIT_NAME != null) a.ASSESS_UNIT_NAME = aSSESS_UNIT_NAME;
                    if (lOCATION_DESC != null) a.LOCATION_DESC = lOCATION_DESC;
                    if (aGENCY_CODE != null) a.AGENCY_CODE = aGENCY_CODE;
                    if (sTATE_CODE != null) a.STATE_CODE = sTATE_CODE;
                    if (aCT_IND != null) a.ACT_IND = aCT_IND;
                    if (wATER_TYPE_CODE != null) a.WATER_TYPE_CODE = wATER_TYPE_CODE;
                    if (wATER_SIZE != null) a.WATER_SIZE = wATER_SIZE;
                    if (wATER_UNIT_CODE != null) a.WATER_UNIT_CODE = wATER_UNIT_CODE;
                    if (uSE_CLASS_CODE != null) a.USE_CLASS_CODE = uSE_CLASS_CODE;
                    if (uSE_CLASS_NAME != null) a.USE_CLASS_NAME = uSE_CLASS_NAME;

                    if (insInd) //insert case
                    {
                        a.CREATE_USERID = cREATE_USER.ToUpper();
                        a.CREATE_DT = System.DateTime.Now;
                        ctx.AddToT_ATTAINS_ASSESS_UNITS(a);
                    }
                    else
                    {
                        a.MODIFY_USERID = cREATE_USER.ToUpper();
                        a.MODIFY_DT = System.DateTime.Now;
                    }

                    ctx.SaveChanges();

                    return a.ATTAINS_ASSESS_UNIT_IDX;
                }
                catch (Exception ex)
                {
                    return 0;
                }
            }
        }