Example #1
0
 private CantvItemViewModel ToCantvItemViewModel(
     CantvDataItem _cantvDataItem)
 {
     return(new CantvItemViewModel
     {
         CantvDataId = _cantvDataItem.CantvDataId,
         CodePhone = _cantvDataItem.CodePhone,
         NumberPhone = _cantvDataItem.NumberPhone,
     });
 }
Example #2
0
        private async void Save()
        {
            var response = MethodsHelper.IsValidField(
                "I",
                3,
                3,
                "code phone",
                this.CodePhone,
                true,
                false,
                string.Empty);

            if (!response.IsSuccess)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "I",
                7,
                7,
                "number phone",
                this.NuberPhone,
                true,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Define control format
            this.SetStatusControl(false, true, 1);

            response = await apiservices.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Define control format
                this.SetStatusControl(true, false, 0);

                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            var cantvData = new CantvDataItem
            {
                CodePhone   = this.CodePhone,
                NumberPhone = this.NuberPhone,
                UserId      = mainViewModel.UserData.UserId,
            };

            //  Save the data CatvData
            response = await apiservices.Post <CantvDataItem>(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/CantvDatas",
                mainViewModel.Token.TokenType,
                mainViewModel.Token.AccessToken,
                cantvData);

            if (!response.IsSuccess)
            {
                //  Define control format
                SetStatusControl(true, false, 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Add new record
            cantvData.CantvDataId = ((CantvData)response.Result).CantvDataId;
            cantvViewModel.UpdateCantvData(
                1,
                this.ToCantvItemViewModel(cantvData));

            //  Define control format
            this.SetStatusControl(true, false, 0);

            //  Navigate to back
            await this.navigationService.GoBackOnMaster();
        }
        private async void Delete()
        {
            //  Validate if delete the record
            if (await this.dialogService.ShowMessageConfirm(
                    "Informtion",
                    "Are you sure delete this record...?",
                    "Yes",
                    "No"))
            {
                //  Validate connection to internet
                var response = await this.apiService.CheckConnection();

                if (!response.IsSuccess)
                {
                    await this.dialogService.ShowMessage(
                        "Error",
                        response.Message,
                        "Accept");

                    return;
                }

                //  Generate an object CantvDatas
                var cantvData = new CantvDataItem
                {
                    CantvDataId = this.CantvDataId,
                    CodePhone   = this.CodePhone,
                    NumberPhone = this.NumberPhone,
                    UserId      = this.mainViewModel.UserData.UserId,
                };

                response = await this.apiService.Delete <CantvDataItem>(
                    MethodsHelper.GetUrlAPI(),
                    "/api",
                    "/CantvDatas",
                    this.mainViewModel.Token.TokenType,
                    this.mainViewModel.Token.AccessToken,
                    cantvData);

                if (!response.IsSuccess)
                {
                    await this.dialogService.ShowMessage(
                        "Error",
                        response.Message,
                        "Accept");

                    return;
                }

                //  Invokate the method that removes a CantvDatas
                cantvData.UserId = 0;
                this.cantvViewModel.UpdateCantvData(
                    -1,
                    this.ToCantvItemViewModel(cantvData));

                await this.dialogService.ShowMessage(
                    "Information",
                    string.Format(
                        "Record: {0} remove successfully...!!!",
                        cantvData.GetFullCantvData),
                    "Accept");
            }
        }