Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            // Set UpdatedAt time to now
            BlogPost.UpdatedAt = DateTime.Now;

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

            // We don't want to update CreatedAt, since we're editing the object
            _context.Entry(BlogPost).Property("CreatedAt").IsModified = false;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BlogModelExists(BlogPost.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            // Set CreatedAt to now
            BlogPost.CreatedAt = DateTime.Now;

            _context.Blog.Add(BlogPost);

            // We don't want to change UpdatedAt, since we're only just creating the object
            _context.Entry(BlogPost).Property("UpdatedAt").IsModified = false;

            await _context.SaveChangesAsync();

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