Пример #1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var record = await _context.Records
                         .AsNoTracking()
                         .FirstOrDefaultAsync(m => m.Id == id);

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

            try
            {
                _context.Records.Remove(record);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.)
                return(RedirectToAction("./Delete",
                                        new { id = id, saveChangesError = true }));
            }
        }
Пример #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var emptyRecord = new Record();

            if (await TryUpdateModelAsync <Record>(
                    emptyRecord,
                    "record",
                    s => s.Comments, s => s.Project, s => s.Date))
            {
                _context.Records.Add(emptyRecord);
                await _context.SaveChangesAsync();

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

            return(null);
        }