public async Task <Response> IndiceOcupacionalModalidadPartidaPorIdEmpleado([FromBody] IndiceOcupacionalModalidadPartida indiceOcupacionalModalidadPartida) { try { var IndiceOcupacionalModalidadPartida = await db.IndiceOcupacionalModalidadPartida.SingleOrDefaultAsync(m => m.IdEmpleado == indiceOcupacionalModalidadPartida.IdEmpleado); var response = new Response { IsSuccess = true, Resultado = IndiceOcupacionalModalidadPartida, }; return(response); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.SwTH), ExceptionTrace = ex.Message, Message = Mensaje.Excepcion, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "", }); return(new Response { }); } }
public async Task <IActionResult> Create(IndiceOcupacionalModalidadPartida indiceOcupacionalModalidadPartida) { Response response = new Response(); try { if (indiceOcupacionalModalidadPartida.IndiceOcupacional.Nivel == "0") { indiceOcupacionalModalidadPartida.IndiceOcupacional.Nivel = Constantes.NivelProfesional; } else { indiceOcupacionalModalidadPartida.IndiceOcupacional.Nivel = Constantes.NivelNoProfesional; } response = await apiServicio.InsertarAsync( indiceOcupacionalModalidadPartida.IndiceOcupacional, new Uri(WebApp.BaseAddress), "api/IndicesOcupacionales/InsertarIndiceOcupacional" ); if (response.IsSuccess) { return(RedirectToAction("Index")); } await CargarListaCombox(); this.TempData["MensajeTimer"] = $"{Mensaje.Error}|{response.Message}|{"10000"}"; var indiceDetalle = new IndiceOcupacionalDetalle { IndiceOcupacionalModalidadPartida = indiceOcupacionalModalidadPartida }; return(View(indiceDetalle)); } catch (Exception ex) { return(BadRequest()); } }
private Response Existe(IndiceOcupacionalModalidadPartida IndiceOcupacionalModalidadPartida) { var fecha = IndiceOcupacionalModalidadPartida.Fecha; var salarioReal = IndiceOcupacionalModalidadPartida.SalarioReal; //var IndiceOcupacionalModalidadPartidarespuesta = db.IndiceOcupacionalModalidadPartida.Where(p => p.Fecha == fecha && p.SalarioReal == salarioReal && p.IdIndiceOcupacional == IndiceOcupacionalModalidadPartida.IdIndiceOcupacional && p.IdEmpleado == IndiceOcupacionalModalidadPartida.IdEmpleado && p.IdFondoFinanciamiento == IndiceOcupacionalModalidadPartida.IdFondoFinanciamiento && p.IdModalidadPartida == IndiceOcupacionalModalidadPartida.IdModalidadPartida && p.IdTipoNombramiento == IndiceOcupacionalModalidadPartida.IdTipoNombramiento).FirstOrDefault(); var IndiceOcupacionalModalidadPartidarespuesta = db.IndiceOcupacionalModalidadPartida.Where(p => p.Fecha == fecha && p.SalarioReal == salarioReal && p.IdIndiceOcupacional == IndiceOcupacionalModalidadPartida.IdIndiceOcupacional && p.IdEmpleado == IndiceOcupacionalModalidadPartida.IdEmpleado && p.IdFondoFinanciamiento == IndiceOcupacionalModalidadPartida.IdFondoFinanciamiento && p.IdTipoNombramiento == IndiceOcupacionalModalidadPartida.IdTipoNombramiento).FirstOrDefault(); if (IndiceOcupacionalModalidadPartidarespuesta != null) { return(new Response { IsSuccess = true, Message = Mensaje.ExisteRegistro, Resultado = IndiceOcupacionalModalidadPartidarespuesta, }); } return(new Response { IsSuccess = false, Resultado = IndiceOcupacionalModalidadPartidarespuesta, }); }
public async Task <Response> InsertarIndiceOcupacional([FromBody] IndiceOcupacional indiceOcupacional) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = Mensaje.ModeloInvalido, }); } var respuesta = Existe(indiceOcupacional); if (!respuesta.IsSuccess) { using (var transaction = await db.Database.BeginTransactionAsync()) { // Se crea el índice ocupacional db.IndiceOcupacional.Add(indiceOcupacional); // Se crea un indice ocupacional modalidad partida vacío // para el historial var modelo = new IndiceOcupacionalModalidadPartida { IdIndiceOcupacional = indiceOcupacional.IdIndiceOcupacional, IdEmpleado = null, IdFondoFinanciamiento = null, IdTipoNombramiento = null, Fecha = DateTime.Now, SalarioReal = null, CodigoContrato = null, NumeroPartidaIndividual = null, IdModalidadPartida = null }; db.IndiceOcupacionalModalidadPartida.Add(modelo); await db.SaveChangesAsync(); transaction.Commit(); return(new Response { IsSuccess = true, Message = Mensaje.Satisfactorio }); } // end transaction } return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro }); } catch (Exception ex) { return(new Response { IsSuccess = false, Message = Mensaje.Error, }); } }
public async Task <Response> ListarFichaMedicaViewModel([FromBody] FichaMedicaViewModel fmv) { try { Persona personaVar = new Persona(); if (fmv.DatosBasicosPersonaViewModel.IdPersona < 1) { try { personaVar = db.Persona.Where(x => x.Identificacion == fmv.DatosBasicosPersonaViewModel.Identificacion).FirstOrDefault(); } catch (Exception ex) { return(new Response { IsSuccess = false, Message = Mensaje.RegistroNoEncontrado }); } } else { try { personaVar = db.Persona.Where(x => x.IdPersona == fmv.DatosBasicosPersonaViewModel.IdPersona).FirstOrDefault(); } catch (Exception ex) { return(new Response { IsSuccess = false, Message = Mensaje.RegistroNoEncontrado }); } } if (personaVar == null) { return(new Response { IsSuccess = false, Message = Mensaje.RegistroNoEncontrado }); } PersonaEstudio personaEstudioVar = db.PersonaEstudio.Where(x => x.IdPersona == personaVar.IdPersona).FirstOrDefault(); Sexo sexoVar = db.Sexo.Where(x => x.IdSexo == personaVar.IdSexo).FirstOrDefault(); Nacionalidad NacionalidadVar = db.Nacionalidad.Where(x => x.IdNacionalidad == personaVar.IdNacionalidad).FirstOrDefault(); Parroquia parroquiaVar = db.Parroquia.Where(x => x.IdParroquia == personaVar.IdParroquia).FirstOrDefault(); EstadoCivil estadoCivilVar = db.EstadoCivil.Where(x => x.IdEstadoCivil == personaVar.IdEstadoCivil).FirstOrDefault(); Etnia etniaVar = db.Etnia.Where(x => x.IdEtnia == personaVar.IdEtnia).FirstOrDefault(); TipoSangre tipoSangreVar = db.TipoSangre.Where(x => x.IdTipoSangre == personaVar.IdTipoSangre).FirstOrDefault(); PersonaDiscapacidad personaDiscapacidadVar = db.PersonaDiscapacidad.Where(x => x.IdPersona == personaVar.IdPersona).FirstOrDefault(); Empleado empleadoVar = db.Empleado.Where(x => x.IdPersona == personaVar.IdPersona).FirstOrDefault(); /* INICIALIZACIÓN DE OBJETOS CON VALORES NULOS */ Titulo tituloVar = new Titulo(); Estudio estudioVar = new Estudio(); EmpleadoContactoEmergencia contactoEmergenciaVar = new EmpleadoContactoEmergencia(); Dependencia dependenciaVar = new Dependencia(); EmpleadoFamiliar empleadoFamiliarVar = new EmpleadoFamiliar(); Persona personaEmergenciaVar = new Persona(); Sucursal sucursalVar = new Sucursal(); Parentesco parentescoVar = new Parentesco(); TipoDiscapacidad discapacidadVar = new TipoDiscapacidad(); IndiceOcupacionalModalidadPartida indOcupModParVar = new IndiceOcupacionalModalidadPartida(); IndiceOcupacional inOcupVar = new IndiceOcupacional(); ManualPuesto manPuestoVar = new ManualPuesto(); /* INICIALIZACIÓN DE VARIABLES NULAS*/ var datoConadis = ""; var datoPorcentaje = ""; var datoCargoTrabajo = ""; var datoPuestoTrabajo = ""; var datoEdad = ""; bool datoCondicionEspecial = false; int datoNumHijos = 0; var datoSedeTrabajo = ""; var datoPersonaEmergencia = ""; var datoPersonaEmergenciaContacto = ""; var nombreCampoHijos = "Hijo/a"; if (personaEstudioVar != null && personaEstudioVar.IdPersonaEstudio > 0) { tituloVar = db.Titulo.Where(x => x.IdTitulo == personaEstudioVar.IdTitulo).FirstOrDefault(); } if (tituloVar != null && tituloVar.IdEstudio > 0) { estudioVar = db.Estudio.Where(x => x.IdEstudio == tituloVar.IdEstudio).FirstOrDefault(); } if (empleadoVar != null && empleadoVar.IdEmpleado > 0) { contactoEmergenciaVar = db.EmpleadoContactoEmergencia.Where(x => x.IdEmpleado == empleadoVar.IdEmpleado).FirstOrDefault(); dependenciaVar = db.Dependencia.Where(x => x.IdDependencia == empleadoVar.IdDependencia).FirstOrDefault(); empleadoFamiliarVar = db.EmpleadoFamiliar.Where(x => x.IdEmpleado == empleadoVar.IdEmpleado).FirstOrDefault(); indOcupModParVar = db.IndiceOcupacionalModalidadPartida.Where(x => x.IdEmpleado == empleadoVar.IdEmpleado).FirstOrDefault(); var listaHijos = db.EmpleadoFamiliar.Where(x => x.IdEmpleado == empleadoVar.IdEmpleado).ToList(); datoNumHijos = listaHijos.Count(); } if (indOcupModParVar != null && indOcupModParVar.IdEmpleado > 0) { inOcupVar = db.IndiceOcupacional.Where(x => x.IdIndiceOcupacional == indOcupModParVar.IdIndiceOcupacional).FirstOrDefault(); } if (inOcupVar != null && inOcupVar.IdIndiceOcupacional > 0) { manPuestoVar = db.ManualPuesto.Where(x => x.IdManualPuesto == inOcupVar.IdManualPuesto).FirstOrDefault(); } if (contactoEmergenciaVar != null && contactoEmergenciaVar.IdEmpleadoContactoEmergencia > 0) { personaEmergenciaVar = db.Persona.Where(x => x.IdPersona == contactoEmergenciaVar.IdPersona).FirstOrDefault(); } if (dependenciaVar != null && dependenciaVar.IdDependencia > 0) { sucursalVar = db.Sucursal.Where(x => x.IdSucursal == dependenciaVar.IdSucursal).FirstOrDefault(); } if (empleadoFamiliarVar != null && empleadoFamiliarVar.IdEmpleadoFamiliar > 0 && contactoEmergenciaVar != null && contactoEmergenciaVar.IdEmpleadoContactoEmergencia > 0) { parentescoVar = db.Parentesco.Where(x => x.IdParentesco == contactoEmergenciaVar.IdParentesco).FirstOrDefault(); } if (personaDiscapacidadVar != null && personaDiscapacidadVar.IdPersonaDiscapacidad > 0) { discapacidadVar = db.TipoDiscapacidad.Where(x => x.IdTipoDiscapacidad == personaDiscapacidadVar.IdTipoDiscapacidad).FirstOrDefault(); datoCondicionEspecial = true; } /* Validación obtencion de dato nulo */ if (discapacidadVar != null && discapacidadVar.IdTipoDiscapacidad > 0) { datoConadis = personaDiscapacidadVar.NumeroCarnet; datoPorcentaje = personaDiscapacidadVar.Porciento + " %"; } if (sucursalVar != null && sucursalVar.IdSucursal > 0) { datoSedeTrabajo = sucursalVar.Nombre; } if (personaEmergenciaVar != null && personaEmergenciaVar.IdPersona > 0) { datoPersonaEmergencia = personaEmergenciaVar.Nombres + " " + personaEmergenciaVar.Apellidos; datoPersonaEmergenciaContacto = personaEmergenciaVar.TelefonoCasa + " " + personaEmergenciaVar.TelefonoPrivado; } if (manPuestoVar != null && manPuestoVar.IdManualPuesto > 0) { datoPuestoTrabajo = manPuestoVar.Descripcion; datoCargoTrabajo = manPuestoVar.Nombre; } DateTime year = (DateTime)personaVar.FechaNacimiento; int yActual = DateTime.Now.Year; int yNacimiento = (int)(year.Year); datoEdad = (yActual - yNacimiento) + ""; DatosBasicosPersonaViewModel dbvm = new DatosBasicosPersonaViewModel { IdPersona = personaVar.IdPersona, NombresApellidos = personaVar.Nombres + " " + personaVar.Apellidos, Identificacion = personaVar.Identificacion, LugarNacimiento = NacionalidadVar.Nombre + "/ " + parroquiaVar.Nombre, FechaNacimiento = year.ToString("dd/MM/yyyy"), DireccionDomiciliaria = personaVar.CallePrincipal + " " + personaVar.CalleSecundaria + " " + personaVar.Numero, Telefono = personaVar.TelefonoPrivado + " " + personaVar.TelefonoCasa, Edad = datoEdad, Genero = sexoVar.Nombre, NivelEducativo = estudioVar.Nombre, EstadoCivil = estadoCivilVar.Nombre, Profesion = (tituloVar != null)? tituloVar.Nombre:"", NumeroHijos = datoNumHijos, Etnia = etniaVar.Nombre, CondicionEspecial = datoCondicionEspecial, TipoDiscapacidad = discapacidadVar.Nombre, Conadis = datoConadis, Porcentaje = datoPorcentaje, NombreCargoTrabajo = datoCargoTrabajo, DescripcionPuestoTrabajo = datoPuestoTrabajo, SedeTrabajo = datoSedeTrabajo, ContactoEmergencias = datoPersonaEmergencia, Parentesco = parentescoVar.Nombre, ParienteTelefono = datoPersonaEmergenciaContacto, FechaIngreso = empleadoVar.FechaIngreso }; var ListaFichasMedicas = await db.FichaMedica.Where(x => x.IdPersona == personaVar.IdPersona).OrderByDescending(x => x.FechaFichaMedica).ToListAsync(); // devuelve una lista var fichaMedicaViewModel = new FichaMedicaViewModel { DatosBasicosPersonaViewModel = dbvm, FichasMedicas = ListaFichasMedicas, ListaPersonas = ListaPersonasFichaMedicaView() }; return(new Response { IsSuccess = true, Resultado = fichaMedicaViewModel }); } catch (Exception ex) { var fichaMedicaViewModel = new FichaMedicaViewModel(); return(new Response { IsSuccess = false, Resultado = fichaMedicaViewModel, Message = Mensaje.Error }); } }
public async Task <Response> PostIndiceOcupacionalModalidadPartida([FromBody] IndiceOcupacionalModalidadPartida IndiceOcupacionalModalidadPartida) { using (var transaction = await db.Database.BeginTransactionAsync()) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = "" }); } if ( IndiceOcupacionalModalidadPartida.IdEmpleado != null && IndiceOcupacionalModalidadPartida.IdTipoNombramiento == null ) { return(new Response { IsSuccess = false, Message = Mensaje.RequeridoTipoNombramiento }); } if (String.IsNullOrEmpty(IndiceOcupacionalModalidadPartida.NumeroPartidaIndividual)) { return(new Response { IsSuccess = false, Message = Mensaje.NumeroPartidaObligatorio }); } // Se obtienen los diferentes tipos de relación laboral var nombramiento = await db.TipoNombramiento .Include(i => i.RelacionLaboral) .Where(w => w.IdTipoNombramiento == IndiceOcupacionalModalidadPartida.IdTipoNombramiento) .FirstOrDefaultAsync(); // Se crea el modelo para guardar var modelo = new IndiceOcupacionalModalidadPartida { IdIndiceOcupacional = IndiceOcupacionalModalidadPartida.IdIndiceOcupacional, IdFondoFinanciamiento = IndiceOcupacionalModalidadPartida.IdFondoFinanciamiento, IdTipoNombramiento = IndiceOcupacionalModalidadPartida.IdTipoNombramiento, SalarioReal = IndiceOcupacionalModalidadPartida.SalarioReal, Fecha = IndiceOcupacionalModalidadPartida.Fecha, IdEmpleado = IndiceOcupacionalModalidadPartida.IdEmpleado }; if ( nombramiento != null && nombramiento.RelacionLaboral.Nombre.ToUpper() == ConstantesTipoRelacion.Contrato.ToUpper() ) { modelo.CodigoContrato = IndiceOcupacionalModalidadPartida.NumeroPartidaIndividual; modelo.FechaFin = IndiceOcupacionalModalidadPartida.FechaFin; // si el código ya existe para otro registro no debe guardar la información var existeCodigo = await db.IndiceOcupacionalModalidadPartida .Where(w => w.CodigoContrato == modelo.CodigoContrato) .FirstOrDefaultAsync(); if ( existeCodigo != null && existeCodigo.IdIndiceOcupacionalModalidadPartida != IndiceOcupacionalModalidadPartida.IdIndiceOcupacionalModalidadPartida ) { return(new Response { IsSuccess = false, Message = Mensaje.ErrorCodigoRepetido }); } } else if ( nombramiento != null && nombramiento.RelacionLaboral.Nombre.ToUpper() == ConstantesTipoRelacion.Nombramiento.ToUpper() ) { modelo.NumeroPartidaIndividual = IndiceOcupacionalModalidadPartida.NumeroPartidaIndividual; modelo.IdModalidadPartida = IndiceOcupacionalModalidadPartida.IdModalidadPartida; // si el código ya existe para otro registro no debe guardar la información var existeCodigo = await db.IndiceOcupacionalModalidadPartida .Where(w => w.NumeroPartidaIndividual == modelo.NumeroPartidaIndividual) .FirstOrDefaultAsync(); if ( existeCodigo != null && existeCodigo.IdIndiceOcupacionalModalidadPartida != IndiceOcupacionalModalidadPartida.IdIndiceOcupacionalModalidadPartida ) { return(new Response { IsSuccess = false, Message = Mensaje.ErrorNumeroPartidaRepetida }); } } if (IndiceOcupacionalModalidadPartida.IdIndiceOcupacionalModalidadPartida < 1) { // ** Si no existe un registro se crea uno nuevo db.IndiceOcupacionalModalidadPartida.Add(modelo); await db.SaveChangesAsync(); // ** Se agrega la dependencia y el estado del empleado cambia a activo var empleado = await db.Empleado.Where(x => x.IdEmpleado == modelo.IdEmpleado).FirstOrDefaultAsync(); empleado.TipoRelacion = nombramiento.RelacionLaboral.Nombre.ToUpper(); empleado.IdDependencia = IndiceOcupacionalModalidadPartida.IdDependencia; empleado.Activo = true; empleado.EsJefe = IndiceOcupacionalModalidadPartida.Empleado.EsJefe; db.Empleado.Update(empleado); await db.SaveChangesAsync(); transaction.Commit(); return(new Response { IsSuccess = true, Message = Mensaje.GuardadoSatisfactorio }); } else { // En caso de existir un registro se edita var empleadoModelo = await db.Empleado .Where(w => w.IdEmpleado == modelo.IdEmpleado) .FirstOrDefaultAsync(); empleadoModelo.TipoRelacion = nombramiento.RelacionLaboral.Nombre.ToUpper(); empleadoModelo.EsJefe = IndiceOcupacionalModalidadPartida.Empleado.EsJefe; empleadoModelo.Activo = true; empleadoModelo.IdDependencia = IndiceOcupacionalModalidadPartida.IdDependencia; db.Empleado.Update(empleadoModelo); var actualizar = await db.IndiceOcupacionalModalidadPartida .Where(w => w.IdIndiceOcupacionalModalidadPartida == IndiceOcupacionalModalidadPartida.IdIndiceOcupacionalModalidadPartida) .FirstOrDefaultAsync(); actualizar.IdIndiceOcupacional = modelo.IdIndiceOcupacional; actualizar.IdFondoFinanciamiento = modelo.IdFondoFinanciamiento; actualizar.IdTipoNombramiento = modelo.IdTipoNombramiento; actualizar.SalarioReal = modelo.SalarioReal; actualizar.Fecha = modelo.Fecha; actualizar.IdEmpleado = modelo.IdEmpleado; actualizar.CodigoContrato = modelo.CodigoContrato; actualizar.IdModalidadPartida = modelo.IdModalidadPartida; actualizar.NumeroPartidaIndividual = modelo.NumeroPartidaIndividual; actualizar.FechaFin = modelo.FechaFin; db.IndiceOcupacionalModalidadPartida.Update(actualizar); await db.SaveChangesAsync(); transaction.Commit(); return(new Response { IsSuccess = true, Message = Mensaje.GuardadoSatisfactorio }); } } catch (Exception ex) { transaction.Rollback(); return(new Response { IsSuccess = false, Message = Mensaje.Error, }); } } }
public async Task <Response> PutIndiceOcupacionalModalidadPartida([FromRoute] int id, [FromBody] IndiceOcupacionalModalidadPartida indiceOcupacionalModalidadPartida) { try { if (!ModelState.IsValid) { return(new Response { IsSuccess = false, Message = Mensaje.ModeloInvalido }); } var existe = Existe(indiceOcupacionalModalidadPartida); var IndiceOcupacionalModalidadPartidaActualizar = (IndiceOcupacionalModalidadPartida)existe.Resultado; if (existe.IsSuccess) { if (IndiceOcupacionalModalidadPartidaActualizar.IdIndiceOcupacionalModalidadPartida == indiceOcupacionalModalidadPartida.IdIndiceOcupacionalModalidadPartida) { return(new Response { IsSuccess = true, }); } return(new Response { IsSuccess = false, Message = Mensaje.ExisteRegistro, }); } var IndiceOcupacionalModalidadPartida = db.IndiceOcupacionalModalidadPartida.Find(indiceOcupacionalModalidadPartida.IdIndiceOcupacionalModalidadPartida); IndiceOcupacionalModalidadPartida.IdIndiceOcupacional = indiceOcupacionalModalidadPartida.IdIndiceOcupacional; IndiceOcupacionalModalidadPartida.IdEmpleado = indiceOcupacionalModalidadPartida.IdEmpleado; IndiceOcupacionalModalidadPartida.IdFondoFinanciamiento = indiceOcupacionalModalidadPartida.IdFondoFinanciamiento; //IndiceOcupacionalModalidadPartida.IdModalidadPartida = indiceOcupacionalModalidadPartida.IdModalidadPartida; IndiceOcupacionalModalidadPartida.IdTipoNombramiento = indiceOcupacionalModalidadPartida.IdTipoNombramiento; IndiceOcupacionalModalidadPartida.Fecha = indiceOcupacionalModalidadPartida.Fecha; IndiceOcupacionalModalidadPartida.SalarioReal = indiceOcupacionalModalidadPartida.SalarioReal; db.IndiceOcupacionalModalidadPartida.Update(IndiceOcupacionalModalidadPartida); await db.SaveChangesAsync(); return(new Response { IsSuccess = true, Message = Mensaje.Satisfactorio, }); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.SwTH), ExceptionTrace = ex.Message, Message = Mensaje.Excepcion, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "", }); return(new Response { IsSuccess = true, Message = Mensaje.Excepcion, }); } }