コード例 #1
0
    private void InitializeFieldVariables()
    {
        if (ResourceId != Guid.Empty)
        {
            isEditMode = true;
            ButtonSimilarMatch.Visible     = false;
            resourceProperties.ControlMode = ResourcePropertiesOperationMode.Edit;
            resourceProperties.ResourceId  = ResourceId;
        }
        else
        {
            resourceProperties.ControlMode = ResourcePropertiesOperationMode.Add;
            using (ResourceDataAccess dataAccess = new ResourceDataAccess())
            {
                ResourceType resTypeObj = dataAccess.GetResourceType(typeName);

                if (resTypeObj != null)
                {
                    resourceProperties.ResourceType = resTypeObj.Name;
                }
                else
                {
                    HideResourcePropertyControl(Resources.Resources.InvalidResourceType);
                    return;
                }
            }
        }

        // Handle scenario which is "a resource deleted by one user and another user operating on the resource".
        using (ResourceDataAccess resDataAccess = new ResourceDataAccess())
        {
            if (isEditMode)
            {
                Resource resource = resDataAccess.GetResource(ResourceId);

                if (resource == null)
                {
                    this.HideResourcePropertyControl(Resources.Resources.ResourceNotFound);
                    this._isResourceExist = false;
                    return;
                }

                typeName   = resource.GetType().Name;
                Page.Title = Resources.Resources.Edit + Blank_Space + Utility.FitString(Utility.UpdateEmptyTitle(resource.Title),
                                                                                        _titleLength) + "(" + typeName + ")";
            }
            else
            {
                Page.Title = Resources.Resources.Create + Blank_Space + Utility.FitString(typeName, _titleLength);
            }
        }

        resourceProperties.ResourceType = typeName;
        resourceProperties.Title        = string.Format(CultureInfo.InvariantCulture,
                                                        Resources.Resources.ResourceLabelResourcePropertiesText, typeName);
        resourceProperties.ValidationRequired = true;
        ButtonSimilarMatch.ValidationGroup    = _createResourceValidationGroup;
        SubmitButton.ValidationGroup          = _createResourceValidationGroup;
        resourceProperties.ValidationGroup    = _createResourceValidationGroup;
    }
コード例 #2
0
    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);
    }