/** * <author> * Ariel Cornejo * </author> * <summary> * Este metodo se encarga de realizar una consulta a la base de datos para comprobar si el usuario * esta registrado * </summary> * <param name="usuario"> El string con el id del usuario</param> * <returns> * valor booleano, true si existe o false en caso contrario * </returns> */ private Boolean ValidarUsuario(String usuario) { String consultaExistaUsuario = "SELECT usuario.rut as rut" + " FROM usuario" + " WHERE usuario.rut = '" + usuario + "';"; MySqlDataReader readerUsuario = this.conexion.RealizarConsulta(consultaExistaUsuario); if (readerUsuario == null) { conexion.CerrarConexion(); return(false); } conexion.CerrarConexion(); return(true); }
public ActionResult SubirDiagrama(HttpPostedFileBase file, string nombre, string id, int diagramaValue, int diagramaValueURL, string url, int opValue, string nombreURL) { Debug.Write(opValue + " valor de la opcion "); Debug.Write(diagramaValue + " valor del tipo de diagrama"); int idProyecto = Int32.Parse(id); try { if (url.Length > 0 && opValue == 3) { string tipoDeDiagramaURL = tipoDiagrama(diagramaValueURL); System.Net.WebClient webClient = new WebClient(); string path = Path.Combine(Server.MapPath("~/UploadedFiles"), id + nombreURL + Path.GetExtension(url)).Replace(@"\", @"/"); Debug.Write(" " + path.Replace(@"\", @"/") + " "); if (nombreURL.Length == 0) { TempData["alerta"] = new Alerta("Debe ingresar un nombre", TipoAlerta.ERROR); ViewBag.Message = "Debe ingresar un nombre."; return(RedirectToAction("SubirDiagrama", "Diagrama", new { id = idProyecto })); } if (this.ValidarExtencionURL(url) == false) { TempData["alerta"] = new Alerta("Formato no soportado. Seleccione un archivo de imagen (.jpg, .jpeg, .png, .bmp o .gif)", TipoAlerta.ERROR); ViewBag.Messagw = "Formato no soportado. Seleccione un archivo de imagen (.jpg, .jpeg, .png, .bmp o .gif)"; return(RedirectToAction("SubirDiagrama", "Diagrama", new { id = idProyecto })); } if (this.ValidarURLNoRepetida2("/UploadedFiles/" + id + nombreURL + Path.GetExtension(path)) == false) { TempData["alerta"] = new Alerta("Ya existe un archivo con este nombre", TipoAlerta.ERROR); ViewBag.Message = "Ya existe un archivo con este nombre."; return(RedirectToAction("SubirDiagrama", "Diagrama", new { id = idProyecto })); } if (this.ValidarLargoNombre(nombreURL) == false) { TempData["alerta"] = new Alerta("El nombre debe tener no más de 45 caracteres", TipoAlerta.ERROR); ViewBag.Message = "El nombre debe tener no más de 45 caracteres"; return(RedirectToAction("SubirDiagrama", "Diagrama", new { id = idProyecto })); } if (this.ValidarNombreNoRepetido(nombreURL) == false) { TempData["alerta"] = new Alerta("Ya existe un diagrama con este nombre", TipoAlerta.ERROR); ViewBag.Message = "Ya existe un diagrama con este nombre."; return(RedirectToAction("SubirDiagrama", "Diagrama", new { id = idProyecto })); } webClient.DownloadFile(@url, @path); //this.agregar(nombreURL, id, "../../UploadedFiles/" +id + nombreURL + Path.GetExtension(path), tipoDeDiagramaURL); this.agregar(nombreURL, id, "/UploadedFiles/" + id + nombreURL + Path.GetExtension(path), tipoDeDiagramaURL); TempData["alerta"] = new Alerta("Diagrama subido con éxito!!", TipoAlerta.SUCCESS); ViewBag.Message = "Diagrama subido con éxito!!"; Conector.CerrarConexion(); return(RedirectToAction("ListarDiagramas", "Proyecto", new { id = idProyecto })); } string tipoDeDiagrama = tipoDiagrama(diagramaValue); string _FileName = id + Path.GetFileName(file.FileName); string _path = Path.Combine(Server.MapPath("~/UploadedFiles"), _FileName).Replace(@"\", @"/"); Debug.Write(" " + _path.Replace(@"\", @"/") + " "); if (nombre.Length == 0) { nombre = "null"; } if (this.ValidarExtencion(file) == false) { TempData["alerta"] = new Alerta("Tipo de archivo no soportado. Seleccione un archivo de imagen (.jpg, .jpeg, .png, .bmp o .gif)", TipoAlerta.ERROR); ViewBag.Messagw = "Tipo de archivo no soportado. Seleccione un archivo de imagen (.jpg, .jpeg, .png, .bmp o .gif)"; return(RedirectToAction("SubirDiagrama", "Diagrama", new { id = idProyecto })); } if (file.ContentLength <= 0) { ViewBag.Message = "Falla en la subida del Diagrama!!"; TempData["alerta"] = new Alerta("Falla en la subida del Diagrama!!", TipoAlerta.ERROR); return(RedirectToAction("SubirDiagrama", "Diagrama", new { id = idProyecto })); } if (this.ValidarURLNoRepetida(file, id) == false) { TempData["alerta"] = new Alerta("Ya existe un archivo con este nombre", TipoAlerta.ERROR); ViewBag.Message = "Ya existe un archivo con este nombre."; return(RedirectToAction("SubirDiagrama", "Diagrama", new { id = idProyecto })); } if (this.ValidarLargoNombre(nombre) == false) { TempData["alerta"] = new Alerta("El nombre debe tener no más de 45 caracteres", TipoAlerta.ERROR); ViewBag.Message = "El nombre debe tener no más de 45 caracteres"; return(RedirectToAction("SubirDiagrama", "Diagrama", new { id = idProyecto })); } if (this.ValidarNombreNoRepetido(nombre) == false) { TempData["alerta"] = new Alerta("Ya existe un diagrama con este nombre", TipoAlerta.ERROR); ViewBag.Message = "Ya existe un diagrama con este nombre."; return(RedirectToAction("SubirDiagrama", "Diagrama", new { id = idProyecto })); } //this.agregar(nombre, id, "../../UploadedFiles/" + _FileName, tipoDeDiagrama); this.agregar(nombre, id, "/UploadedFiles/" + _FileName, tipoDeDiagrama); file.SaveAs(_path); TempData["alerta"] = new Alerta("Diagrama subido con éxito!!", TipoAlerta.SUCCESS); ViewBag.Message = "Diagrama subido con éxito!!"; Conector.CerrarConexion(); return(RedirectToAction("ListarDiagramas", "Proyecto", new { id = idProyecto })); } catch { ViewBag.Message = "Error al subir el diagrama."; TempData["alerta"] = new Alerta("Error al subir el diagrama.", TipoAlerta.ERROR); return(RedirectToAction("SubirDiagrama", "Diagrama", new { id = idProyecto })); } }