Ejemplo n.º 1
0
        public static int InsertOrUpdateATTAINS_ASSESS(int? aTTAINS_ASSESS_IDX, string rEPORTING_CYCLE, string rEPORT_STATUS, int aTTAINS_ASSESS_UNIT_IDX,
            string aGENCY_CODE, string cYCLE_LAST_ASSESSED, string cYCLE_LAST_MONITORED, string tROPHIC_STATUS_CODE, String cREATE_USER = "******")
        {
            using (OpenEnvironmentEntities ctx = new OpenEnvironmentEntities())
            {
                Boolean insInd = false;
                try
                {
                    if (aTTAINS_ASSESS_IDX == -1) aTTAINS_ASSESS_IDX = null;

                    T_ATTAINS_ASSESS a = null;

                    if (aTTAINS_ASSESS_IDX != null)
                        a = (from c in ctx.T_ATTAINS_ASSESS
                             where c.ATTAINS_ASSESS_IDX == aTTAINS_ASSESS_IDX
                             select c).FirstOrDefault();

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

                    if (rEPORTING_CYCLE != null) a.REPORTING_CYCLE = rEPORTING_CYCLE;
                    if (rEPORT_STATUS != null) a.REPORT_STATUS = rEPORT_STATUS;
                    a.ATTAINS_ASSESS_UNIT_IDX = aTTAINS_ASSESS_UNIT_IDX;
                    if (aGENCY_CODE != null) a.AGENCY_CODE = aGENCY_CODE;
                    if (cYCLE_LAST_ASSESSED != null) a.CYCLE_LAST_ASSESSED = cYCLE_LAST_ASSESSED;
                    if (cYCLE_LAST_MONITORED != null) a.CYCLE_LAST_MONITORED = cYCLE_LAST_MONITORED;
                    if (tROPHIC_STATUS_CODE != null) a.TROPHIC_STATUS_CODE = tROPHIC_STATUS_CODE;

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

                    ctx.SaveChanges();

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