예제 #1
0
        public async Task <EnumerableResponse <List <PermisosDto> > > GetPermisosPagina(int?padre,
                                                                                        CancellationToken cancellationToken = new CancellationToken())
        {
            var errors = new List <BaseResponseDto>();

            cancellationToken.ThrowIfCancellationRequested();
            try
            {
                var response = await EnumerableResponse(await GetAll(string.Format("api/Permiso/PermisosPagina?Pagina={0}", padre)));

                var data = new List <PermisosDto>();
                if (response.ErrorCode == 200)
                {
                    dynamic jObject = (JObject)JsonConvert.DeserializeObject(response.jObject, (typeof(JObject)));
                    foreach (JObject json in ((JArray)jObject["data"]).Children <JObject>())
                    {
                        data.Add(PermisosDto.create(json));
                    }
                }
                response.Data = data;
                return(response);
            }
            catch (Exception e)
            {
                errors.Add(BaseResponseDto.create(Clase, e.Message));
                return(EnumerableResponse <List <PermisosDto> > .create(500, errors));
            }
        }
예제 #2
0
        public async Task <EnumerableResponse <DataTable> > GetConsultaDataTable(string busqueda, string table, string tipo, int page, int limit,
                                                                                 CancellationToken cancellationToken = new CancellationToken())
        {
            var errors = new List <BaseResponseDto>();

            cancellationToken.ThrowIfCancellationRequested();
            try
            {
                var response = await EnumerableResponseDataTable(await Get(string.Format("api/Consulta/GetAll?tabla={0}&tipo={1}&busqueda={2}&page={3}&limit={4}",
                                                                                         table, tipo, busqueda, page, limit)));

                if (response.ErrorCode == 200)
                {
                    dynamic data = (JObject)JsonConvert.DeserializeObject(response.jObject, (typeof(JObject)));
                    response.Data  = (DataTable)JsonConvert.DeserializeObject(data["data"].ToString(), (typeof(DataTable)));
                    response.Count = data["count"] != null?Convert.ToInt32(data["count"].ToString()) : 0;

                    response.Pages = data["pages"] != null?Convert.ToInt32(data["pages"].ToString()) : 0;
                }
                return(response);
            }
            catch (Exception e)
            {
                errors.Add(BaseResponseDto.create(Clase, e.Message));
                return(EnumerableResponse <DataTable> .create(500, errors));
            }
        }
예제 #3
0
        public async Task <EnumerableResponse <TData> > EnumerableResponseDataTable(HttpResponseMessage response)
        {
            var errors = new List <BaseResponseDto>();

            try
            {
                if (response.IsSuccessStatusCode)
                {
                    if (!string.IsNullOrEmpty(await response.Content.ReadAsStringAsync()))
                    {
                        errors.Add(BaseResponseDto.create("", ""));
                        return(EnumerableResponse <TData> .create(200, errors, await response.Content.ReadAsStringAsync()));
                    }
                    if (response.StatusCode.Equals(HttpStatusCode.NoContent))
                    {
                        return(EnumerableResponse <TData> .create(204, errors, null));
                    }
                    return(EnumerableResponse <TData> .create(Convert.ToInt32(response.StatusCode.ToString()),
                                                              errors, null));
                }
                if (response.StatusCode != HttpStatusCode.OK &&
                    response.StatusCode != HttpStatusCode.InternalServerError)
                {
                    if (!string.IsNullOrEmpty(await response.Content.ReadAsStringAsync()))
                    {
                        JObject jObject = JObject.Parse(await response.Content.ReadAsStringAsync());
                        var     values  = VentasService.Util.JObjectExtensions.ToDictionary(jObject);
                        foreach (var error in values)
                        {
                            errors.Add(BaseResponseDto.create(error.Key, error.Value));
                        }
                        return(EnumerableResponse <TData> .create(Convert.ToInt32(response.StatusCode.ToString()), errors));
                    }
                    errors.Add(BaseResponseDto.create(Clase, "Error consultando registro"));
                    return(EnumerableResponse <TData> .create(500, errors));
                }
                errors.Add(BaseResponseDto.create(Clase, "Error no identificado"));
                return(EnumerableResponse <TData> .create(500, errors));
            }
            catch (Exception e)
            {
                errors.Add(BaseResponseDto.create(Clase, e.Message));
                return(EnumerableResponse <TData> .create(500, errors));
            }
        }