Exemplo n.º 1
0
        public async void ActivateInstrument()
        {
            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Warning,
                    Languages.CheckConnection,
                    Languages.Ok);

                return;
            }
            var cookie   = Settings.Cookie; //.Split(11, 33)
            var res      = cookie.Substring(11, 32);
            var response = await apiService.GetAttachmentWithCoockie <Instrument>(
                "https://portalesp.smart-path.it",
                "/Portalesp",
                "/instrument/activate?id=" + Instrument.id,
                res);

            if (!response.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert("Error", response.Message, "ok");

                return;
            }
            await InstrumentViewModel.GetInstance().Activate(Instrument);

            DependencyService.Get <INotification>().CreateNotification("PortalSP", "Instrument Activated");
            await PopupNavigation.Instance.PopAsync(true);
        }
        public async void deactivateInstrument()
        {
            Value = true;
            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Warning,
                    Languages.CheckConnection,
                    Languages.Ok);

                return;
            }
            if (string.IsNullOrEmpty(Reason))
            {
                Value = true;
                return;
            }
            var instrument = new InstrumentDeactivate
            {
                id     = Instrument.id,
                reason = Reason
            };
            var cookie = Settings.Cookie;  //.Split(11, 33)
            var res    = cookie.Substring(11, 32);

            var response = await apiService.Save <InstrumentDeactivate>(
                "https://portalesp.smart-path.it",
                "/Portalesp",
                "/instrument/deactivate",
                res,
                instrument);

            if (!response.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert("Error", response.Message, "ok");

                return;
            }
            await InstrumentViewModel.GetInstance().Activate(Instrument);

            Value = false;
            DependencyService.Get <INotification>().CreateNotification("PortalSP", "Instrument Deactivated");
            await PopupNavigation.Instance.PopAsync(true);
        }
        public async void EditInstrument()
        {
            Value = true;
            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Warning,
                    Languages.CheckConnection,
                    Languages.Ok);

                return;
            }
            if (string.IsNullOrEmpty(Instrument.code) || string.IsNullOrEmpty(Instrument.name))
            {
                Value = true;
                return;
            }
            if (SelectedType == null)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please Select Type", "ok");

                Value = true;
                return;
            }
            var instrument = new InstrumentUpdate
            {
                id          = Instrument.id,
                active      = Instrument.active,
                code        = Instrument.code,
                name        = Instrument.name,
                description = Instrument.description,
                type        = SelectedType.Key,
                createBy    = Instrument.createBy,
                deleteBy    = Instrument.deleteBy,
                //createDate = Room.createDate.ToString(),
                //deleteDate = Room.deleteDate.ToString(),
                deleteReason = Instrument.deleteReason
            };
            var cookie = Settings.Cookie;  //.Split(11, 33)
            var res    = cookie.Substring(11, 32);

            var response = await apiService.Put <InstrumentUpdate>(
                "https://portalesp.smart-path.it",
                "/Portalesp",
                "/instrument/update",
                res,
                instrument);

            Debug.WriteLine("********responseIn ViewModel*************");
            Debug.WriteLine(response);

            /* if (!response.IsSuccess)
             * {
             *   await Application.Current.MainPage.DisplayAlert("Error", response.Message, "ok");
             *   return;
             * }*/
            Value = false;
            InstrumentViewModel.GetInstance().Update(Instrument);

            DependencyService.Get <INotification>().CreateNotification("PortalSP", "Instrument Updated");
            await App.Current.MainPage.Navigation.PopPopupAsync(true);
        }