Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!(User.Identity.GetUserId() == Post.UserId.ToString() || User.IsInRole("admin")))
            {
                return(RedirectToPage("/Errors/Unauthorized"));
            }
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Post.DateEdited = (DateTime?)DateTime.Now;
            //Post.PostContent = Post.PostContent.Replace(Environment.NewLine, "<br/>");
            _context.Attach(Post).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostExists(Post.PostId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 2
0
        // To protect from overposting attacks, 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(Post).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostExists(Post.PostId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

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