Exemple #1
0
    /// <summary>
    /// Manage the group information section while updating group information.
    /// </summary>
    private void ManageGroupSection()
    {
        if (!string.IsNullOrEmpty(Id))
        {
            txtGroupName.Enabled = false;
            using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
            {
                //Populate group info on UI
                Group groupObject = (Group)dataAccess.GetResource(new Guid(Id));

                if (groupObject == null)
                {
                    return;
                }

                groupInformation = dataAccess.GetGroup(groupObject.GroupName);

                if (!Page.IsPostBack)
                {
                    txtTitle.Text       = groupInformation.Title;
                    txtGroupName.Text   = groupInformation.GroupName;
                    txtDescription.Text = groupInformation.Description;
                    txtUri.Text         = groupInformation.Uri;
                }
            }
        }
    }
    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;
    }
Exemple #3
0
    private bool IsValidResourceId(Guid resourceId)
    {
        Resource resourceObj = null;

        using (ResourceDataAccess dataAccess = new ResourceDataAccess())
        {
            resourceObj = dataAccess.GetResource(resourceId);
        }

        return(resourceObj != null);
    }
    /// <summary>
    /// Delete given resource from database.
    /// </summary>
    /// <param name="sender">sender</param>
    /// <param name="e">Event Args</param>
    protected void DeleteButton_OnClick(object sender, EventArgs e)
    {
        using (ResourceDataAccess dataAccess = new ResourceDataAccess())
        {
            if (ResourceDetailView.ResourceId != Guid.Empty)
            {
                Resource resource     = dataAccess.GetResource(ResourceDetailView.ResourceId);
                bool     isAuthorized = resource is CategoryNode?
                                        dataAccess.AuthorizeUserForDeletePermissionOnCategory(ResourceDetailView.AuthenticatedToken, resource.Id) :
                                            dataAccess.AuthorizeUser(ResourceDetailView.AuthenticatedToken, UserResourcePermissions.Delete, resource.Id);

                if (isAuthorized)
                {
                    bool isDeleted = resource is CategoryNode?
                                     dataAccess.DeleteCategoryNodeWithHierarchy(ResourceDetailView.ResourceId) :
                                         dataAccess.DeleteResource(ResourceDetailView.ResourceId);

                    //Delete resource
                    if (isDeleted)
                    {
                        DeleteButton.Visible       = false;
                        ResourceDetailView.Visible = false;
                        //Show Delete successful message
                        MessageLabel.ForeColor = System.Drawing.Color.Black;
                        MessageLabel.Text      = Resources.Resources.AlertRecordDelerted;
                        if (OnSuccessfulDelete != null)
                        {
                            OnSuccessfulDelete(this, new EventArgs());
                        }
                    }
                    else
                    {
                        //Show delete failure message
                        MessageLabel.ForeColor = System.Drawing.Color.Red;
                        MessageLabel.Text      = Resources.Resources.AlertResourceDelertedError;
                    }
                }
                else
                {
                    //Show delete failure message
                    MessageLabel.ForeColor = System.Drawing.Color.Red;
                    if (resource is CategoryNode)
                    {
                        MessageLabel.Text = Resources.Resources.MsgUnauthorizeAccessDeleteCategory;
                    }
                    else
                    {
                        MessageLabel.Text = string.Format(CultureInfo.InvariantCulture, Resources.Resources.MsgUnAuthorizeAccess,
                                                          UserResourcePermissions.Delete);
                    }
                }
            }
        }
    }
