예제 #1
0
        public static void SaveLoginUser(TAdminUser adminUser)
        {
            if (!string.IsNullOrEmpty(adminUser.Token))
            {
                CacheHelper.RemoveAllCache(adminUser.Token);
            }

            var sessionUserModel = new AdminUserModel();

            UtilHelper.CopyProperties(adminUser, sessionUserModel, new string[] {
                "ID",
                "Account",
                "Avatar",
                "Token",
                "TokenExpired",
                "LastLoginDate",
                "LastLoginIP"
            });

            var role             = new RoleModel();
            var adminUserRoleBLL = new TAdminUserRoleBLL();
            var adminUserRole    = adminUserRoleBLL.Find(ur => ur.AdminUserID == sessionUserModel.ID);

            UtilHelper.CopyProperties(adminUserRole.TRole, role, new string[] {
                "ID",
                "Name"
            });

            sessionUserModel.RoleID = role.ID;
            sessionUserModel.Role   = role;

            CacheHelper.SetCache(adminUser.Token, sessionUserModel, new TimeSpan(0, 30, 0));
        }
예제 #2
0
        public APIJsonResult Edit(AdminUserEditModel adminUserModel)
        {
            var adminUserBLL = new TAdminUserBLL();
            var adminUser    = adminUserBLL.Find(u => u.ID == adminUserModel.ID);

            AddUpdateInfo(adminUser);

            List <string> updatedField = new List <string>();

            if (!string.IsNullOrEmpty(adminUserModel.Password))
            {
                adminUser.Password = EncryptHelper.EncryptString(adminUserModel.Password);
            }

            adminUser.Status = adminUserModel.Status;

            adminUserBLL.SaveChanges();

            var adminUserRoleBLL = new TAdminUserRoleBLL();
            var adminUserRole    = adminUserRoleBLL.Find(r => r.AdminUserID == adminUser.ID);

            adminUserRole.RoleID = adminUserModel.RoleID;

            AddUpdateInfo(adminUserRole);
            adminUserRoleBLL.SaveChanges();

            return(Success());
        }
예제 #3
0
        //public new List<TAdminUser> PagerQuery<Tkey>(int pageSize, int pageIndex, out int total, Expression<Func<TAdminUser, bool>> whereLambda, Func<TAdminUser, Tkey> orderbyLambda, bool isAsc)
        //{
        //    var adminUserList bdal.PagerQuery(pageSize, pageIndex, out total, whereLambda, orderbyLambda, isAsc);
        //}


        public void Register(TAdminUser userModel, TAdminUserRole roleModel)
        {
            var existAccount = Find(u => u.Account == userModel.Account);

            if (existAccount != null)
            {
                throw new ValidationException("Account name duplicated.");
            }

            Add(userModel);

            SaveChanges();

            roleModel.AdminUserID = userModel.ID;

            var roleBLL = new TAdminUserRoleBLL();

            roleBLL.Add(roleModel);
            roleBLL.SaveChanges();
        }
예제 #4
0
        public APIJsonResult Delete(int adminUserID)
        {
            var adminUserBLL = new TAdminUserBLL();

            try
            {
                adminUserBLL.Delete(adminUserID);
                adminUserBLL.SaveChanges();
            }
            catch (ValidationException ex)
            {
                return(Failed(ex.Message));
            }

            var adminUserRoleBLL = new TAdminUserRoleBLL();

            adminUserRoleBLL.Delete(ur => ur.AdminUserID == adminUserID);
            adminUserRoleBLL.SaveChanges();

            return(Success());
        }
예제 #5
0
        public APIJsonResult MultiDelete(int[] adminUserIDs)
        {
            var adminUserBLL     = new TAdminUserBLL();
            var adminUserRoleIDs = adminUserBLL.Query(u => adminUserIDs.Contains(u.ID)).Select(u => u.TAdminUserRole.First().ID);

            try
            {
                adminUserBLL.Delete(adminUserIDs);
                adminUserBLL.SaveChanges();
            }
            catch (ValidationException ex)
            {
                return(Failed(ex.Message));
            }

            var adminUserRoleBLL = new TAdminUserRoleBLL();

            adminUserRoleBLL.Delete(ur => adminUserRoleIDs.Contains(ur.ID));
            adminUserRoleBLL.SaveChanges();


            return(Success());
        }