public async Task <IActionResult> Editar(int id, [Bind("EquipoID, EstadoCivilID, InstruccionID, ProfesionID, ProvinciaID, ParroquiaID, Cedula, Nombre, Apellido, FechaNacimiento, Carnet, FechaAfiliacion, NombreArchivo")] Jugadores jugadores) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { string path = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\images\TempFotos"}"; Jugadores entidad = _context.Jugadores.Find(id); entidad.EquipoID = jugadores.EquipoID == 0 ? null : jugadores.EquipoID; entidad.EstadoCivilID = jugadores.EstadoCivilID; entidad.InstruccionID = jugadores.InstruccionID; entidad.ProfesionID = jugadores.ProfesionID; entidad.ProvinciaID = jugadores.ProvinciaID; entidad.ParroquiaID = jugadores.ParroquiaID; entidad.Cedula = jugadores.Cedula.Trim(); entidad.Nombre = jugadores.Nombre.Trim(); entidad.Apellido = jugadores.Apellido.Trim(); entidad.FechaNacimiento = jugadores.FechaNacimiento; entidad.Carnet = jugadores.Carnet; entidad.FechaAfiliacion = jugadores.FechaAfiliacion; //Cada vez que se modifique algo sera enviado a calificar. entidad.Calificado = false; if (!string.IsNullOrWhiteSpace(jugadores.NombreArchivo)) { if (System.IO.File.Exists(path + "\\" + jugadores.NombreArchivo)) { entidad.Foto = FormateadorImagen.CambiarTamanio(path + "\\" + jugadores.NombreArchivo, 100, 200); } } _context.Jugadores.Update(entidad); await _context.SaveChangesAsync(); // Al final de la modificación eliminamos el archivo if (!string.IsNullOrWhiteSpace(jugadores.NombreArchivo)) { System.IO.File.Delete(path + "\\" + jugadores.NombreArchivo); } } catch (DbUpdateConcurrencyException ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } catch (Exception ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } return(Ok("Registro Actualizado")); }
public async Task <IActionResult> Editar(int id, [Bind("LigaID, SerieID, CategoriaID, DirigenteID, Nombre, Color, FechaFundacion, NombreArchivo")] Equipos equipos) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { string path = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\images\TempFotos"}"; Equipos entidad = _context.Equipos.Find(id); entidad.LigaID = equipos.LigaID == 0 ? null : equipos.LigaID; entidad.SerieID = equipos.SerieID == 0 ? null : equipos.SerieID; entidad.CategoriaID = equipos.CategoriaID == 0 ? null : equipos.CategoriaID; entidad.DirigenteID = equipos.DirigenteID == 0 ? null : equipos.DirigenteID; entidad.Nombre = equipos.Nombre.Trim(); entidad.Color = equipos.Color.Trim(); entidad.FechaFundacion = equipos.FechaFundacion; if (!string.IsNullOrWhiteSpace(equipos.NombreArchivo)) { if (System.IO.File.Exists(path + "\\" + equipos.NombreArchivo)) { entidad.Foto = FormateadorImagen.CambiarTamanio(path + "\\" + equipos.NombreArchivo, 200, 200); } } _context.Equipos.Update(entidad); await _context.SaveChangesAsync(); // Al final de la modificación eliminamos el archivo if (!string.IsNullOrWhiteSpace(equipos.NombreArchivo)) { System.IO.File.Delete(path + "\\" + equipos.NombreArchivo); } } catch (DbUpdateConcurrencyException ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } catch (Exception ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } return(Ok("Registro Actualizado")); }
public async Task <IActionResult> Editar(int id, [Bind("Cedula, Nombre, Apellido, Direccion, Pais, Telefono, CorreoElectronico, NombreArchivo")] Arbitros arbitros) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { string path = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\images\TempFotos"}"; Arbitros entidad = _context.Arbitros.Find(id); entidad.Cedula = arbitros.Cedula.Trim(); entidad.Nombre = arbitros.Nombre.Trim(); entidad.Apellido = arbitros.Apellido.Trim(); entidad.Direccion = arbitros.Direccion.Trim(); entidad.Pais = arbitros.Pais.Trim(); entidad.Telefono = arbitros.Telefono; entidad.CorreoElectronico = arbitros.CorreoElectronico.Trim(); if (!string.IsNullOrWhiteSpace(arbitros.NombreArchivo)) { if (System.IO.File.Exists(path + "\\" + arbitros.NombreArchivo)) { entidad.Foto = FormateadorImagen.CambiarTamanio(path + "\\" + arbitros.NombreArchivo, 275, 350); } } _context.Arbitros.Update(entidad); await _context.SaveChangesAsync(); // Al final de la modificación eliminamos el archivo if (!string.IsNullOrWhiteSpace(arbitros.NombreArchivo)) { System.IO.File.Delete(path + "\\" + arbitros.NombreArchivo); } } catch (DbUpdateConcurrencyException ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } catch (Exception ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } return(Ok("Registro Actualizado")); }
public async Task <IActionResult> Crear([Bind("LigaID, SerieID, CategoriaID, DirigenteID, Nombre, Color, FechaFundacion, NombreArchivo")] Equipos equipos) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { string path = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\images\TempFotos"}"; Equipos entidad = new Equipos { LigaID = equipos.LigaID == 0 ? null : equipos.LigaID, SerieID = equipos.SerieID == 0 ? null : equipos.SerieID, CategoriaID = equipos.CategoriaID == 0 ? null : equipos.CategoriaID, DirigenteID = equipos.DirigenteID == 0 ? null : equipos.DirigenteID, Nombre = equipos.Nombre.Trim(), Color = equipos.Color.Trim(), FechaFundacion = equipos.FechaFundacion, Foto = string.IsNullOrWhiteSpace(equipos.NombreArchivo) == false?FormateadorImagen.CambiarTamanio(path + "\\" + equipos.NombreArchivo, 200, 200) : null, //Valores fijos Estado = true }; _context.Equipos.Add(entidad); await _context.SaveChangesAsync(); // Al final de la modificación eliminamos el archivo if (!string.IsNullOrWhiteSpace(equipos.NombreArchivo)) { System.IO.File.Delete(path + "\\" + equipos.NombreArchivo); } return(Ok(entidad)); } catch (DbUpdateConcurrencyException ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } catch (Exception ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } }
public async Task <IActionResult> Crear([Bind("Cedula, Nombre, Apellido, Direccion, Pais, Telefono, CorreoElectronico, NombreArchivo")] Arbitros arbitros) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { string path = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\images\TempFotos"}"; Arbitros entidad = new Arbitros { Cedula = arbitros.Cedula.Trim(), Nombre = arbitros.Nombre.Trim(), Apellido = arbitros.Apellido.Trim(), Direccion = arbitros.Direccion.Trim(), Pais = arbitros.Pais.Trim(), Telefono = arbitros.Telefono, CorreoElectronico = arbitros.CorreoElectronico.Trim(), Foto = string.IsNullOrWhiteSpace(arbitros.NombreArchivo) == false?FormateadorImagen.CambiarTamanio(path + "\\" + arbitros.NombreArchivo, 275, 350) : null, //Valores fijos Estado = true }; _context.Arbitros.Add(entidad); await _context.SaveChangesAsync(); if (!string.IsNullOrWhiteSpace(arbitros.NombreArchivo)) { System.IO.File.Delete(path + "\\" + arbitros.NombreArchivo); } } catch (DbUpdateConcurrencyException ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } catch (Exception ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } return(Ok(arbitros)); }
public async Task <IActionResult> Crear([Bind("EquipoID, EstadoCivilID, InstruccionID, ProfesionID, ProvinciaID, ParroquiaID, Cedula, Nombre, Apellido, FechaNacimiento, Carnet, FechaAfiliacion, NombreArchivo")] Jugadores jugadores) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { string path = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\images\TempFotos"}"; Jugadores entidad = new Jugadores { EquipoID = jugadores.EquipoID == 0 ? null : jugadores.EquipoID, EstadoCivilID = jugadores.EstadoCivilID, InstruccionID = jugadores.InstruccionID, ProfesionID = jugadores.ProfesionID, ProvinciaID = jugadores.ProvinciaID, ParroquiaID = jugadores.ParroquiaID, Cedula = jugadores.Cedula.Trim(), Nombre = jugadores.Nombre.Trim(), Apellido = jugadores.Apellido.Trim(), FechaNacimiento = jugadores.FechaNacimiento, Carnet = jugadores.Carnet, FechaAfiliacion = jugadores.FechaAfiliacion, Foto = string.IsNullOrWhiteSpace(jugadores.NombreArchivo) == false?FormateadorImagen.CambiarTamanio(path + "\\" + jugadores.NombreArchivo, 100, 200) : null, //Valores fijos Calificado = false, Estado = true }; _context.Jugadores.Add(entidad); await _context.SaveChangesAsync(); // Al final de la modificación eliminamos el archivo if (!string.IsNullOrWhiteSpace(jugadores.NombreArchivo)) { System.IO.File.Delete(path + "\\" + jugadores.NombreArchivo); } } catch (DbUpdateConcurrencyException ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } catch (Exception ex) { string errMsg = FormateadorCadenas.ObtenerMensajesErrores(ex); return(BadRequest(errMsg)); } return(Ok(jugadores)); }