Exemple #5
0
    /// <summary>
    /// Initialized the user assignment user control.
    /// </summary>
    private void InitializeControls()
    {
        Group group = null;

        if (!Page.IsPostBack)
        {
            groupAssignment.ClearGroupList();
        }

        groupAssignment.ControlMode      = UserControls_GroupAssignment.RoleType.User;
        groupAssignment.UserSearchButton = Resources.Resources.ButtonSearchText;

        if (!string.IsNullOrEmpty(Id))
        {
            using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
            {
                group = (Group)dataAccess.GetResource(new Guid(Id));

                if (group == null)
                {
                    return;
                }
                group.Identities.Load();
                if (group.Identities != null)
                {
                    groupAssignment.SelectedIdentityList = group.Identities.ToList();
                }
            }
        }

        if (!string.IsNullOrEmpty(Id))
        {
            if (group.GroupName == UserManager.AllUsersGroupName)
            {
                groupInfoPanel.Enabled   = false;
                groupAssignment.IsEnable = false;
                groupAssignment.SelectedUserOrGroupType = UserControls_GroupAssignment.SelectedType.AllUsersGroupName;
            }
            else if (group.GroupName == UserManager.AdminGroupName)
            {
                groupInfoPanel.Enabled   = false;
                groupAssignment.IsEnable = true;
                groupAssignment.SelectedUserOrGroupType = UserControls_GroupAssignment.SelectedType.AdminGroupName;
            }
        }
        else
        {
            groupInfoPanel.Enabled   = true;
            groupAssignment.IsEnable = true;
        }

        Utility.ShowMessage(lblMessage, string.Empty, false);
    }
Exemple #6
0
        /// <summary>
        /// Gets the subject entity.
        /// </summary>
        /// <returns> Subject entity. </returns>
        private object GetSubjectEntity()
        {
            Resource entity = null;

            using (ResourceDataAccess dataAccess = new ResourceDataAccess(base.CreateContext()))
            {
                entity = dataAccess.GetResource(SubjectItemId, Constants.ScholarlyWorkItemFullName);
                dataAccess.AuthorizeResource <Resource>(AuthenticatedToken, UserResourcePermissions.Update, entity, true);
            }

            return(entity);
        }
Exemple #7
0
        /// <summary>
        /// Gets the subject entity.
        /// </summary>
        /// <returns> type of object </returns>
        private object GetSubjectEntity()
        {
            Resource entity = null;

            using (ResourceDataAccess dataAccess = new ResourceDataAccess(base.CreateContext()))
            {
                entity = dataAccess.GetResource(SubjectItemId);
                dataAccess.AuthorizeResource <Resource>(AuthenticatedToken, UserResourcePermissions.Update, entity, true);
                typeName = ((Resource)entity).GetType().Name;
            }

            return(entity);
        }
    private void Initialize()
    {
        lblErrorOrMessage.Visible          = false;
        lblErrorGlobalPermission.Visible   = false;
        lblErrorResourcePermission.Visible = false;

        grantAccess.PermissionGranted += new EventHandler <GrantEventArgs>(grantAccess_PermissionGranted);

        if (Request.QueryString[Resources.Resources.QuerystringResourceId] != null)
        {
            try
            {
                Id = new Guid(Request.QueryString[Resources.Resources.QuerystringResourceId]);

                using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
                {
                    Resource resourceData = dataAccess.GetResource(Id);
                    if (resourceData.GetType().Name == "Group")
                    {
                        Group group = (Group)resourceData;
                        lblPageTitle.Text           = resourceData.GetType().Name + ": " + group.GroupName;
                        selectedIdentityOrGroupName = group.GroupName;
                    }
                    else
                    {
                        Identity identity = (Identity)resourceData;
                        lblPageTitle.Text           = resourceData.GetType().Name + ": " + identity.IdentityName;
                        selectedIdentityOrGroupName = identity.IdentityName;
                    }
                }
            }
            catch
            {
                lblErrorOrMessage.Visible = true;
                PageContent.Visible       = false;
                lblErrorOrMessage.Text    = Resources.Resources.MsgUserOrGroupInvalid;
                return;
            }
        }

        if (UserManager.AdminUserName == selectedIdentityOrGroupName || UserManager.GuestUserName == selectedIdentityOrGroupName ||
            UserManager.AdminGroupName == selectedIdentityOrGroupName)
        {
            GlobalPermissionPanel.Visible = false;
            return;
        }
    }
