Exemplo n.º 1
0
        public NewGroupViewModel(INavigationService navigationService, IPageDialogService dialogService)
            : base(navigationService, dialogService)
        {
            Group = new GroupItem
            {
                Id            = null,
                CreatedUserId = GlobalAttributes.User.Id,
                GroupName     = null,
            };
            // Init and add yourself.
            var myself = new GroupUserItem()
            {
                RefGroupId = Group.Id
                ,
                RefUser = GlobalAttributes.User
                ,
                RefUserId = GlobalAttributes.User.Id
                ,
                AdminFlg = true
            };

            Task.Run(() => Service.ImageService.SetImageSource(myself.RefUser));
            GroupUserItems = new ObservableCollection <GroupUserItem> {
                myself
            };
            NewGroupUser = new GroupUserItem();

            ImageSelectCommand = new DelegateCommand(imageSelect);
            SubmitCommand      = new DelegateCommand(submitGroup);
            AddUserCommand     = new DelegateCommand(addUser);
            DeleteCommand      = new DelegateCommand <GroupUserItem>(deleteUser);
            AuthPicker         = Constants.AuthPicker.Select(x => x.Label).ToList();
        }
Exemplo n.º 2
0
        protected async void deleteUser(GroupUserItem item)
        {
            string message = this.getErrorMessageDeleteGroupUser(item);

            if (message != null)
            {
                await dialogService.DisplayAlertAsync
                (
                    "Error",
                    message,
                    "Confirm"
                );

                return;
            }
            var accepted = await dialogService.DisplayAlertAsync
                           (
                "Confirmation",
                $"Do you want to remove group user '{item.RefUser.NameAndEmail}'?",
                "Confirm",
                "Cancel"
                           );

            if (accepted)
            {
                this.GroupUserItems.Remove(item);
            }
        }
Exemplo n.º 3
0
        public BaseGroupViewModel(INavigationService navigationService, IPageDialogService dialogService)
            : base(navigationService, dialogService)
        {
            Group          = new GroupItem();
            GroupUserItems = new ObservableCollection <GroupUserItem> ();
            NewGroupUser   = new GroupUserItem();

            ImageSelectCommand = new DelegateCommand(imageSelect);
            SubmitCommand      = new DelegateCommand(submitGroup);
            AddUserCommand     = new DelegateCommand(addUser);
            DeleteCommand      = new DelegateCommand <GroupUserItem>(deleteUser);
            AuthPicker         = Constants.AuthPicker.Select(x => x.Label).ToList();
        }
Exemplo n.º 4
0
        protected async void addUser()
        {
            if (!GlobalAttributes.IsConnectedInternet)
            {
                await dialogService.DisplayAlertAsync("Error", "This feature only available with network access!", "OK");

                return;
            }

            UserItem user    = null;
            string   message = this.getErrorMessageGroupUser();

            if (message == null)
            {
                user = await getUserByEmail();

                message = "The Email address you entered does not exist in accounts";
            }
            if (user != null)
            {
                var groupUser = new GroupUserItem()
                {
                    RefUser = user
                    ,
                    RefUserId = user.Id
                };
                this.GroupUserItems.Add(groupUser);
                // read user image
                await Service.ImageService.SetImageSource(groupUser.RefUser);

                this.NewGroupUser = new GroupUserItem();
            }
            else
            {
                await dialogService.DisplayAlertAsync
                (
                    "Error",
                    message,
                    "OK"
                );

                //this.NewGroupUser.RefUser.Email = null;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// valid and get error message before delete user.
        /// </summary>
        /// <returns></returns>
        protected string getErrorMessageDeleteGroupUser(GroupUserItem item)
        {
            // cannot delete userself.
            if (item.Id == GlobalAttributes.User.Id)
            {
                return("Cannot delete yourself.");
            }
            //cannot delete last 1.
            if (this.GroupUserItems.Count == 1)
            {
                return("Cannot delete last group user.");
            }
            //cannot delete last admin user.
            if (item.AdminFlg && this.GroupUserItems.Where(x => x.AdminFlg).Count() == 1)
            {
                return("Cannot delete last admin user.");
            }

            return(null);
        }