public void UpdateTdLoad(TdLoad curLoad) { using (var context = new EstimeContext(options, connString)) { EFHelper.CallEF(() => { context.TdLoad.Update(curLoad); context.SaveChanges(); }); } }
public TdLoad AddTdLoad(TdLoad newLoad) { using (var context = new EstimeContext(options, connString)) { EFHelper.CallEF(() => { context.TdLoad.Add(newLoad); context.SaveChanges(); }); } return(newLoad); }
public bool AddTdLoadStaging(int loadId, int refPeriodId, List <TdLoadStaging> newLoadStaging) { bool retVal = false; using (var context = new EstimeContext(connString)) { using (var trans = context.Database.BeginTransaction()) { //Add parameters for the stored proc SqlParameter loadIdParam = new SqlParameter("@LoadId", SqlDbType.Int) { Value = loadId }; SqlParameter refPeriodIdParam = new SqlParameter("@RefPeriodId", SqlDbType.Int) { Value = refPeriodId }; SqlParameter successParam = new SqlParameter("@SuccessCode", SqlDbType.Int) { Direction = ParameterDirection.Output }; SqlParameter errorMessageParam = new SqlParameter("@ErrorExceptionMessage", SqlDbType.NVarChar) { Size = 50000, Direction = ParameterDirection.Output }; SqlParameter[] parameters = new SqlParameter[] { loadIdParam, refPeriodIdParam, successParam, errorMessageParam }; try { context.TdLoadStaging.AddRange(newLoadStaging); context.SaveChanges(); context.Database.ExecuteSqlCommand("ESTIME.usp_ProcessLoadStagingData @LoadId, @RefPeriodId, @SuccessCode OUTPUT, @ErrorExceptionMessage OUTPUT", parameters); retVal = Convert.ToInt32(successParam.Value) == 0 ? true : false; trans.Commit(); } catch (Exception ex) { retVal = false; trans.Rollback(); } } } return(retVal); }