예제 #1
0
        public async Task <ActionResult> Edit(int id, EditConceptViewModel editConceptViewModel)
        {
            try
            {//first or default takes a call-back function
                var concept = await _context.Concepts
                              .Include(c => c.Descriptions)
                              .Include(c => c.UsefulLinks)
                              .FirstOrDefaultAsync(concept => concept.Id == id);

                concept.Name = editConceptViewModel.ConceptName;
                //this is updating the lists with new list and it updates the links/descriptions database
                concept.UsefulLinks  = editConceptViewModel.Links;
                concept.Descriptions = editConceptViewModel.Descriptions;

                concept.Id = id;

                //this is what edits the concept in the database.
                _context.Concepts.Update(concept);
                await _context.SaveChangesAsync();

                //the , new Id lets you grab the software id and include it in the route
                return(RedirectToAction(nameof(Index), new { id = concept.SoftwareLanguageId }));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
예제 #2
0
        // GET: Concept/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            var viewModel = new EditConceptViewModel();

            var user = await GetCurrentUserAsync();

            var descriptions = await _context
                               .Descriptions.Where(d => d.ConceptId == id).ToListAsync();

            var links = await _context
                        .UsefulLinks.Where(l => l.ConceptId == id).ToListAsync();

            var concept = await _context.Concepts.FindAsync(id);

            viewModel.ConceptName  = concept.Name;
            viewModel.Descriptions = descriptions;
            viewModel.Links        = links;
            viewModel.ConceptId    = id;

            return(View(viewModel));
        }