コード例 #1
0
        public async Task <IActionResult> PutHeroValue(int id, HeroValue heroValue)
        {
            if (id != heroValue.id)
            {
                return(BadRequest());
            }

            _context.Entry(heroValue).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HeroValueExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult <HeroValue> > PostHeroValue(HeroValue heroValue)
        {
            if (heroValue == null)
            {
                return(BadRequest());
            }
            // Generate Hero Id
            //https://github.com/lohithgn/blazor-tour-of-heroes/blob/master/src/BlazorTourOfHeroes/BlazorTourOfHeroes.Server/Controllers/HeroesController.cs
            // Grab the current context of the DbSet HeroValue
            // Find the max id
            // increase by 1
            heroValue.id = _context.HeroValue.Max(h => h.id) + 1;
            _context.HeroValue.Add(heroValue);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetHeroValue", new { id = heroValue.id }, heroValue));
        }
コード例 #3
0
        PostHeroValue(HeroValue heroValue)
        {
            if (heroValue == null)
            {
                return(BadRequest());
            }

            // Generate Hero Id
            // Grab the current context of the DbSet HeroValue
            // Find the max id
            // increase by 1
            heroValue.id = _context.HeroValue.Max(h => h.id) + 1;

            _context.HeroValue.Add(heroValue);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetHeroValue",
                                   new { id = heroValue.id },
                                   heroValue));
        }