protected void btneventgrid_Click(object sender, EventArgs e) { try { int id_ayuda = Convert.ToInt32(hdfid_ayuda.Value == "" ? "0" : hdfid_ayuda.Value); if (id_ayuda > 0) { ayudas ayuda = GetAyuda(id_ayuda); if (ayuda != null) { txttitulo.Text = ayuda.titulo; txtdescripcion.Text = ayuda.descripcion; txtcodigohtml.Text = ayuda.codigo_html; ddlpadre.SelectedValue = ayuda.id_ayuda_padre == null ? "0" : ayuda.id_ayuda_padre.ToString(); ddltipoarchivo.SelectedValue = ayuda.video ? "1" : "0"; txticono.Text = ayuda.icono; ModalShow("#ModalAyudas"); } } } catch (Exception ex) { Toast.Error("Error al cargar ayudas : " + ex.Message, this); } }
/// <summary> /// Edita una ayuda /// </summary> /// <param name="entidad"></param> /// <returns></returns> public string Editar(ayudas entidad) { try { Model context = new Model(); ayudas ayuda = context.ayudas .First(i => i.id_ayuda == entidad.id_ayuda); ayuda.titulo = entidad.titulo; ayuda.id_ayuda_padre = entidad.id_ayuda_padre; ayuda.icono = entidad.icono; ayuda.descripcion = entidad.descripcion; ayuda.codigo_html = entidad.codigo_html; ayuda.src = entidad.src; ayuda.video = entidad.video; ayuda.fecha_edicion = DateTime.Now; ayuda.usuario_edicion = entidad.usuario_edicion; context.SaveChanges(); return(""); } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); return(fullErrorMessage.ToString()); } }
private string Agregar(ayudas ayuda) { AyudaCOM ayudas = new AyudaCOM(); string vmensaje = ayudas.Agregar(ayuda); if (vmensaje == "") { return(""); } else { return(vmensaje); } }
private ayudas GetAyuda(int id_ayuda) { ayudas dt = new ayudas(); try { AyudaCOM ayudas = new AyudaCOM(); dt = ayudas.Ayuda(id_ayuda); } catch (Exception) { dt = null; } return(dt); }
/// <summary> /// Devuelve una instancia de Ayuda /// </summary> /// <param name="id_ayuda"></param> /// <returns></returns> public ayudas Ayuda(int id_ayuda) { try { Model context = new Model(); ayudas ayuda = context.ayudas .First(i => i.id_ayuda == id_ayuda); return(ayuda); } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); return(null); } }
protected void rtrvProyectWorks_NodeClick(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e) { int id = Convert.ToInt32(e.Node.Value); RadTreeNode node1 = rtrvProyectWorks.FindNodeByValue(id.ToString()) as RadTreeNode; if (node1 != null) { int nodes_children = node1.Nodes.Count; if (nodes_children > 0) { node1.Expanded = node1.Expanded == true ? false : true; } ayudas ayuda = GetAyuda(id); if (ayuda != null && ayuda.id_ayuda_padre != null) { lbldesc.Text = ayuda.descripcion == "" ? "No hay descripción disponible." : ayuda.descripcion; lbltituloayuda.Text = ayuda.titulo; string codigo = ""; image.Visible = false; PlaceHolder1.Visible = false; if (ayuda.video) { string url = HttpContext.Current.Request.Url.AbsoluteUri; url = url.Replace("Pages/Common/ayuda.aspx", ""); codigo = "<div align='center' style='max-height:400px' class='embed-responsive embed-responsive-16by9'>" + "<video class='embed-responsive-item' controls>" + " <source src='" + url + ayuda.src + "' type='video/mp4'>" + "</video>" + " </div>"; PlaceHolder1.Visible = true; PlaceHolder1.Controls.Add(new Literal { Text = codigo }); } else { image.Visible = true; image.ImageUrl = ayuda.src; } ModalShow("#ModalAyudas"); } } }
/// <summary> /// Elimina una ayuda /// </summary> /// <param name="entidad"></param> /// <returns></returns> public string Eliminar(ayudas entidad) { try { Model context = new Model(); ayudas ayuda = context.ayudas .First(i => i.id_ayuda == entidad.id_ayuda); ayuda.activo = false; ayuda.fecha_edicion = DateTime.Now; ayuda.usuario_edicion = entidad.usuario_edicion; context.SaveChanges(); return(""); } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); return(fullErrorMessage.ToString()); } }
/// <summary> /// Agrega un nuevo apartado de ayuda /// </summary> /// <param name="entidad"></param> /// <returns></returns> public string Agregar(ayudas entidad) { try { string mess = ""; if (Exist(entidad.titulo)) { mess = "Ya existe un apartado de ayuda con el nombre " + entidad.titulo; } else { ayudas ayuda = new ayudas { titulo = entidad.titulo, id_ayuda_padre = entidad.id_ayuda_padre, icono = entidad.icono, descripcion = entidad.descripcion, codigo_html = entidad.codigo_html, src = entidad.src, video = entidad.video, activo = true, usuario_creacion = entidad.usuario_creacion.ToUpper(), fecha_creacion = DateTime.Now }; Model context = new Model(); context.ayudas.Add(ayuda); context.SaveChanges(); } return(mess); } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); return(fullErrorMessage.ToString()); } }
protected void btneliminarpermiso_Click(object sender, EventArgs e) { try { int id_ayuda = Convert.ToInt32(hdfid_ayuda.Value == "" ? "0" : hdfid_ayuda.Value); ayudas ayuda = new ayudas(); ayuda.id_ayuda = id_ayuda; ayuda.usuario_edicion = Session["usuario"] as string; string vmensaje = Eliminar(ayuda); if (vmensaje == "") { CargarCatalogo(); Toast.Success("Ayuda eliminada correctamente.", "Mensaje del sistema", this); } else { Toast.Error("Error al eliminar ayudas: " + vmensaje, this); } } catch (Exception ex) { Toast.Error("Error al eliminar ayuda : " + ex.Message, this); } }
protected void lnkguardar_Click(object sender, EventArgs e) { try { string vmensaje = string.Empty; int id_ayuda = Convert.ToInt32(hdfid_ayuda.Value == "" ? "0" : hdfid_ayuda.Value); ayudas ayuda = new ayudas(); ayuda.titulo = txttitulo.Text; ayuda.descripcion = txtdescripcion.Text; ayuda.codigo_html = txtcodigohtml.Text; ayuda.id_ayuda_padre = null; if (ddlpadre.SelectedValue != "0") { ayuda.id_ayuda_padre = Convert.ToInt32(ddlpadre.SelectedValue); } if (id_ayuda > 0) { ayuda.id_ayuda = id_ayuda; } bool video = ddltipoarchivo.SelectedValue == "1"; DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("~/")); string src = fuparchivo.HasFile ? "img/helps/" + Guid.NewGuid().ToString() + Path.GetExtension(fuparchivo.FileName): ""; ayuda.src = src; ayuda.video = video; ayuda.icono = txticono.Text; ayuda.usuario_creacion = Session["usuario"] as string; ayuda.usuario_edicion = Session["usuario"] as string; string extension = Path.GetExtension(fuparchivo.FileName); if (ayuda.titulo == "") { ModalShow("#ModalAyudas"); Toast.Error("Error al procesar ayudas : Ingrese un titulo", this); } else if (!fuparchivo.HasFile && ayuda.descripcion == "") { ModalShow("#ModalAyudas"); Toast.Error("Debe incluir un archivo.", this); } else if (fuparchivo.HasFile && extension != ".mp4" && extension != ".jpg" && extension != ".png" && extension != ".jpeg") { ModalShow("#ModalAyudas"); Toast.Error("Formato de archivo no permitido", this); } else { vmensaje = id_ayuda > 0 ? Editar(ayuda) : Agregar(ayuda); if (vmensaje == "") { if (src != "") { funciones.UploadFile(fuparchivo, dirInfo + src.Trim(), this.Page); } txttitulo.Text = ""; txtdescripcion.Text = ""; txtcodigohtml.Text = ""; txticono.Text = ""; hdfid_ayuda.Value = ""; ddlpadre.SelectedValue = "0"; CargarCatalogo(); Toast.Success("Ayuda agregada correctamente.", "Mensaje del sistema", this); } else { ModalShow("#ModalAyudas"); Toast.Error("Error al procesar ayudas : " + vmensaje, this); } } } catch (Exception ex) { ModalShow("#ModalAyudas"); Toast.Error("Error al procesar ayudas : " + ex.Message, this); } }