Ejemplo n.º 1
0
        private async void AddItemAsync()
        {
            var editorPage = new BaseMasterUserEditorPage(false, true);

            BaseMasterUserEditorPageViewModel viewModel = null;

            viewModel = new BaseMasterUserEditorPageViewModel(page: editorPage,
                                                              save: async() =>
            {
                if (!(editorPage.EnglishTranslation || editorPage.ArabicTranslation))
                {
                    await Page.DisplayAlert("Error", "At least one translation language must be selected", "OK");
                    return;
                }

                viewModel.IsBusy = true;

                if ((await DataManager.Default.UserTable.Where(u => u.PhoneNumber == editorPage.PhoneNumber).ToListAsync()).FirstOrDefault() != null)
                {
                    await Page.DisplayAlert("Error", "Phone number is associated with other account", "OK");
                    viewModel.IsBusy = false;
                    return;
                }

                string translationData = String.Empty;

                if (editorPage.EnglishTranslation)
                {
                    translationData += Constants.EnglishTranslationID;
                }
                if (editorPage.ArabicTranslation)
                {
                    translationData += Constants.ArabicTranslationID;
                }

                User user = new User()
                {
                    Username     = editorPage.Username,
                    PhoneNumber  = editorPage.PhoneNumber,
                    Password     = editorPage.Password,
                    MasterUserID = User.Current.ID,
                    UserType     = UserType.Translator,
                    Data         = translationData
                };

                await RegisterAPI.InsertAsync(user);

                viewModel.IsBusy = false;
                Refresh();
                await Page.Navigation.PopModalAsync();
            });

            editorPage.ViewModel = viewModel;


            await Page.Navigation.PushModalAsync(editorPage);
        }
        protected override async void OnItemEditedAsync(object obj)
        {
            User user       = obj as User;
            var  editorPage = new BaseMasterUserEditorPage(true, false);

            editorPage.Username            = user.Username;
            editorPage.PhoneNumber         = user.PhoneNumber;
            editorPage.Password            =
                editorPage.ConfirmPassword = Constants.LocalPassword;

            BaseMasterUserEditorPageViewModel viewModel = null;

            viewModel = new BaseMasterUserEditorPageViewModel(page: editorPage,
                                                              save: async() =>
            {
                viewModel.IsBusy = true;

                var phoneOwner = (await DataManager.Default.UserTable.Where(u => u.PhoneNumber == editorPage.PhoneNumber).ToListAsync()).FirstOrDefault();
                if (phoneOwner != null && phoneOwner.ID != user.ID)
                {
                    await Page.DisplayAlert("Error", "Phone number is associated with other account", "OK");
                    viewModel.IsBusy = false;
                    return;
                }


                user.Username    = editorPage.Username;
                user.PhoneNumber = editorPage.PhoneNumber;
                if (user.Password != Constants.LocalPassword)
                {
                    user.Password = editorPage.Password;//User.EncryptPassword(editorPage.Password);
                }
                user.MasterUserID = (editorPage.Picker.SelectedItem as User).ID;


                await RegisterAPI.UpdateAsync(user);
                viewModel.IsBusy = false;
                Refresh();
                await Page.Navigation.PopModalAsync();
            })
            {
                PickerOptions = await DataManager.Default.UserTable.Where(u => u.UserType == UserType.Moderator).ToListAsync()
            };

            var moderator = ((List <User>)viewModel.PickerOptions).Where(u => u.ID == user.MasterUserID).Take(1).ToList().FirstOrDefault();

            if (moderator != null)
            {
                viewModel.PickerSelectedIndex = viewModel.PickerOptions.IndexOf(moderator);
            }

            editorPage.ViewModel = viewModel;
            await Page.Navigation.PushModalAsync(editorPage);
        }
        protected override async void OnItemEditedAsync(object obj)
        {
            {
                User user       = obj as User;
                var  editorPage = new BaseMasterUserEditorPage(false, false);

                editorPage.Username            = user.Username;
                editorPage.PhoneNumber         = user.PhoneNumber;
                editorPage.Password            =
                    editorPage.ConfirmPassword = Constants.LocalPassword;

                BaseMasterUserEditorPageViewModel viewModel = null;
                viewModel = new BaseMasterUserEditorPageViewModel(page: editorPage,
                                                                  save: async() =>
                {
                    viewModel.IsBusy = true;
                    var phoneOwner   = (await DataManager.Default.UserTable.Where(u => u.PhoneNumber == editorPage.PhoneNumber).ToListAsync()).FirstOrDefault();
                    if (phoneOwner != null && phoneOwner.ID != user.ID)
                    {
                        await Page.DisplayAlert("Error", "Phone number is associated with other account", "OK");
                        viewModel.IsBusy = false;
                        return;
                    }


                    user.Username    = editorPage.Username;
                    user.PhoneNumber = editorPage.PhoneNumber;
                    if (user.Password != Constants.LocalPassword)
                    {
                        user.Password = editorPage.Password;//User.EncryptPassword(editorPage.Password);
                    }
                    await RegisterAPI.UpdateAsync(user);
                    viewModel.IsBusy = false;
                    //Refresh();
                    await Page.Navigation.PopModalAsync();
                });

                editorPage.ViewModel = viewModel;


                await Page.Navigation.PushModalAsync(editorPage);
            }
        }
        protected async void AddItemAsync()
        {
            var editorPage = new BaseMasterUserEditorPage(true, false);
            BaseMasterUserEditorPageViewModel viewModel = null;

            viewModel = new BaseMasterUserEditorPageViewModel(page: editorPage,
                                                              save: async() =>
            {
                viewModel.IsBusy = true;

                if ((await DataManager.Default.UserTable.Where(u => u.PhoneNumber == editorPage.PhoneNumber).ToListAsync()).FirstOrDefault() != null)
                {
                    await Page.DisplayAlert("Error", "Phone number is associated with other account", "OK");
                    viewModel.IsBusy = false;
                    return;
                }

                User user = new User()
                {
                    Username     = editorPage.Username,
                    PhoneNumber  = editorPage.PhoneNumber,
                    Password     = editorPage.Password,
                    MasterUserID = (editorPage.Picker.SelectedItem as User).ID,
                    UserType     = UserType.Salesman,
                    Data         = String.Empty
                };

                await RegisterAPI.InsertAsync(user);

                viewModel.IsBusy = false;
                Refresh();
                await Page.Navigation.PopModalAsync();
            })
            {
                PickerOptions = await DataManager.Default.UserTable.Where(u => u.UserType == UserType.Moderator).ToListAsync()
            };
            editorPage.ViewModel = viewModel;


            await Page.Navigation.PushModalAsync(editorPage);
        }
