示例#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_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));
     }
 }
示例#3
0
 private void DataService_OnPostFailed(object sender, FailEventArgs e)
 {
     OnGetDeviceFailed?.Invoke(this, new FailEventArgs(e.MethodError, e.ErrorMessage));
 }