Beispiel #1
0
        void ResourceListView_OnDeleteButtonClicked(object sender, DeleteEventArgs e)
        {
            if (e.EntityIdList != null && e.EntityIdList.Count > 0)
            {
                using (ResourceDataAccess resourceDAL = new ResourceDataAccess(this.CreateContext()))
                {
                    if (IsSecurityAwareControl)
                    {
                        Collection <Guid> resourceIdsToBeDeleted = new Collection <Guid>();

                        foreach (Guid resId in e.EntityIdList.ToList())
                        {
                            Resource resource = resourceDAL.GetResource(resId);

                            if (resource != null)
                            {
                                resourceIdsToBeDeleted.Add(resource.Id);
                                CategoryNode categoryNodeobject = resource as CategoryNode;

                                bool isCategoryNode = false;
                                if (categoryNodeobject != null)
                                {
                                    isCategoryNode = true;
                                }

                                if (IsSecurityAwareControl && AuthenticatedToken != null)
                                {
                                    bool isAuthorized = isCategoryNode ?
                                                        resourceDAL.AuthorizeUserForDeletePermissionOnCategory(AuthenticatedToken, resId) :
                                                        resourceDAL.AuthorizeUser(AuthenticatedToken, UserResourcePermissions.Delete, resId);

                                    if (!isAuthorized)
                                    {
                                        if (isCategoryNode)
                                        {
                                            throw new UnauthorizedAccessException(GlobalResource.UnauthorizedAccessExceptionCategoryDelete);
                                        }
                                        else
                                        {
                                            throw new UnauthorizedAccessException(string.Format(CultureInfo.InvariantCulture,
                                                                                                GlobalResource.UnauthorizedAccessException, UserResourcePermissions.Delete));
                                        }
                                    }
                                }

                                if (isCategoryNode)
                                {
                                    UpdateEntityListWithCategoryNodes(categoryNodeobject, resourceIdsToBeDeleted);
                                }
                            }
                        }

                        resourceDAL.DeleteResources(resourceIdsToBeDeleted);
                    }
                }

                //Refresh data source for current page.
                Refresh();

                //If page count is changed and Data fetched is empty then try to fetch last page
                IList entityList = ResourceListView.DataSource as IList;
                if ((entityList == null || entityList.Count == 0) && ResourceListView.TotalRecords > 0)
                {
                    ResourceListView.PageIndex = Convert.ToInt32(Math.Ceiling((double)ResourceListView.TotalRecords / ResourceListView.PageSize)) - 1;
                    Refresh();
                }
            }
        }