Пример #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(TblPost).State = EntityState.Modified;

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

            return(RedirectToPage("./Index"));
        }
Пример #2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TblPost = await _context.TblPost.FindAsync(id);

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

            return(RedirectToPage("./Index"));
        }
Пример #3
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());
            }

            TblPost post = new TblPost();

            if (Input.BannerImagePath != null && Input.BannerImagePath.Count > 0)
            {
                foreach (var item in Input.BannerImagePath)
                {
                    using (var stream = new MemoryStream())
                    {
                        await item.CopyToAsync(stream);

                        post.BannerImagePath = stream.ToArray();
                    }
                }
            }

            post.UserId        = Input.UserId;
            post.Title         = Input.Title;
            post.CategoryId    = Input.CategoryId;
            post.Summary       = Input.Summary;
            post.FullBody      = Input.FullBody;
            post.NumViews      = 0;
            post.DatePublished = DateTime.Today;


            _context.TblPost.Add(post);
            await _context.SaveChangesAsync();

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