Beispiel #1
0
        // GET: EczaneNobet/MenuRole/Details/5
        public ActionResult Details(int id)
        {
            if (id < 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var           menuRole      = _menuRoleService.GetById(id);
            MenuRoleDetay menuRoleDetay = _menuRoleService.GetMenuRoleDetaylar().Where(s => s.Id == menuRole.Id).SingleOrDefault();

            if (menuRole == null)
            {
                return(HttpNotFound());
            }
            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);
        }