示例#1
0
 public IActionResult Edit(GeekyRole geekyRole)
 {
     if (ModelState.IsValid)
     {
         var res = _roleManager.UpdateAsync(geekyRole).Result;
         if (res.Succeeded)
         {
             return(RedirectToAction("Index"));
         }
         return(RedirectToAction("Index", new { Message = RolesMessageId.ConcurrecyError }));
     }
     return(View());
 }
示例#2
0
        public IActionResult PostRole([FromBody] GeekyRole geekyRole)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelState));
            }

            var res = _roleManager.CreateAsync(geekyRole);

            if (!res.Result.Succeeded)
            {
            }

            return(CreatedAtRoute("GetGeekyRole", new { id = geekyRole.Id }, geekyRole));
        }
示例#3
0
        public IActionResult GetRole([FromRoute] string id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelState));
            }

            GeekyRole geekyRole = _roleManager.Roles.Single(m => m.Id == id);

            if (geekyRole == null)
            {
                return(HttpNotFound());
            }

            return(Ok(geekyRole));
        }
示例#4
0
        public IActionResult Create(GeekyRole geekyRole)
        {
            if (ModelState.IsValid)
            {
                geekyRole.Id = Guid.NewGuid().ToString();
                geekyRole.ConcurrencyStamp = Guid.NewGuid().ToString();
                var res = _roleManager.CreateAsync(geekyRole);

                if (res.Result.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                return(View());
            }
            return(View(geekyRole));
        }
示例#5
0
        public IActionResult DeleteRole(string id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelState));
            }

            GeekyRole geekyRole = _roleManager.Roles.Single(m => m.Id == id);

            if (geekyRole == null)
            {
                return(HttpNotFound());
            }

            var res = _roleManager.DeleteAsync(geekyRole);

            if (!res.Result.Succeeded)
            {
                return(Content(res.Result.Errors.FirstOrDefault().Description));
            }

            return(Ok(geekyRole));
        }
示例#6
0
        public IActionResult PutRole(string id, [FromBody] GeekyRole geekyRole)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelState));
            }

            if (id != geekyRole.Id)
            {
                return(HttpBadRequest());
            }


            try
            {
                var res = _roleManager.UpdateAsync(geekyRole);
                return(!res.Result.Succeeded ? new HttpStatusCodeResult(StatusCodes.Status500InternalServerError) : Ok());
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }