Beispiel #1
0
 public ActionResult Edit([Bind(Include = "Id,MenuId,RoleId")] MenuRole menuRole)
 {
     if (ModelState.IsValid)
     {
         _menuRoleService.Update(menuRole);
         return(RedirectToAction("Index"));
     }
     ViewBag.MenuId = new SelectList(_menuService.GetList(), "Id", "LinkText", menuRole.MenuId);
     ViewBag.RoleId = new SelectList(_roleService.GetList(), "Id", "Name", menuRole.RoleId);
     return(View(menuRole));
 }
        //[Authorize(Roles = "EditMenuRole")]
        public IActionResult Put([FromBody] MenuRoleViewModel menuRoleViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            IActionResult result       = new ObjectResult(false);
            GenericResult updateResult = null;

            try
            {
                if (menuRoleViewModel.MenuLink == "/")
                {
                    menuRoleViewModel.MenuLink = "";
                }

                var menuRole = _menuRoleService.GetById(menuRoleViewModel.MenuId);
                menuRole.UpdateMenuRole(menuRoleViewModel);
                //   MenuRole menuRole = Mapper.Map<MenuRoleViewModel, MenuRole>(menuRoleViewModel);
                _menuRoleService.Update(menuRole);
                _menuRoleService.Save();
                updateResult = new GenericResult()
                {
                    Succeeded = true,
                    Message   = "Cập nhật menu thành công"
                };
            }
            catch (Exception ex)
            {
                updateResult = new GenericResult()
                {
                    Succeeded = false,
                    Message   = "Cập nhật menu thất bại"
                };
                _loggingRepository.Add(new Error()
                {
                    Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now
                });
                _loggingRepository.Commit();
            }

            result = new ObjectResult(updateResult);
            return(result);
        }