public ActionResult Create(TBL_REPORTE reporte) { try { //TransactionOptions to = new TransactionOptions(); decimal reporte_id = reporte.ID; context.Connection.Open(); using (var tr = context.Connection.BeginTransaction()) { if (!ModelState.IsValid) { FlashError("Revise los campos"); return(View("New", this.getNewReporte(reporte))); } if (reporte.ID > 0) { var items = context.TBL_REPORTE_PARAM.Where(c => c.REPORTE_ID == reporte.ID); foreach (TBL_REPORTE_PARAM param in items) { context.DeleteObject(param); } var updatedItem = context.TBL_REPORTE.Where(c => c.ID == reporte.ID).SingleOrDefault(); updatedItem.SimpleCopyFrom(reporte, new string[] { "ID", "NOMBRE", "CONSULTA_SQL", "DESCRIPCION", "CATEGORIA_ID" }); reporte = updatedItem; } else { context.TBL_REPORTE.AddObject(reporte); } context.SaveChanges(); if (reporte_id < 1) { tr.Commit(); ////HACK- Cambiar cuando el connector de Oracle funcione bien reporte = context.TBL_REPORTE.OrderByDescending(c => c.ID).First(); ////HACK---------------------------------------------------------------------------- reporte_id = reporte.ID; this.AddParams(reporte_id); context.SaveChanges(); } else { this.AddParams(reporte_id); context.SaveChanges(System.Data.Objects.SaveOptions.None); tr.Commit(); } } } catch (Exception ex) { FlashErrorIntraSession("La acción no se ejecutó correctamente. Error:" + ex.Message); return(RedirectToAction("New", "Reporte", reporte)); } FlashOKIntraSession("El reporte fue guardado correctamente."); return(RedirectToAction("List", "Reporte")); }
public SelectList CreateCategoriesComboBox(TBL_REPORTE rep) { List <object> newList = new List <object>(); foreach (var cat in context.TBL_REPORTECATEGORIA) { newList.Add(new { id = cat.ID, nombre = cat.NOMBRE }); } return(new SelectList(newList, "id", "nombre", Convert.ToInt32(rep.CATEGORIA_ID))); }
private TBL_REPORTE getNewReporte(TBL_REPORTE reporte) { TBL_REPORTE _reporte = new TBL_REPORTE(); if (reporte != null) { _reporte = reporte; } _reporte.TBL_REPORTE_PARAM = new System.Data.Objects.DataClasses.EntityCollection <TBL_REPORTE_PARAM>(); TBL_REPORTE_PARAM param = new TBL_REPORTE_PARAM(); param.INDICE = 1; param.NOMBRE = "nombre"; param.TIPO_DATO = Convert.ToInt32(ReporteParamDataType.ENTERO); _reporte.TBL_REPORTE_PARAM.Add(param); return(_reporte); }