public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Todos.Add(TodoTakeObject);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostDeleteAsync(int id)
        {
            var toDoID = await _context.Todos.FindAsync(id);

            if (toDoID != null)
            {
                _context.Todos.Remove(toDoID);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage());
        }
示例#3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw new Exception($"Task! {TodoTakeObject.Id} not found!");
            }

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