public IHttpActionResult DeleteRoleMenu(RoleMenuViewModel roleMenu)
        {
            var role = db.Roles.Find(roleMenu.RoleId);
            if (role == null)
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "不存在的RoleId!"));

            var menus = db.Menus.Where(item => item.Id == roleMenu.MenuId || item.ParentId == roleMenu.MenuId);

            foreach (var item in menus)
            {
                role.Menus.Remove(item);
                //role.Menus.Remove(db.Menus.Find(item.ParentId));
            }

            db.SaveChanges();

            //寫入AccessLog
            MPAccessLog.WriteEntry(User.Identity.Name, AccessAction.Delete, "RoleMenu", JsonConvert.SerializeObject(new { role.Id, role.Name, Menus = menus.Select(m => m.Id + m.Text).ToArray() }));

            return Ok();
        }
        public IHttpActionResult PostRoleMenu(RoleMenuViewModel roleMenu)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var role = db.Roles.Find(roleMenu.RoleId);
            if (role == null)
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "不存在的RoleId!"));

            var menus = db.Menus.Where(item => item.Id==roleMenu.MenuId || item.ParentId==roleMenu.MenuId);

            foreach (var item in menus)
            {
                role.Menus.Add(item);
                //role.Menus.Add(db.Menus.Find( item.ParentId));
            }

            try
            {
                db.SaveChanges();

                //寫入AccessLog
                MPAccessLog.WriteEntry(User.Identity.Name, AccessAction.Create, "RoleMenu", JsonConvert.SerializeObject(new { role.Id, role.Name, Menus = menus.Select(m => m.Id+m.Text).ToArray() }));

            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
            return Ok();
        }