public async Task <IActionResult> List(string name = null, DateTime?creationDateFrom = null, DateTime?creationDateTo = null, int?idEmpresa = null)
        {
            try
            {
                var filters  = new RolFilterDTO(name, creationDateFrom, creationDateTo, idEmpresa);
                var entities = await _rolService.List(this.Usuario, this.IsSuperUser, filters);

                return(Ok(entities));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e));
            }
        }
Beispiel #2
0
        public async Task <IEnumerable <RolDTO> > List(UsuarioDTO userLogged, bool isSuperUser, RolFilterDTO filter = null)
        {
            IEnumerable <Rol> entities;
            var prueba = filter;

            if (isSuperUser)
            {
                entities = await _rolRepository.ListBy(rol =>
                                                       (
                                                           (!filter.IdEmpresa.HasValue || rol.IdEmpresa == filter.IdEmpresa.Value) &&
                                                           (!filter.CreationDateFrom.HasValue || rol.CreationDate >= filter.CreationDateFrom.Value) &&
                                                           (!filter.CreationDateTo.HasValue || rol.CreationDate <= filter.CreationDateTo.Value) &&

                                                           (filter.Datos.IsNullOrEmpty() || rol.Nombre.ToLower().Contains(filter.Datos) ||
                                                            rol.Descripcion.ToLower().Contains(filter.Datos))
                                                       ) &&

                                                       rol.Active == true,
                                                       rol => rol.Empresa
                                                       );
            }

            else
            {
                entities = await _rolRepository.ListBy(rol =>
                                                       rol.IdEmpresa == userLogged.IdEmpresa &&
                                                       ((!filter.CreationDateFrom.HasValue || rol.CreationDate >= filter.CreationDateFrom.Value) &&
                                                        (!filter.CreationDateTo.HasValue || rol.CreationDate <= filter.CreationDateTo.Value) &&
                                                        (filter.Datos.IsNullOrEmpty() || rol.Nombre.ToLower().Contains(filter.Datos) ||
                                                         rol.Descripcion.ToLower().Contains(filter.Datos))) &&
                                                       rol.Active == true,
                                                       includeProperties => includeProperties.Empresa
                                                       );
            }
            var dtos = _mapper.Map <IEnumerable <RolDTO> >(entities);

            return(dtos);
        }