示例#1
0
        public override void OnClick(View view)
        {
            var viewHolder = view.Tag as ViewHolders.RoleViewHolder;

            if (view.Id == Resource.Id.RoleRowItemDelete)
            {
                Task.Run(async() =>
                {
                    var item   = _adapter.GetItem(viewHolder.AdapterPosition);
                    var result = await RoleService.DeleteRole(item.Id);

                    if (result.Error.Any())
                    {
                        if (result.Error.ContainsKey("UserRoles"))
                        {
                            RunOnUiThread(() =>
                            {
                                ShowToastMessage(Resource.String.UsersAssignedToRole);
                            });

                            return;
                        }

                        RunOnUiThread(() =>
                        {
                            ShowToastMessage(Resource.String.ErrorOccurred);
                        });

                        return;
                    }

                    RunOnUiThread(() =>
                    {
                        _adapter.RemoveItem(item);
                    });
                });
            }
            if (view.Id == Resource.Id.RoleRowItemEdit)
            {
                var item = _adapter.GetItem(viewHolder.AdapterPosition);
                NavigationManager.GoToEditRole(item);
            }
            if (view.Id == Resource.Id.RoleRowItemInfo)
            {
                var item = _adapter.GetItem(viewHolder.AdapterPosition);
                NavigationManager.GoToRoleDetails(item);
            }
            if (view.Id == AddItemFloatActionButton.Id)
            {
                NavigationManager.GoToAddRole();
            }
        }