Пример #1
0
        private async void DataService_OnGetSuccessfull(object sender, DataServiceEventArgs e)
        {
            try
            {
                HttpResponseMessage result = e.Result;
                string json   = result.Content.ReadAsStringAsync().Result;
                long   dispId = JsonConvert.DeserializeObject <long>(json);

                DispositivoModel dispositivo = DependencyService.Get <IDeviceManager>().GetDeviceData();

                if (dispId != 0)
                {
                    dispositivo.Id = dispId;
                    OnGetDeviceSuccesfull?.Invoke(this, dispositivo);
                }
                else
                {
                    dispositivo.FechaRegistro = DateTime.Now;
                    dispositivo.UserId        = App.UserInfo.Id;
                    string serDataDisp      = JsonConvert.SerializeObject(dispositivo);
                    string addDispositvoURL = $"{App.ApiUrl}api/device/addDevice";

                    await dataService.PostDataAsync(addDispositvoURL, serDataDisp, e.ParentMethodName);
                }
            }
            catch (Exception ex)
            {
                OnGetDeviceFailed?.Invoke(this, new FailEventArgs(e.ParentMethodName, ex.Message));
            }
        }
Пример #2
0
        private void DataService_OnGetSuccessfull(object sender, DataServiceEventArgs e)
        {
            HttpResponseMessage result        = e.Result;
            Task <string>       resultContent = result.Content.ReadAsStringAsync();
            UserModel           userModel     = JsonConvert.DeserializeObject <UserModel>(resultContent.Result);

            OnGetDataUserSuccessfull?.Invoke(this, new DataUserEventArgs(userModel, e.ParentMethodName));
        }
Пример #3
0
 private void DataService_OnPostSuccessfull(object sender, DataServiceEventArgs e)
 {
     try
     {
         string           json        = e.Result.Content.ReadAsStringAsync().Result;
         DispositivoModel dispositivo = JsonConvert.DeserializeObject <DispositivoModel>(json);
         OnGetDeviceSuccesfull?.Invoke(this, dispositivo);
     }
     catch (Exception ex)
     {
         OnGetDeviceFailed?.Invoke(this, new FailEventArgs(e.ParentMethodName, ex.Message));
     }
 }
Пример #4
0
        private void DataService_OnPostSuccessfull(object sender, DataServiceEventArgs e)
        {
            HttpResponseMessage result        = e.Result;
            Task <string>       resultContent = result.Content.ReadAsStringAsync();
            TokenModel          token         = JsonConvert.DeserializeObject <TokenModel>(resultContent.Result);

            if (token.Expires_In == 0)
            {
                OnAutenticationFailed?.Invoke(this, new FailEventArgs(e.ParentMethodName, "Verifique sus credenciales"));
                return;
            }

            OnAuthenticatedSuccesfull?.Invoke(this, new AuthenticateEventArgs(true, token, e.ParentMethodName));
        }
Пример #5
0
        private async void DataService_OnGetSuccessfull(object sender, DataServiceEventArgs e)
        {
            string json = string.Empty;

            switch (e.ParentMethodName)
            {
            case "GetCompanies":
                List <EmpresaModel> empresas = new List <EmpresaModel>();

                if (e.Result.IsSuccessStatusCode)
                {
                    json = await e.Result.Content.ReadAsStringAsync().ConfigureAwait(false);

                    empresas = JsonConvert.DeserializeObject <List <EmpresaModel> >(json);
                }
                OnGetCompanySuccessful?.Invoke(this, empresas);
                break;

            case "GetModules":
                List <ModuloModel> modulos = new List <ModuloModel>();

                if (e.Result.IsSuccessStatusCode)
                {
                    json = await e.Result.Content.ReadAsStringAsync().ConfigureAwait(false);

                    modulos = JsonConvert.DeserializeObject <List <ModuloModel> >(json);
                }
                OnGetModuleSuccessful?.Invoke(this, modulos);
                break;

            case "GetDocuments":
                List <DocumentoModel> documents = new List <DocumentoModel>();
                if (e.Result.IsSuccessStatusCode)
                {
                    json      = e.Result.Content.ReadAsStringAsync().Result;
                    documents = JsonConvert.DeserializeObject <List <DocumentoModel> >(json);
                }
                OnGetDocumentsSuccessful?.Invoke(this, documents);
                break;
            }
        }