Esempio n. 1
0
        public async Task <IActionResult> Create(CreateStepsViewModel vm)
        {
            if (ModelState.IsValid)
            {//if the model state is valid, and the currentUser's id matches the id of the specific step, add the new step to that user's list of steps
                var currentUser = await GetCurrentUserAsync();

                vm.Step.UserId = currentUser.Id;
                _context.Add(vm.Step);
                await _context.SaveChangesAsync();

                //return to the Steps Index view
                return(RedirectToAction(nameof(Index)));
            }

            // If the post fails, rebuild the view model and send it back to the view
            List <StepType> stepTypes = await _context.StepTypes.ToListAsync();

            //set up drop down to display and select step type names
            vm.StepTypeOptions = stepTypes.Select(s => new SelectListItem
            {
                Value = s.Id.ToString(),
                Text  = s.StepTypeName
            }).ToList();

            return(View(vm));
        }
Esempio n. 2
0
        // GET: Steps/Create
        public async Task <IActionResult> Create()
        {
            //create a list called stepTypes and add the StepTypes from the db to the list
            List <StepType> stepTypes = await _context.StepTypes.ToListAsync();

            //instantiate view model
            var viewModel = new CreateStepsViewModel()
            {//set up drop down to display and select step type names
                StepTypeOptions = stepTypes.Select(s => new SelectListItem
                {
                    Value = s.Id.ToString(),
                    Text  = s.StepTypeName
                }).ToList()
            };

            return(View(viewModel));
        }