コード例 #1
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(JournalModel).State            = EntityState.Modified;
            _context.Attach(JournalModel).Entity.CreatedAt = _creationTime;

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

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
ファイル: Edit.cshtml.cs プロジェクト: KeesHiemstra/JoostWeb
        public async Task <IActionResult> OnPostSaveAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _db.Attach(Journal).State = EntityState.Modified;

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException e)
            {
                //Handle deleted row
                var exceptionEntry = e.Entries.Single();
                var databaseEntry  = exceptionEntry.GetDatabaseValues();
                if (databaseEntry == null)
                {
                    ModelState.AddModelError(string.Empty, "Unable to save. " +
                                             "The journal entity was deleted by another user.");
                    return(Page());
                }

                ModelState.AddModelError(string.Empty, "Unable to save. " +
                                         "The journal entity was changed by another user.");
                return(Page());
            }

            return(Redirect("/Journal/Index"));
        }