Exemple #9
0
    /// <summary>
    /// Initialize the server controls on page load.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        userToken = (AuthenticatedToken)Session[Constants.AuthenticationTokenKey];

        if (!userToken.IsAdmin(Utility.CreateContext()))
        {
            throw new UnauthorizedAccessException(string.Format(CultureInfo.InvariantCulture,
                                                                Resources.Resources.UnauthorizedAccessException, UserResourcePermissions.Read));
        }

        id = Convert.ToString(Request.QueryString[Resources.Resources.QuerystringResourceId], CultureInfo.InvariantCulture);
        if (id != null)
        {
            using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
            {
                identity = (Identity)dataAccess.GetResource(new Guid(id));
                identity.Groups.Load();
                loginName = identity.IdentityName;
            }
        }

        InitializeControls();

        if (!string.IsNullOrEmpty(loginName) && !Page.IsPostBack)
        {
            ZentityUserAdmin adminObject = new ZentityUserAdmin(userToken);
            currentUserProfile = adminObject.GetUserProfile(loginName);

            txtLoginName.Text          = loginName;
            txtLoginName.Enabled       = false;
            passwordRow.Visible        = false;
            reEnterPasswordRow.Visible = false;
            securityQuesRow.Visible    = false;
            answerRow.Visible          = false;

            txtFirstName.Text  = currentUserProfile.FirstName;
            txtMiddlename.Text = currentUserProfile.MiddleName;
            txtLastName.Text   = currentUserProfile.LastName;
            txtEmail.Text      = currentUserProfile.Email;
            txtCity.Text       = currentUserProfile.City;
            txtState.Text      = currentUserProfile.State;
            txtCountry.Text    = currentUserProfile.Country;
            if (currentUserProfile.AccountStatus == AccountStatus.Active.ToString())
            {
                chkAccountStatus.Checked = true;
            }
            else if (currentUserProfile.AccountStatus == AccountStatus.InActive.ToString())
            {
                chkAccountStatus.Checked = false;
            }

            currentUser = new ZentityUser(loginName, userToken, currentUserProfile);
        }
        else
        {
            if (!string.IsNullOrEmpty(loginName) && Page.IsPostBack)
            {
                ZentityUserAdmin adminObject = new ZentityUserAdmin(userToken);
                currentUserProfile = adminObject.GetUserProfile(loginName);
                currentUser        = new ZentityUser(loginName, userToken, currentUserProfile);
            }
            else
            {
                currentUserProfile = new ZentityUserProfile();
            }
        }

        if (!Page.IsPostBack)
        {
            FillUserGrid();
        }

        UserTable.DeleteClicked += new EventHandler <ZentityGridEventArgs>(UserTable_DeleteClicked);
    }
