public async Task <IActionResult> Edit(int id, [Bind("Id,PetId,AchievementId")] PetAchievement petAchievement)
        {
            if (id != petAchievement.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(petAchievement);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PetAchievementExists(petAchievement.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AchievementId"] = new SelectList(_context.Achievements, "Id", "Id", petAchievement.AchievementId);
            ViewData["PetId"]         = new SelectList(_context.Pets, "Id", "Id", petAchievement.PetId);
            return(View(petAchievement));
        }
示例#2
0
 public AchievementViewModel ToAchievementViewModel(PetAchievement petachievement)
 {
     return(new AchievementViewModel
     {
         Id = petachievement.Id,
         Achievements = _combosHelper.GetComboAchievements(),
         AchievementId = petachievement.AchievementId,
         Pet = petachievement.Pet,
         PetId = petachievement.PetId,
     });
 }
        public async Task <IActionResult> Create([Bind("Id,PetId,AchievementId")] PetAchievement petAchievement)
        {
            if (ModelState.IsValid)
            {
                _context.Add(petAchievement);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AchievementId"] = new SelectList(_context.Achievements, "Id", "Id", petAchievement.AchievementId);
            ViewData["PetId"]         = new SelectList(_context.Pets, "Id", "Id", petAchievement.PetId);
            return(View(petAchievement));
        }