public ActionResult Excluir(int id) { using (var session = NHibernateHelper.OpenSession()) { using (var transaction = session.BeginTransaction()) { IList <Categoria> CatList = session.Query <Categoria>().ToList(); var listaCategorias = (from u in CatList.AsEnumerable() select new SelectListItem { Text = u.descricao, Value = u.categoriaId.ToString(), }).AsEnumerable(); ViewBag.ListaDrop = listaCategorias; var subCategorias = session.Get <SubCategoria>(id); SubCategoriaModel subCategoriasDetalhes = new SubCategoriaModel(); subCategoriasDetalhes.subCategoriaId = subCategorias.subCategoriaId; subCategoriasDetalhes.descricao = subCategorias.descricao; subCategoriasDetalhes.slug = subCategorias.slug; subCategoriasDetalhes.categoria = new CategoriaModel { categoriaId = subCategorias.categoria.categoriaId, descricao = subCategorias.categoria.descricao, slug = subCategorias.categoria.slug }; return(View(subCategoriasDetalhes)); } } }
public void Grabar(SubCategoriaModel datos) { using (var c = new Contexto()) { c.SubCategoria.Add(datos); c.SaveChanges(); } }
public ActionResult Edit([Bind(Include = "Id,Nombre,CategoriaId, FijaMensualmente, Tipo, Monto")] SubCategoriaModel subCategoriaModel) { if (ModelState.IsValid) { db.Actualizar(subCategoriaModel, CategoriaId); return(RedirectToAction("Index")); } ViewBag.CategoriaId = new SelectList(dc.Listar(), "Id", "Nombre", subCategoriaModel.CategoriaId); return(View(subCategoriaModel)); }
// GET: SubCategoria/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SubCategoriaModel subCategoriaModel = db.Devolver(id); if (subCategoriaModel == null) { return(HttpNotFound()); } return(View(subCategoriaModel)); }
// GET: SubCategoria/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SubCategoriaModel subCategoriaModel = db.Devolver(id); if (subCategoriaModel == null) { return(HttpNotFound()); } ViewBag.CategoriaId = new SelectList(dc.Listar(), "Id", "Nombre", subCategoriaModel.CategoriaId); CategoriaId = subCategoriaModel.CategoriaId; return(View(subCategoriaModel)); }
public void Actualizar(SubCategoriaModel datos, int idCategoriaViejo) { using (var c = new Contexto()) { if (datos.CategoriaId != idCategoriaViejo) { //Modifico los movimientos idCategoria List <MovimientosModel> mov = c.Movimiento.Where(f => f.SubCategoriaId == datos.Id).ToList(); foreach (MovimientosModel m in mov) { m.CategoriaId = datos.CategoriaId; } } c.Entry(datos).State = EntityState.Modified; c.SaveChanges(); } }
public ActionResult Detalhes(int id) { using (var session = NHibernateHelper.OpenSession()) { using (var transaction = session.BeginTransaction()) { var subCategorias = session.Get <SubCategoria>(id); SubCategoriaModel subCategoriasDetalhes = new SubCategoriaModel(); subCategoriasDetalhes.subCategoriaId = subCategorias.subCategoriaId; subCategoriasDetalhes.descricao = subCategorias.descricao; subCategoriasDetalhes.slug = subCategorias.slug; subCategoriasDetalhes.categoria = new CategoriaModel { categoriaId = subCategorias.categoria.categoriaId, descricao = subCategorias.categoria.descricao, slug = subCategorias.categoria.slug }; return(View(subCategoriasDetalhes)); } } }
public IActionResult RegistrarSubCategoria(SubCategoriaModel productoModel) { string connectionString = Configuration["ConnectionStrings:DB_Connection"]; CategoriaModel productoTemp = new CategoriaModel(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sqlQuery = $"exec insertSubCategoria @idCategoria='{productoModel.Id}', @nombre='{productoModel.Nombre}', @id='{productoModel.idSubCategoria}'"; using (SqlCommand command = new SqlCommand(sqlQuery, connection)) { command.CommandType = CommandType.Text; connection.Open(); command.ExecuteReader(); connection.Close(); } } // ModelState.IsValid return(View()); } // Registrar