Exemple #10
0
    /// <summary>
    /// Event will Save or Update the User information.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            bool result = false;

            GetUserInformation();
            ZentityUserAdmin adminObject = new ZentityUserAdmin(userToken);

            if (!string.IsNullOrEmpty(loginName))
            {
                currentUser = new ZentityUser(loginName, userToken, currentUserProfile);

                if (userInfoPanel.Enabled)
                {
                    result = UserManager.UpdateUser(currentUser, userToken);
                }

                if (groupAssignment.IsEnable)
                {
                    if (result)
                    {
                        result = adminObject.SetAccountStatus(currentUser.LogOnName, GetAccountStatus());
                        using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
                        {
                            List <String> groupList     = AddGroupsInIdentity();
                            List <String> allSearchList = groupAssignment.GetSearchList();

                            Identity identity = (Identity)dataAccess.GetResource(new Guid(id));
                            identity.Groups.Load();

                            List <string> existingGroups = identity.Groups
                                                           .Select(group => group.Id.ToString())
                                                           .ToList();

                            foreach (string exsitingId in existingGroups)
                            {
                                if (!groupList.Contains(exsitingId))
                                {
                                    if (allSearchList.Contains(exsitingId))
                                    {
                                        Group group = (Group)dataAccess.GetResource(new Guid(exsitingId));
                                        dataAccess.RemoveIdentityFromGroup(identity, group, userToken);
                                    }
                                }
                            }

                            foreach (string selectedId in groupList)
                            {
                                if (!existingGroups.Contains(selectedId))
                                {
                                    Group group = (Group)dataAccess.GetResource(new Guid(selectedId));
                                    result = dataAccess.AddIdentityToGroup(group, identity, userToken);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
                {
                    result = dataAccess.CreateUser(currentUser, userToken);
                    if (result)
                    {
                        result = adminObject.SetAccountStatus(currentUser.LogOnName, GetAccountStatus());
                        Identity      identity  = UserManager.GetIdentity(currentUser.LogOnName, Utility.CreateContext());
                        List <String> groupList = AddGroupsInIdentity();
                        foreach (String groupId in groupList)
                        {
                            Group group = (Group)dataAccess.GetResource(new Guid(groupId));
                            result = dataAccess.AddIdentityToGroup(group, identity, userToken);
                        }
                    }
                }
            }

            if (!result)
            {
                if (string.IsNullOrEmpty(loginName))
                {
                    Utility.ShowMessage(lblMessage, Resources.Resources.LabelErrorRegistrationFail, true);
                }
                else
                {
                    Utility.ShowMessage(lblMessage, Resources.Resources.LabelErrorUpdateUserFail, true);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(loginName))
                {
                    Utility.ShowMessage(lblMessage,
                                        string.Format(CultureInfo.InvariantCulture, Resources.Resources.LabelUserInfoUpdated, currentUser.LogOnName),
                                        false);
                }
                else
                {
                    Utility.ShowMessage(lblMessage,
                                        string.Format(CultureInfo.InvariantCulture, Resources.Resources.LabelRegistrationCompleted, currentUser.LogOnName),
                                        false);
                    ResetRegistrationForm();
                }
                FillUserGrid();
            }
        }
        catch (Exception ex)
        {
            Utility.ShowMessage(lblMessage, ex.Message, true);
        }
    }
Exemple #11
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();
                }
            }
        }
