Example #1
0
        public async Task <Response> RegisterDevice(WSDevice WSDevice)
        {
            Response response = new Response();

            if (XPlatform.IsThereInternet)
            {
                response = await WSMethods.Post(Constants.Url_Devices, WSDevice);

                return(response);
            }
            else
            {
                response.Result = Result.NETWORK_UNAVAILABLE;
            }
            return(response);
        }
Example #2
0
        private async void RegisterDevice()
        {
            await Alerts.ShowLoadingPageAsync("Registrando dispositivo");


            tblUsersDTO User     = App.CurrentUser;
            WSDevice    WSDevice = new WSDevice();

            WSDevice.Name         = string.Format("{0}_{1}", User.Name, App.GetDeviceName());
            WSDevice.Code         = User.Code;
            WSDevice.DeviceTypeID = App.GetDeviceTypeID();
            WSDevice.AppVersion   = App.GetAppVersion();
            WSDevice.Model        = App.GetDeviceName();
            WSDevice.OSVersion    = App.GetOSVersion();

            Response response = await DevicesService.RegisterDevice(WSDevice);

            if (response.Result != Result.NETWORK_UNAVAILABLE)
            {
                if (response.Result == Result.ERROR_GETTING_DATA)
                {
                    await Alerts.HideLoadingPageAsync();

                    Alerts.ShowAlert(string.Empty, "Error al obtener datos del servidor");
                }
                else if (response.Result == Result.SERVICE_EXCEPTION)
                {
                    await Alerts.HideLoadingPageAsync();

                    Alerts.ShowAlert(string.Empty, "Error al obtener datos del dispositivo (SE)");
                }
                else if (response.Result == Result.OK)
                {
                    if (!string.IsNullOrEmpty(response.Data))
                    {
                        response.Data = response.Data.NormalizeResponse();
                        if (response.Data == Constants.Error_Code)
                        {
                            await Alerts.HideLoadingPageAsync();

                            Alerts.ShowAlert(string.Empty, response.Data);
                            return;
                        }

                        await Alerts.HideLoadingPageAsync();

                        User.DeviceID = int.Parse(response.Data);
                        App.UsersB.Update(User);

                        App.Current.MainPage = new Confirmation();
                    }
                    else
                    {
                        await Alerts.HideLoadingPageAsync();

                        Alerts.ShowAlert(string.Empty, "Error al obtener datos del dispositivo.");
                    }
                }
            }
            else
            {
                await Alerts.HideLoadingPageAsync();

                Alerts.ShowNetworkError();
            }
        }