コード例 #1
0
        public async Task <ActionResult <Pirate> > AddPirate([FromBody] NewPirate pirate)
        {
            var p = new Pirate
            {
                Name            = pirate.Name,
                RealName        = pirate.RealName,
                YearOfBirth     = pirate.YearOfBirth,
                YearOfDeath     = pirate.YearOfDeath,
                CountryOfOrigin = pirate.CountryOfOrigin
            };
            await context.Pirates.AddAsync(p);

            await context.SaveChangesAsync();

            return(CreatedAtRoute(nameof(GetPirateById), new { id = p.ID }, p));
        }
コード例 #2
0
        public async Task OnPostDelete(Guid id)
        {
            var pirate = await context.Pirates.FirstOrDefaultAsync(p => p.ID == id);

            if (pirate != null)
            {
                context.Pirates.Remove(pirate);
                await context.SaveChangesAsync();
            }

            await OnPostFilter();
        }
コード例 #3
0
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid && Pirate != null)
            {
                if (RouteData.Values["id"] != null)
                {
                    context.Pirates.Update(Pirate);
                }
                else
                {
                    context.Pirates.Add(Pirate);
                }

                await context.SaveChangesAsync();

                return(RedirectToPage("Index"));
            }

            return(Page());
        }