コード例 #1
0
        public async Task <IActionResult> Create(CreateOrUpdateRoleViewModel role)
        {
            if (ModelState.IsValid)
            {
                var viewModel = _mapper.Map <AppRole>(role);

                await _roleManager.CreateAsync(viewModel);

                Alert("Lưu vai trò thành công!");


                return(RedirectToAction(nameof(Index)));
            }
            return(View(nameof(CreateOrUpdate), role));
        }
コード例 #2
0
        public async Task <IActionResult> CreateOrUpdate(string id)
        {
            var model = new CreateOrUpdateRoleViewModel();

            if (id != null)
            {
                var data = await _roleManager.FindByIdAsync(id);

                model = _mapper.Map <CreateOrUpdateRoleViewModel>(data);

                if (model == null)
                {
                    return(NotFound());
                }
            }
            return(View(model));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(Guid id, CreateOrUpdateRoleViewModel role)
        {
            if (id != role.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var viewModel = _mapper.Map <AppRole>(role);

                await _roleManager.UpdateAsync(viewModel);

                Alert("Lưu danh mục thành công!");

                return(RedirectToAction(nameof(Index)));
            }
            return(View(nameof(CreateOrUpdate), role));
        }