Exemple #1
0
        public bool AddUserinGroup(List <int> userList, int groupId)
        {
            try
            {
                for (var r = 0; r < userList.Count; r++)
                {
                    var userId    = userList[r];
                    var isPresent = _groupManagement.SearchUserInGroupwithGroupId(userId, groupId);

                    if (isPresent.Count == 0)
                    {
                        _groupManagement.AddUserInGroup(userId, groupId);
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public JsonResult SaveUserIntoGroup()
        {
            if (groupManagement.IsGroupAlreadyExist(Request["GroupName"]).Value.ToString() == "True")
            {
                var result = new { status = false, value = "Group name already exists" };
                return(Json(new { Data = result }));
            }

            try
            {
                var group = new Group
                {
                    GroupName        = Request["GroupName"],
                    GroupDescription = Request["GroupDescription"],
                    GroupColor       = Request["GroupColor"],
                };

                var groupUsers = Request["GroupUsers"].Split(',').ToList();

                var groupId = groupManagement.AddGroup(group);

                foreach (var user in groupUsers)
                {
                    var userId = Convert.ToInt32(user);
                    groupManagement.AddUserInGroup(userId, Convert.ToInt32(groupId));
                }
            }
            catch
            {
                var result = new { status = false, value = "Group creation has been failed." };
                return(Json(new { Data = result }));
            }
            var finalResult = new { status = true, value = "Group has been created successfully." };

            return(Json(new { Data = finalResult }));
        }
        /// <summary>
        /// Add System Admin
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="firstName">Full name of user</param>
        /// <param name="lastName">Last name of user</param>
        /// <param name="emailId">Email Id</param>
        /// <param name="password">Password</param>
        public static void AddSystemAdmin(string userName, string firstName, string lastName, string emailId,
                                          string password)
        {
            LogExtension.LogInfo("Creating system admin",
                                 MethodBase.GetCurrentMethod());
            var encrypt         = new Cryptography();
            var umpUser         = new User();
            var userManagement  = new UserManagement(GlobalAppSettings.QueryBuilder, GlobalAppSettings.DataProvider);
            var groupManagement = new GroupManagement(GlobalAppSettings.QueryBuilder, GlobalAppSettings.DataProvider);

            umpUser.Password          = Convert.ToBase64String(encrypt.Encryption(password));
            umpUser.CreatedDate       = DateTime.UtcNow;
            umpUser.ModifiedDate      = DateTime.UtcNow;
            umpUser.IsActive          = true;
            umpUser.IsDeleted         = false;
            umpUser.ResetPasswordCode = "default";
            umpUser.ActivationCode    = "default";
            umpUser.UserName          = userName;
            umpUser.FirstName         = firstName.Trim();
            umpUser.LastName          = lastName.Trim();
            umpUser.DisplayName       = (umpUser.FirstName.Trim() + " " + umpUser.LastName.Trim()).Trim();
            umpUser.Email             = emailId;
            umpUser.IsActivated       = true;
            var activationCode           = String.Empty;
            var activationExpirationDate = new DateTime();

            LogExtension.LogInfo("Adding user in user table", MethodBase.GetCurrentMethod());
            var result = userManagement.AddUser(umpUser, out activationExpirationDate, out activationCode);

            if (result.Status)
            {
                LogExtension.LogInfo("Adding user in user table succesful", MethodBase.GetCurrentMethod());
                LogExtension.LogInfo("Adding user in super admin group table", MethodBase.GetCurrentMethod());
                var userGroup = groupManagement.AddUserInGroup(Convert.ToInt32(result.ReturnValue), 1);
                LogExtension.LogInfo("Is user added in super admin?" + userGroup, MethodBase.GetCurrentMethod());

                //var permissionSet = new PermissionSet();

                //permissionSet.AddPermissionToGroup(new Permission
                //{
                //    PermissionAccess = PermissionAccess.Create,
                //    PermissionEntity = PermissionEntity.AllCategories,
                //    TargetId = 1
                //});

                //permissionSet.AddPermissionToGroup(new Permission
                //{
                //    PermissionAccess = PermissionAccess.Create,
                //    PermissionEntity = PermissionEntity.AllReports,
                //    TargetId = 1
                //});

                //permissionSet.AddPermissionToGroup(new Permission
                //{
                //    PermissionAccess = PermissionAccess.Create,
                //    PermissionEntity = PermissionEntity.AllSchedules,
                //    TargetId = 1
                //});

                //permissionSet.AddPermissionToGroup(new Permission
                //{
                //    PermissionAccess = PermissionAccess.Create,
                //    PermissionEntity = PermissionEntity.AllDataSources,
                //    TargetId = 1
                //});

                //permissionSet.AddPermissionToGroup(new Permission
                //{
                //    PermissionAccess = PermissionAccess.Create,
                //    PermissionEntity = PermissionEntity.AllFiles,
                //    TargetId = 1
                //});
            }
            else
            {
                LogExtension.LogInfo("Error in adding user in user table", MethodBase.GetCurrentMethod());
            }
        }