コード例 #1
0
        public async Task <IActionResult> Edit(Guid id, ItemChoiceCreateEditViewModel vm)
        {
            if (id != vm.ItemChoice.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _bll.ItemChoices.UpdateAsync(vm.ItemChoice);

                    await _bll.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ItemChoiceExists(vm.ItemChoice.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            vm.ItemOptions = new SelectList(await _bll.ItemOptions.GetAllAsync(), nameof(ItemOption.Id), nameof(ItemOption.Name), vm.ItemChoice.ItemOptionId);
            return(View(vm));
        }
コード例 #2
0
        // GET: ItemChoices/Create
        public IActionResult Create()
        {
            var userIdTKey = User.IsInRole("Admin") ? null : (Guid?)User.UserGuidId();
            var vm         = new ItemChoiceCreateEditViewModel {
                ItemOptions = new SelectList(_bll.ItemOptions.GetAll(userIdTKey), nameof(ItemOption.Id), nameof(ItemOption.Name))
            };

            return(View(vm));
        }
コード例 #3
0
        public async Task <IActionResult> Create(ItemChoiceCreateEditViewModel vm)
        {
            if (ModelState.IsValid)
            {
                vm.ItemChoice.Id = Guid.NewGuid();
                _bll.ItemChoices.Add(vm.ItemChoice);
                await _bll.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            var userIdTKey = User.IsInRole("Admin") ? null : (Guid?)User.UserGuidId();

            vm.ItemOptions = new SelectList(await _bll.ItemOptions.GetAllAsync(userIdTKey), nameof(ItemOption.Id), nameof(ItemOption.Name), vm.ItemChoice.ItemOptionId);
            return(View(vm));
        }
コード例 #4
0
        // GET: ItemChoices/Edit/5
        public async Task <IActionResult> Edit(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var userIdTKey = User.IsInRole("Admin") ? null : (Guid?)User.UserGuidId();
            var vm         = new ItemChoiceCreateEditViewModel {
                ItemChoice = await _bll.ItemChoices.FirstOrDefaultAsync(id.Value, userIdTKey)
            };

            if (vm.ItemChoice == null)
            {
                return(NotFound());
            }
            vm.ItemOptions = new SelectList(await _bll.ItemOptions.GetAllByUserAsync(userIdTKey), nameof(ItemOption.Id), nameof(ItemOption.Name), vm.ItemChoice.ItemOptionId);
            return(View(vm));
        }