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());
        }
Exemple #2
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();
        }
        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());
        }
        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());
        }