private void Validate() { if (resourceId == Guid.Empty) { lblErrorOrMessage.Text = Resources.Resources.ResourceNotFound; lblErrorOrMessage.Visible = true; } using (ResourceDataAccess dataAccess = new ResourceDataAccess()) { if (!this.IsPostBack && !dataAccess.IsOwner(userToken, resourceId) && !dataAccess.IsAdmin(userToken)) { throw new UnauthorizedAccessException(Resources.Resources.MsgUnAuthorizeAccessOwner); } } }
private void Initialize() { ResourceType type = null; IEnumerable <NavigationProperty> propertyCollection = null; ResourcePermissions <Resource> userPermissions = null; bool isAdmin = false; bool isOwner = false; using (ResourceDataAccess dataAccess = new ResourceDataAccess()) { if (IsEditMode) { AuthenticatedToken token = Session[Constants.AuthenticationTokenKey] as AuthenticatedToken; userPermissions = dataAccess.GetResourcePermissions(token, ResourceId); //Throw exception is user is not having atleast read permission on the resource. if (userPermissions == null || !userPermissions.Permissions.Contains(UserResourcePermissions.Read)) { throw new UnauthorizedAccessException(string.Format(CultureInfo.InvariantCulture, Resources.Resources.MsgUnAuthorizeAccess, UserResourcePermissions.Read)); } isAdmin = dataAccess.IsAdmin(token); isOwner = dataAccess.IsOwner(token, userPermissions.Resource); type = dataAccess.GetResourceType(ResourceId); propertyCollection = dataAccess.GetNavigationProperties(Cache, ResourceId); } else { string resType = Convert.ToString(Request.QueryString[_resourceTypeKey]); if (!string.IsNullOrEmpty(resType)) { type = dataAccess.GetResourceType(resType); } } } if (type != null) { SelectedResourceType = type.Name; } UpdateControlsStatus(propertyCollection, userPermissions, isAdmin, isOwner); }