コード例 #1
0
        public async Task <IActionResult> Edit(int?id, [Bind("Id,DiseaseId,AssociationId")] DiseaseAssociation diseaseAssociation)
        {
            if (id != diseaseAssociation.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(diseaseAssociation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DiseaseAssociationExists(diseaseAssociation.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AssociationId"] = new SelectList(_context.Association, "Id", "Name", diseaseAssociation.AssociationId);
            ViewData["DiseaseId"]     = new SelectList(_context.Disease, "Id", "Name", diseaseAssociation.DiseaseId);
            return(View(diseaseAssociation));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,DiseaseId,AssociationId")] DiseaseAssociation diseaseAssociation)
        {
            if (ModelState.IsValid)
            {
                _context.Add(diseaseAssociation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AssociationId"] = new SelectList(_context.Association, "Id", "Name", diseaseAssociation.AssociationId);
            ViewData["DiseaseId"]     = new SelectList(_context.Disease, "Id", "Name", diseaseAssociation.DiseaseId);
            return(View(diseaseAssociation));
        }