public Respuesta <Participante> Actualizar() { Respuesta <Participante> result = new Respuesta <Participante>(); result.codigo = 1; result.mensaje = "Ocurrio un Error en Base de datos"; result.data = new Participante(); if (this.nombre == null) { result.codigo = -1; result.mensaje = "El dato del nombre no puede ser vacio, colocar un nombre valido"; return(result); } else if (this.apellido == null) { result.codigo = -1; result.mensaje = "El dato del apellido no puede ser vacio, colocar un apellido valido"; return(result); } else if (this.telefono == null) { result.codigo = -1; result.mensaje = "El dato del telefono no puede ser vacio, colocar un telefono valido"; return(result); } else if (this.genero == null) { result.codigo = -1; result.mensaje = "El dato del geneo no puede ser vacio, colocar un dato de geneo valido"; return(result); } else if (this.fechaNacimiento == null) { result.codigo = -1; result.mensaje = "El dato de la Fecha de Nacimiento no puede ser vacio, colocar un dato de Fecha de Nacimiento valido"; return(result); } try { using (var tr = new TransactionScope()) { using (var db = new EntitiesEVE01()) { var existente = (from e in db.EVE01_PARTICIPANTE where e.PARTICIPANTE == this.idParticipante select e).SingleOrDefault(); existente.NOMBRE = this.nombre.ToUpper(); existente.APELLIDO = this.apellido.ToUpper(); existente.DIRECCION = this.direccion; existente.TELEFONO = this.telefono; existente.CORREO = this.correo; existente.TALLA = this.talla; existente.GENERO = this.genero; existente.FECHA_NACIMIENTO = this.fechaNacimiento; existente.ALERJICO = this.alerjico; existente.OBSERVACIONES = this.observaciones; existente.USUARIO_MODIFICACION = MvcApplication.UserName; existente.FECHA_MODIFICACION = DateTime.Now; int rap = db.SaveChanges(); if (rap <= 0) { Transaction.Current.Rollback(); result.codigo = -2; result.mensaje = "Ocurrio un error al tratar de actualizar los datos"; return(result); } var validaActualizacionEvento = (from va in db.EVE01_EVENTO_ACTUALIZACION where va.EVENTO == MvcApplication.idEvento && va.PARTICIPANTE == this.idParticipante select va).SingleOrDefault(); if (validaActualizacionEvento == null) { EVE01_EVENTO_ACTUALIZACION actualizacion = new EVE01_EVENTO_ACTUALIZACION(); actualizacion.EVENTO = MvcApplication.idEvento; actualizacion.PARTICIPANTE = this.idParticipante; actualizacion.ESTADO_REGISTO = "A"; actualizacion.USUARIO_CREACION = MvcApplication.UserName; actualizacion.FECHA_CREACION = DateTime.Now; db.EVE01_EVENTO_ACTUALIZACION.Add(actualizacion); int ria = db.SaveChanges(); if (ria <= 0) { Transaction.Current.Rollback(); result.codigo = -2; result.mensaje = "Ocurrio un error al registrar la actualizacion de datos del evento actual"; return(result); } } } tr.Complete(); } result.codigo = 0; result.mensaje = "Se actualizaron correctamente los datos del Participante"; return(result); } catch (Exception ex) { result.codigo = -1; result.mensaje = "Ocurrio una Excepcion al tratar de Registrar al Participante, ref: " + ex.ToString(); result.mensajeError = ex.ToString(); return(result); } }
public Respuesta <Participante> Nuevo() { Respuesta <Participante> result = new Respuesta <Participante>(); result.codigo = 1; result.mensaje = "Ocurrio un Error en Base de datos"; result.data = new Participante(); if (MvcApplication.idEvento == 0) { result.codigo = -1; result.data = new Participante(); result.mensaje = "Para registrar una Participante Nuevo, debe iniciar un Evento"; return(result); } if (this.nombre == null) { result.codigo = -1; result.mensaje = "El dato del nombre no puede ser vacio, colocar un nombre valido"; return(result); } else if (this.apellido == null) { result.codigo = -1; result.mensaje = "El dato del apellido no puede ser vacio, colocar un apellido valido"; return(result); } else if (this.telefono == null) { result.codigo = -1; result.mensaje = "El dato del telefono no puede ser vacio, colocar un telefono valido"; return(result); } else if (this.genero == null) { result.codigo = -1; result.mensaje = "El dato del geneo no puede ser vacio, colocar un dato de geneo valido"; return(result); } else if (this.fechaNacimiento == null) { result.codigo = -1; result.mensaje = "El dato de la Fecha de Nacimiento no puede ser vacio, colocar un dato de Fecha de Nacimiento valido"; return(result); } try { using (var tr = new TransactionScope()) { using (var db = new EntitiesEVE01()) { var correlativo = (from c in db.EVE01_PARTICIPANTE select c.PARTICIPANTE).Max(); var corr = correlativo + 1; correlativo = correlativo == null ? 1 : corr; EVE01_PARTICIPANTE nuevo = new EVE01_PARTICIPANTE(); nuevo.PARTICIPANTE = correlativo; nuevo.NOMBRE = this.nombre.ToUpper(); nuevo.APELLIDO = this.apellido.ToUpper(); nuevo.DIRECCION = this.direccion; nuevo.TELEFONO = this.telefono; nuevo.CORREO = this.correo; nuevo.TALLA = this.talla; nuevo.GENERO = this.genero; nuevo.FECHA_NACIMIENTO = this.fechaNacimiento; nuevo.ALERJICO = this.alerjico; nuevo.OBSERVACIONES = this.observaciones; nuevo.ESTADO_REGISTRO = "A"; nuevo.USUARIO_CREACION = MvcApplication.UserName; nuevo.FECHA_CREACION = DateTime.Now; db.EVE01_PARTICIPANTE.Add(nuevo); int rgp = db.SaveChanges(); if (rgp <= 0) { Transaction.Current.Rollback(); result.codigo = -2; result.mensaje = "Ocurrio un error al registrar al participante"; return(result); } EVE01_EVENTO_ACTUALIZACION actualizacion = new EVE01_EVENTO_ACTUALIZACION(); actualizacion.EVENTO = MvcApplication.idEvento; actualizacion.PARTICIPANTE = correlativo; actualizacion.ESTADO_REGISTO = "A"; actualizacion.USUARIO_CREACION = MvcApplication.UserName; actualizacion.FECHA_CREACION = DateTime.Now; db.EVE01_EVENTO_ACTUALIZACION.Add(actualizacion); int ria = db.SaveChanges(); if (ria <= 0) { Transaction.Current.Rollback(); result.codigo = -2; result.mensaje = "Ocurrio un error al registrar la actualizacion de datos del evento actual"; return(result); } result.data.idParticipante = correlativo; } tr.Complete(); } result.codigo = 0; result.mensaje = "Se registro Correctamente al Participante: " + this.nombre + " " + this.apellido; return(result); } catch (Exception ex) { result.codigo = -1; result.mensaje = "Ocurrio una Excepcion al tratar de Registrar al Participante, ref: " + ex.ToString(); result.mensajeError = ex.ToString(); return(result); } }