Ejemplo n.º 5
0
        protected override async void OnItemEditedAsync(object obj)
        {
            User user       = obj as User;
            var  editorPage = new BaseMasterUserEditorPage(false, true);

            editorPage.Username            = user.Username;
            editorPage.PhoneNumber         = user.PhoneNumber;
            editorPage.Password            =
                editorPage.ConfirmPassword = Constants.LocalPassword;
            editorPage.EnglishTranslation  = user.Data.Contains(Constants.EnglishTranslationID);
            editorPage.ArabicTranslation   = user.Data.Contains(Constants.ArabicTranslationID);

            BaseMasterUserEditorPageViewModel viewModel = null;

            viewModel = new BaseMasterUserEditorPageViewModel(page: editorPage,
                                                              save: async() =>
            {
                if (!(editorPage.EnglishTranslation || editorPage.ArabicTranslation))
                {
                    await Page.DisplayAlert("Error", "At least one translation language must be selected", "OK");
                    return;
                }

                viewModel.IsBusy = true;

                var phoneOwner = (await DataManager.Default.UserTable.Where(u => u.PhoneNumber == editorPage.PhoneNumber).ToListAsync()).FirstOrDefault();
                if (phoneOwner != null && phoneOwner.ID != user.ID)
                {
                    await Page.DisplayAlert("Error", "Phone number is associated with other account", "OK");
                    viewModel.IsBusy = false;
                    return;
                }

                string translationData = String.Empty;

                if (editorPage.EnglishTranslation)
                {
                    translationData += Constants.EnglishTranslationID;
                }
                if (editorPage.ArabicTranslation)
                {
                    translationData += Constants.ArabicTranslationID;
                }


                user.Username    = editorPage.Username;
                user.PhoneNumber = editorPage.PhoneNumber;
                if (user.Password != Constants.LocalPassword)
                {
                    user.Password = editorPage.Password;//User.EncryptPassword(editorPage.Password);
                }
                user.Data = translationData;



                await RegisterAPI.UpdateAsync(user);
                viewModel.IsBusy = false;
                //Refresh();
                await Page.Navigation.PopModalAsync();
            });

            editorPage.ViewModel = viewModel;


            await Page.Navigation.PushModalAsync(editorPage);
        }