public ResponseModel Guardar(tb_Periodo periodo) { var rm = new ResponseModel(); try { using (var ctx = new SeguroContext()) { if (periodo.IdPeriodo > 0) { ctx.Entry(periodo).State = EntityState.Modified; } else { ctx.Entry(periodo).State = EntityState.Added; } rm.SetResponse(true); ctx.SaveChanges(); } } catch (Exception e) { ELog.save(this, e); //throw; } return(rm); }
public tb_Periodo ObtenerPeriodo(int idPeriodo) { var periodo = new tb_Periodo(); try { using (var ctx = new SeguroContext()) { //formas de incluir una relacion entre objetos /* periodo = ctx.tb_Periodo * .Include(x => x.tb_Estado) * .Where(x => x.IdPeriodo==idPeriodo ) * .SingleOrDefault() ;*/ periodo = ctx.tb_Periodo .Include("tb_Estado") .Where(x => x.IdPeriodo == idPeriodo) .SingleOrDefault(); } } catch (Exception e) { ELog.save(this, e); //throw; } return(periodo); }
/* public ActionResult Guardar(tb_Periodo model) * { * if (ModelState.IsValid ) * { * periodo.Guardar(model); * return Redirect("~/Home"); * } * else * { * return View("~/Views/Home/Crud.cshtml", model); * } * }*/ public JsonResult Guardar(tb_Periodo model) { var rm = new ResponseModel(); if (ModelState.IsValid) { rm = periodo.Guardar(model); if (rm.response) { rm.function = "MensajeGrabacion()"; rm.href = Url.Content("~/Home"); } } return(Json(rm)); }
public int ObtenerPeriodo(string anio, string mes) { var periodo = new tb_Periodo(); try { using (var ctx = new SeguroContext()) { periodo = ctx.tb_Periodo .Where(x => x.Anio.StartsWith(anio)) .Where(x => x.Mes.StartsWith(mes)) .SingleOrDefault(); } } catch (Exception e) { ELog.save(this, e); //throw; } return(periodo.IdPeriodo); }