Exemple #12
0
    /// <summary>
    /// Add or Update group information.
    /// </summary>
    /// <param name="context">Zentity Context object</param>
    /// <param name="isAdded">Flag for the specify group is added or updated</param>
    /// <returns></returns>
    private bool SaveResource(ZentityContext context, out bool isAdded)
    {
        bool result = false;

        isAdded = true;
        GetGroupInformation(groupInformation);

        List <String> seletcedList = groupAssignment.GetSelectGroup();

        _resourceName = groupInformation.GroupName;
        using (ResourceDataAccess dataAccess = new ResourceDataAccess(context))
        {
            if (string.IsNullOrEmpty(Id))
            {
                result = dataAccess.CreateGroup(groupInformation, seletcedList, userToken);

                foreach (String identityId in seletcedList)
                {
                    Identity identity = (Identity)dataAccess.GetResource(new Guid(identityId));
                    result = dataAccess.AddIdentityToGroup(groupInformation, identity, userToken);
                }
                isAdded = true;
            }
            else
            {
                if (groupInfoPanel.Enabled)
                {
                    result = dataAccess.UpdateGroup(groupInformation, userToken);
                }


                //result = dataAccess.RemoveIdentityFromGroup(new Guid(Id));
                if (groupAssignment.IsEnable)
                {
                    Group group = (Group)dataAccess.GetResource(new Guid(Id));
                    group.Identities.Load();

                    List <string> existingIdentities = group.Identities
                                                       .Select(identity => identity.Id.ToString())
                                                       .ToList();

                    List <String> allSearchList = groupAssignment.GetSearchList();
                    foreach (string exsitingId in existingIdentities)
                    {
                        if (!seletcedList.Contains(exsitingId))
                        {
                            if (allSearchList.Contains(exsitingId))
                            {
                                Identity identity = (Identity)dataAccess.GetResource(new Guid(exsitingId));
                                result = dataAccess.RemoveIdentityFromGroup(identity, group, userToken);
                            }
                        }
                    }

                    foreach (string selectedId in seletcedList)
                    {
                        if (!existingIdentities.Contains(selectedId))
                        {
                            Identity identity = (Identity)dataAccess.GetResource(new Guid(selectedId));
                            result = dataAccess.AddIdentityToGroup(groupInformation, identity, userToken);
                        }
                    }
                }
                isAdded = false;
            }
        }

        return(result);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Control startNavigationTemplate = Wizard1.FindControl(_templateContainerID) as Control;

        if (startNavigationTemplate != null)
        {
            Button stepNextButton = startNavigationTemplate.FindControl(_stepNextButtonId) as Button;
            if (stepNextButton != null)
            {
                stepNextButton.Text = Resources.Resources.BibTexImportStep1NextButtonText;
            }
        }

        // This is required to avoid "PageRequestManagerParserErrorException" exception with update panel
        // because there is rendering problem with update panel.
        Control stepNavigationTemplate = Wizard1.FindControl(_stepNavTemplateContainerID) as Control;

        if (stepNavigationTemplate != null)
        {
            Button step2ImportButton = stepNavigationTemplate.FindControl(_step2ImportButton) as Button;
            if (step2ImportButton != null)
            {
                step2ImportButton.Text = Resources.Resources.BibTexImportStep2ButtonText;
            }
        }

        Guid guid = Guid.Empty;

        this.HideError();

        if (!this.IsPostBack)
        {
            LocalizePage();
        }

        bool isValidGuid = true;

        if (Request.QueryString[_queryStringKey] != null)
        {
            try
            {
                guid = new Guid(Request.QueryString[_queryStringKey]);
            }
            catch (FormatException)
            {
                this.DisplayError(Resources.Resources.InvalidResource);
                isValidGuid = false;
            }
            catch (OverflowException)
            {
                this.DisplayError(Resources.Resources.InvalidResource);
                isValidGuid = false;
            }
        }
        else if (guid == Guid.Empty)
        {
            this.DisplayError(Resources.Resources.BibtexImportMissinfId);
            isValidGuid = false;
        }

        if (isValidGuid)
        {
            using (ResourceDataAccess resourceDAL = new ResourceDataAccess())
            {
                _scholarlyWorkObj = (ScholarlyWork)resourceDAL.GetResource(guid);
                AuthenticatedToken token = Session[Constants.AuthenticationTokenKey] as AuthenticatedToken;

                //if user is not having update permission on the subject resource then throw exception.
                if (!resourceDAL.AuthorizeUser(token, UserResourcePermissions.Update, _scholarlyWorkObj.Id))
                {
                    throw new UnauthorizedAccessException(string.Format(CultureInfo.InstalledUICulture,
                                                                        Resources.Resources.MsgUnAuthorizeAccess, UserResourcePermissions.Update));
                }

                if (_scholarlyWorkObj != null)
                {
                    _scholarlyWorkObj.Cites.Load();
                }
                else
                {
                    // Handle scenario which is "a resource deleted by one user and another user operating on the resource".
                    this.DisplayError(Resources.Resources.ResourceNotFound);
                    this._isResExist = false;
                }
            }
            if (!IsPostBack && this.Wizard1.ActiveStepIndex == 0)
            {
                if (_scholarlyWorkObj == null)
                {
                    this.DisplayError(Resources.Resources.ResourceNotFound);
                }
                else
                {
                    ResourceTitleLabel.InnerText         = Resources.Resources.ResourceLabelTitleText;
                    LabelImportResourceTitle.Text        = FitString(_scholarlyWorkObj.Title, 40);
                    LabelImportResourceTitle.NavigateUrl = _resourceDetailUrl + _scholarlyWorkObj.Id;
                }
            }
        }
    }