public void update(blog_nota nota) { try { c.Entry(nota); c.SaveChanges(); } catch (Exception) { throw; } }
public void delete(blog_nota nota) { try { c.blog_nota.Remove(nota); c.SaveChanges(); } catch (Exception) { throw; } }
public int buscarIdNotaPorFechaYAutor(blog_nota nota) { try { return((from bn in c.blog_nota where bn.f_publicacion == nota.f_publicacion && bn.id_usuario == nota.id_usuario select bn.id_blog_nota).FirstOrDefault()); } catch (Exception) { throw; } }
protected void Page_Load(object sender, EventArgs e) { int id = int.Parse(Request.QueryString["id"]); this.nota = repository.get(id); if (!IsPostBack) { titulo.Text = this.nota.titulo_nota; descripcion.Text = this.nota.descripcion_nota; texto.Text = this.nota.nota; } }
public void add(blog_nota nota) { try { c.blog_nota.Add(nota); c.SaveChanges(); // Nota: EF setea id autoincrementado de la nota luego del SaveChanges() notificacionRepository.notificarNotaAPacientes(nota.id_blog_nota); } catch (Exception) { throw; } }
protected void Page_Load(object sender, EventArgs e) { UsuarioCompleto UsuarioCompleto = (UsuarioCompleto)Session["UsuarioCompleto"]; int id = int.Parse(Request.QueryString["id"]); this.nota = repository.get(id); int Dia = this.nota.f_publicacion.Day; String Mes = this.nota.f_publicacion.ToString("MMMM", CultureInfo.CreateSpecificCulture("es")); int Anio = this.nota.f_publicacion.Year; nota_titulo.InnerHtml = this.nota.titulo_nota; texto.InnerHtml = this.nota.nota; descripcion.InnerHtml = this.nota.descripcion_nota; fechanota.Text = String.Join(" de ", Dia, Mes, Anio); if (this.nota.imagen_nota != null && this.nota.imagen_nota != "") { imagen.ImageUrl = "../../content/img/notas/" + this.nota.imagen_nota; imagen.CssClass = "imgentrada responsive-img"; } else { imagen.ImageUrl = "../../content/img/sin-imagen.jpg"; imagen.CssClass = "imgentrada responsive-img"; } if (UsuarioCompleto != null) { if (UsuarioCompleto.Usuario.id_usuario_tipo == 1) { LiEditar.Visible = false; LiEliminar.Visible = false; } else if (nota.id_usuario == UsuarioCompleto.Usuario.id_usuario) { LiEditar.Visible = true; LiEliminar.Visible = true; } } }
protected void Editar(object sender, EventArgs e) { blog_nota nota = new blog_nota(); nota = this.nota; UsuarioCompleto usuario = (UsuarioCompleto)Session["UsuarioCompleto"]; if (imagen.HasFile) { StringBuilder fileName = new StringBuilder(); fileName.Append(usuario.Usuario.id_usuario + "-"); fileName.Append(DateTime.Now.Year); fileName.Append("." + DateTime.Now.Month); fileName.Append("." + DateTime.Now.Day); fileName.Append("." + DateTime.Now.Hour); fileName.Append("." + DateTime.Now.Minute); fileName.Append("." + DateTime.Now.Second); fileName.Append("." + DateTime.Now.Millisecond); fileName.Append(Path.GetExtension(imagen.PostedFile.FileName)); string serverPath = Server.MapPath("~/Content/img/notas/"); string path = Path.Combine(serverPath, fileName.ToString()); imagen.SaveAs(path); nota.imagen_nota = fileName.ToString(); } nota.nota = texto.Text; nota.titulo_nota = titulo.Text; nota.descripcion_nota = descripcion.Text; try { repository.update(nota); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
protected void Guardar(object sender, EventArgs e) { UsuarioCompleto usuario = (UsuarioCompleto)Session["UsuarioCompleto"]; blog_nota nota = new blog_nota(); /* Guardar imagen */ if (imagen.HasFile) { StringBuilder fileName = new StringBuilder(); fileName.Append(usuario.Usuario.id_usuario + "-"); fileName.Append(DateTime.Now.Year); fileName.Append("." + DateTime.Now.Month); fileName.Append("." + DateTime.Now.Day); fileName.Append("." + DateTime.Now.Hour); fileName.Append("." + DateTime.Now.Minute); fileName.Append("." + DateTime.Now.Second); fileName.Append("." + DateTime.Now.Millisecond); fileName.Append(Path.GetExtension(imagen.PostedFile.FileName)); string serverPath = Server.MapPath("~/Content/img/notas/"); string path = Path.Combine(serverPath, fileName.ToString()); imagen.SaveAs(path); nota.imagen_nota = fileName.ToString(); } nota.nota = texto.Text; nota.titulo_nota = titulo.Text; nota.descripcion_nota = descripcion.Text; nota.id_usuario = usuario.Usuario.id_usuario; nota.f_publicacion = DateTime.Now; blogRepository.add(nota); //TODO mostar mensaje de exito y redirigir hacia atras }