Example #1
0
        public async Task <IActionResult> OnPostAsync(int?id, bool?saveChangesError = false)
        {
            if (id == null)
            {
                return(NotFound());
            }

            if (saveChangesError.GetValueOrDefault())
            {
                ErrorMessage = "Delete failed. Try again";
            }

            Trucks = await _context.Trucks.FindAsync(id);

            if (Trucks == null)
            {
                return(NotFound());
            }

            try
            {
                _context.Trucks.Remove(Trucks);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            catch (Exception)
            {
                return(RedirectToAction("./Delete", new { id, saveChangesError = true }));
            }
        }
Example #2
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Trucks).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TrucksExists(Trucks.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }