public async Task <CrearActividadesGestionCambioViewModel> CrearActividadesGestionCambio([FromBody] ActividadesGestionCambioViewModel actividadesGestionCambioViewModel)
        {
            var modelo = new CrearActividadesGestionCambioViewModel();

            modelo.actividadesGestionCambioViewModel = new ActividadesGestionCambioViewModel {
                FechaInicio   = DateTime.Now,
                FechaFin      = DateTime.Now,
                Observaciones = ""
            };

            modelo.ListaDatosBasicosEmpleadoViewModel         = new List <DatosBasicosEmpleadoViewModel>();
            modelo.ListaEstadoActividadGestionCambioViewModel = new List <EstadoActividadGestionCambioViewModel>();
            modelo.ListaDependenciasViewModel = new List <DependenciaViewModel>();

            try
            {
                var empleado = db.Empleado.Include(d => d.Dependencia)
                               .Where(x => x.NombreUsuario == actividadesGestionCambioViewModel.NombreUsuario)
                               .FirstOrDefault()
                ;


                // Obtención de estados desde las constantes
                modelo.ListaEstadoActividadGestionCambioViewModel = Constantes.ListaEstadosGestionCambio;

                // Obtención de los empleados por sucursal
                modelo.ListaDatosBasicosEmpleadoViewModel = await db.Empleado
                                                            .Where(w =>
                                                                   w.Dependencia.IdSucursal == empleado.Dependencia.IdSucursal
                                                                   )
                                                            .Select(s => new DatosBasicosEmpleadoViewModel
                {
                    IdEmpleado = s.IdEmpleado,
                    Nombres    = s.Persona.Nombres + " " + s.Persona.Apellidos
                }
                                                                    )
                                                            .ToListAsync();

                // Obtención de dependencias por sucursal
                modelo.ListaDependenciasViewModel = await db.Dependencia
                                                    .Where(w =>
                                                           w.IdSucursal == empleado.Dependencia.IdSucursal
                                                           )
                                                    .Select(s => new DependenciaViewModel
                {
                    IdDependencia     = s.IdDependencia,
                    NombreDependencia = s.Nombre,
                    IdSucursal        = s.IdSucursal
                }
                                                            )
                                                    .ToListAsync();


                return(modelo);
            }
            catch (Exception)
            {
                return(modelo);
            }
        }
        public async Task <CrearActividadesGestionCambioViewModel> ObtenerActividadesGestionCambioPorId([FromBody] ActividadesGestionCambioViewModel actividadesGestionCambioViewModel)
        {
            var modelo = new CrearActividadesGestionCambioViewModel();

            modelo.actividadesGestionCambioViewModel = new ActividadesGestionCambioViewModel
            {
                FechaInicio = DateTime.Now,
                FechaFin    = DateTime.Now
            };

            modelo.ListaDatosBasicosEmpleadoViewModel         = new List <DatosBasicosEmpleadoViewModel>();
            modelo.ListaEstadoActividadGestionCambioViewModel = new List <EstadoActividadGestionCambioViewModel>();
            modelo.ListaDependenciasViewModel = new List <DependenciaViewModel>();

            try
            {
                var empleado = db.Empleado.Include(d => d.Dependencia)
                               .Where(x => x.NombreUsuario == actividadesGestionCambioViewModel.NombreUsuario)
                               .FirstOrDefault()
                ;

                var idSucursal = empleado.Dependencia.IdSucursal;

                // Obtención de estados desde las constantes
                modelo.ListaEstadoActividadGestionCambioViewModel = Constantes.ListaEstadosGestionCambio;

                // Obtención de los empleados por sucursal
                modelo.ListaDatosBasicosEmpleadoViewModel = await db.Empleado
                                                            .Where(w =>
                                                                   w.Dependencia.IdSucursal == idSucursal
                                                                   )
                                                            .Select(s => new DatosBasicosEmpleadoViewModel
                {
                    IdEmpleado = s.IdEmpleado,
                    Nombres    = s.Persona.Nombres + " " + s.Persona.Apellidos
                }
                                                                    )
                                                            .ToListAsync();

                // Obtención de dependencias por sucursal
                modelo.ListaDependenciasViewModel = await db.Dependencia
                                                    .Where(w =>
                                                           w.IdSucursal == empleado.Dependencia.IdSucursal
                                                           )
                                                    .Select(s => new DependenciaViewModel
                {
                    IdDependencia     = s.IdDependencia,
                    NombreDependencia = s.Nombre,
                    IdSucursal        = s.IdSucursal
                }
                                                            )
                                                    .ToListAsync();

                //Obtención del registro
                modelo.actividadesGestionCambioViewModel = await db.ActividadesGestionCambio.Include(d => d.Dependencia).Include(e => e.Empleado).ThenInclude(p => p.Persona)
                                                           .Where(w =>
                                                                  w.IdActividadesGestionCambio == actividadesGestionCambioViewModel.IdActividadesGestionCambio
                                                                  )
                                                           .Select(x => new ActividadesGestionCambioViewModel
                {
                    IdActividadesGestionCambio = x.IdActividadesGestionCambio,

                    IdDependencia     = x.IdDependencia,
                    NombreDependencia = x.Dependencia.Nombre,

                    IdEmpleado     = x.IdEmpleado,
                    NombreEmpleado = x.Empleado.Persona.Nombres + " " + x.Empleado.Persona.Apellidos,

                    Avance        = x.Avance,
                    FechaInicio   = x.FechaInicio,
                    FechaFin      = x.FechaFin,
                    Observaciones = x.Observaciones,
                    Tarea         = x.Tarea,

                    ValorEstado = x.EstadoActividadesGestionCambio,
                    Estado      = Constantes.ListaEstadosGestionCambio.Where(a => a.Valor == x.EstadoActividadesGestionCambio).FirstOrDefault().Nombre
                }
                                                                   )
                                                           .FirstOrDefaultAsync();

                return(modelo);
            }
            catch (Exception ex)
            {
                return(modelo);
            }
        }