Beispiel #1
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);
        }
    }
Beispiel #2
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);
    }