Esempio n. 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));
        }
Esempio n. 2
0
        // GET api/values/5
        public APIJsonResult Get(int id)
        {
            var notice      = new TNoticeBLL().Find(c => c.ID == id);
            var moticeModel = UtilHelper.CopyProperties <NoticeModel>(notice);

            return(Success("",
                           new
            {
                Data = moticeModel
            }
                           ));
        }
Esempio n. 3
0
        // GET api/values/5
        public APIJsonResult Get(int id)
        {
            var adminUser      = new TAdminUserBLL().Find(c => c.ID == id);
            var adminUserModel = UtilHelper.CopyProperties <AdminUserModel>(adminUser);

            adminUserModel.RoleID = adminUser.TAdminUserRole.FirstOrDefault().RoleID;

            return(Success("",
                           new
            {
                Data = adminUserModel
            }
                           ));
        }
Esempio n. 4
0
        public APIJsonResult Edit(NoticeModel noticeModel)
        {
            var noticeBLL = new TNoticeBLL();
            var notice    = new TNotice();

            UtilHelper.CopyProperties(noticeModel, notice);

            AddUpdateInfo(notice);

            noticeBLL.Edit(notice, new string[] { "Title", "Content" });

            noticeBLL.SaveChanges();

            return(Success());
        }
Esempio n. 5
0
        // GET api/values/5
        public APIJsonResult Add(NoticeModel noticeModel)
        {
            var noticeBLL = new TNoticeBLL();
            var notice    = new TNotice();

            UtilHelper.CopyProperties(noticeModel, notice);

            AddCreateInfo(notice);

            noticeBLL.Add(notice);

            noticeBLL.SaveChanges();

            return(Success());
        }
Esempio n. 6
0
        // GET api/values/5
        public APIJsonResult Get(int id)
        {
            var role      = new TRoleBLL().Find(c => c.ID == id);
            var roleModel = UtilHelper.CopyProperties <RoleModel>(role);

            if (role.TRolePermission != null && role.TRolePermission.Count > 0)
            {
                roleModel.PermissionIDList = role.TRolePermission.Select(c => c.PermissionID).ToList();
            }

            return(Success("",
                           new
            {
                Data = roleModel
            }
                           ));
        }
Esempio n. 7
0
        // GET api/values/5
        public APIJsonResult Add(RoleModel roleModel)
        {
            roleModel.Name = roleModel.Name.Trim();
            var roleBLL = new TRoleBLL();
            var role    = new TRole();

            UtilHelper.CopyProperties(roleModel, role);

            AddCreateInfo(role);

            try
            {
                roleBLL.Add(role);
            }
            catch (ValidationException ex)
            {
                return(Failed(ex.Message));
            }

            roleBLL.SaveChanges();

            if (roleModel.PermissionIDList != null && roleModel.PermissionIDList.Count > 0)
            {
                var rolePermissionBLL = new TRolePermissionBLL();

                foreach (var permissionID in roleModel.PermissionIDList)
                {
                    var rolePermission = new TRolePermission()
                    {
                        PermissionID = permissionID,
                        RoleID       = role.ID
                    };

                    AddCreateInfo(rolePermission);

                    rolePermissionBLL.Add(rolePermission);
                }

                rolePermissionBLL.SaveChanges();
            }


            return(Success());
        }
Esempio n. 8
0
        public APIJsonResult Edit(RoleModel roleModel)
        {
            var roleBLL = new TRoleBLL();
            var role    = new TRole();

            UtilHelper.CopyProperties(roleModel, role);
            AddUpdateInfo(role);

            try {
                roleBLL.Edit(role, new string[] { "Name" });
            }
            catch (ValidationException ex)
            {
                return(Failed(ex.Message));
            }

            roleBLL.SaveChanges();

            var rolePermissionBLL = new TRolePermissionBLL();

            rolePermissionBLL.Delete(c => c.RoleID == role.ID);

            if (roleModel.PermissionIDList != null && roleModel.PermissionIDList.Count > 0)
            {
                foreach (var permissionID in roleModel.PermissionIDList)
                {
                    var rolePermission = new TRolePermission()
                    {
                        PermissionID = permissionID,
                        RoleID       = role.ID
                    };

                    AddCreateInfo(rolePermission);

                    rolePermissionBLL.Add(rolePermission);
                }
            }

            rolePermissionBLL.SaveChanges();


            return(Success());
        }
Esempio n. 9
0
        // GET api/values/5
        public APIJsonResult GetList(int pageSize, int pageIndex, string keywords)
        {
            int totalCount    = 0;
            var adminUserList = new TAdminUserBLL().PagerQuery(pageSize, pageIndex, out totalCount, c => c.Account.Contains(keywords), c => c.CreateDate, false);

            var adminUserModelList = UtilHelper.ConvertObjList <TAdminUser, AdminUserModel>(adminUserList);

            for (int i = 0; i < adminUserModelList.Count; i++)
            {
                var adminUserModel = adminUserModelList[i];
                var adminUser      = adminUserList[i];
                adminUserModel.Role = UtilHelper.CopyProperties <RoleModel>(adminUser.TAdminUserRole.First().TRole);
            }


            return(Success("", new
            {
                List = adminUserModelList,
                TotalCount = totalCount
            }));
        }