public ActionResult Crear(Categoria categoria) { try { var sector_id = 0; if (User.IsInRole("Usuario")) { sector_id = ObjSector.ConsultaSectorEmp(Convert.ToInt32(Session["Empresa"])).IdSector; } else { sector_id = categoria.IdSector; } if (ObjCategoria.AgregaCategoria(sector_id, categoria.Descripcion, categoria.Estado, Session["Identificacion"].ToString())) { ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Categoría", "Crear categoría.", "Se crea correctamente la categoría.", 1); return(RedirectToAction("index")); } else { ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Categoría", "Crear categoría.", "Error al crear la categoría.", 0); ViewBag.Sectores = ListaSector().Where(x => x.Estado == true); return(View(categoria)); } } catch (Exception e) { ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Categoría", "Crear categoría.", "Error al crear la categoría.", 0); ViewBag.Sectores = ListaSector().Where(x => x.Estado == true); ViewBag.Error = "Error: " + e.Message; return(View(categoria)); throw; } }