public async Task <PaginaDto> GuardarPagina(PaginaDto pagina, string authToken = null, CancellationToken cancellationToken = new CancellationToken())
        {
            cancellationToken.ThrowIfCancellationRequested();
            try
            {
                var response = await ApiClient.Post("api/Pagina/Create", pagina, cancellationToken);

                var errors = new List <BaseErrorDto>();
                if (response.IsSuccessStatusCode)
                {
                    JObject jObject = JObject.Parse(await response.Content.ReadAsStringAsync());
                    errors.Add(BaseErrorDto.create("Pagina", "Registro almacenado exitosamente"));
                    return(PaginaDto.create(PaginaDto.create(jObject), errors, 200));
                }
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    JObject jObject = JObject.Parse(await response.Content.ReadAsStringAsync());
                    var     values  = VentasService.Util.JObjectExtensions.ToDictionary(jObject);
                    foreach (var error in values)
                    {
                        errors.Add(BaseErrorDto.create(error.Key, error.Value));
                    }
                    return(PaginaDto.create(errors, response.StatusCode));
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(null);
        }
        public async Task <UsuarioDto> Login(string username, string password,
                                             CancellationToken cancellationToken = new CancellationToken())
        {
            cancellationToken.ThrowIfCancellationRequested();
            var errors = new List <BaseErrorDto>();

            try
            {
                var response = await ApiClient.Post("api/Auth/login", new { username = username, password = password });

                if (response.IsSuccessStatusCode)
                {
                    if (!string.IsNullOrEmpty(await response.Content.ReadAsStringAsync()))
                    {
                        JObject jObject = JObject.Parse(await response.Content.ReadAsStringAsync());
                        var     user    = (JObject)jObject["user"];
                        errors.Add(BaseErrorDto.create("Usuario", ""));
                        return(UsuarioDto.create(UsuarioDto.create((JObject)user["data"]), errors, 200));
                    }
                    return(UsuarioDto.create(UsuarioDto.create(), errors, Convert.ToInt32(response.StatusCode.ToString())));
                }
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    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(BaseErrorDto.create(error.Key, error.Value));
                        }
                        return(UsuarioDto.create(errors, 400));
                    }
                    errors.Add(BaseErrorDto.create("Usuario", "Error consultando registro"));
                    return(UsuarioDto.create(errors, 500));
                }
            }
            catch (UriFormatException er)
            {
                errors.Add(BaseErrorDto.create("Usuario", er.Message));
                return(UsuarioDto.create(errors, 500));
            }
            catch (Exception e)
            {
                errors.Add(BaseErrorDto.create("Usuario", e.Message));
                return(UsuarioDto.create(errors, 500));
            }
            return(null);
        }
        public async Task <PaginaDto> GetPagina(int id, string authToken = null, CancellationToken cancellationToken = new CancellationToken())
        {
            cancellationToken.ThrowIfCancellationRequested();
            var errors = new List <BaseErrorDto>();

            try
            {
                HttpResponseMessage response = await ApiClient.Get(string.Format("api/Pagina/Get?id={0}", id), cancellationToken);

                if (response.IsSuccessStatusCode)
                {
                    if (!string.IsNullOrEmpty(await response.Content.ReadAsStringAsync()))
                    {
                        JObject jObject = JObject.Parse(await response.Content.ReadAsStringAsync());
                        errors.Add(BaseErrorDto.create("Pagina", ""));
                        return(PaginaDto.create(PaginaDto.create(jObject), errors, 200));
                    }
                    if (response.StatusCode.Equals(HttpStatusCode.NoContent))
                    {
                        return(PaginaDto.create(PaginaDto.create(), errors, Convert.ToInt32(204)));
                    }
                    return(PaginaDto.create(PaginaDto.create(), errors, Convert.ToInt32(response.StatusCode.ToString())));
                }
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    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(BaseErrorDto.create(error.Key, error.Value));
                        }
                        return(PaginaDto.create(errors, Convert.ToInt32(response.StatusCode.ToString())));
                    }
                    errors.Add(BaseErrorDto.create("Pagina", "Error consultando registro"));
                    return(PaginaDto.create(errors, 500));
                }
            }
            catch (Exception e)
            {
                errors.Add(BaseErrorDto.create("Pagina", e.Message));
                return(PaginaDto.create(errors, 500));
            }
            return(null);
        }
        public async Task <PaginaDto> Delete(int id,
                                             CancellationToken cancellationToken = new CancellationToken())
        {
            cancellationToken.ThrowIfCancellationRequested();
            var errors = new List <BaseErrorDto>();

            try
            {
                var dyn = new { Id = id };
                HttpResponseMessage response = await ApiClient.Delete("api/Pagina/Delete", dyn);

                if (response.IsSuccessStatusCode)
                {
                    if (!string.IsNullOrEmpty(await response.Content.ReadAsStringAsync()))
                    {
                        JObject jObject = JObject.Parse(await response.Content.ReadAsStringAsync());
                        errors.Add(BaseErrorDto.create("Pagina", "Registro eliminado exitosamente"));
                        return(PaginaDto.create(PaginaDto.create(jObject), errors, 200));
                    }
                    return(PaginaDto.create(PaginaDto.create(), errors, Convert.ToInt32(response.StatusCode.ToString())));
                }
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    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(BaseErrorDto.create(error.Key, error.Value));
                        }
                        return(PaginaDto.create(errors, 400));
                    }
                }
                errors.Add(BaseErrorDto.create("Pagina", "Error Eliminando registro"));
                return(PaginaDto.create(errors, 500));
            }
            catch (Exception e)
            {
                errors.Add(BaseErrorDto.create("Pagina", e.Message));
                return(PaginaDto.create(errors, 500));
            }
        }