public async Task<IHttpActionResult> Post(RoleViewModel m)
 {
     if (!ModelState.IsValid)
         return BadRequest(ModelState);
     var role = new AppRole()
     {
         CreateBy = User.Identity.GetUserId(),
         CreateTime = DateTimeOffset.Now,
         Deleted = false,
         Id = Guid.NewGuid().ToString(),
         Name = m.Name
     };
     if (!roleManager.RoleExists(m.Name))
         roleManager.Create(role);
     else
     {
         ModelState.AddModelError("Failure", "该角色已存在。");
         return BadRequest(ModelState);
     }
     return Created<RoleViewModel>(new RoleViewModel() { Id = role.Id, Name = role.Name });
 }
        public async Task<IHttpActionResult> Put(RoleViewModel putModel)
        {

            if (roleManager.RoleExists(putModel.Name))
            {
                ModelState.AddModelError("Failure", "该角色已存在。");
                return BadRequest(ModelState);
            }
            var role = roleManager.FindById(putModel.Id);
            if (role == null)
                return NotFound();
            else
            {
                role.UpdateBy = User.Identity.GetUserId();
                role.UpdateTime = DateTimeOffset.Now;
                role.Name = putModel.Name;
                if (!ModelState.IsValid)
                    return BadRequest(ModelState);
                await roleManager.UpdateAsync(role);
                return Updated<RoleViewModel>(new RoleViewModel() { Id = role.Id, Name = role.Name });
            }
        }
 public IHttpActionResult Get([FromODataUri]string id)
 {
     var m = db.Roles.SingleOrDefault(p => p.Id == id);
     if (m == null) return NotFound();
     var role = new RoleViewModel() { Id = m.Id, Name = m.Name };
     return Ok(role);
 }