示例#1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var deskQuote = await _context.DeskQuote
                            .AsNoTracking()
                            .FirstOrDefaultAsync(m => m.ID == id);


            if (DeskQuote == null)
            {
                return(NotFound());
            }
            try
            {
                _context.DeskQuote.Remove(DeskQuote);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            catch
            {
                //Log error
                return(RedirectToAction("./Delete",
                                        new { id, saveChangesError = true }));
            }
        }
示例#2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var deskQuoteToUpdate = await _context.DeskQuote.FindAsync(id);

            if (await TryUpdateModelAsync <DeskQuote>(
                    deskQuoteToUpdate,
                    "deskQuote",
                    s => s.FirstName, s => s.LastName, s => s.QuoteDate, s => s.RushOrder, s => s.Width, s => s.Depth,
                    s => s.DrawerCount, s => s.SurfaceMaterial))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Details", new { id = deskQuoteToUpdate.ID }));
            }


            return(Page());
        }