Exemple #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 (_session.Get("admin") != null)
            {
                if (!ModelState.IsValid)
                {
                    return(Page());
                }

                _context.Users.Add(Users);
                if (Users.isAdmin == true)
                {
                    Admins admin = new Admins();
                    admin.AdminName     = Users.UserName;
                    admin.AdminUsername = Users.UserNickName;
                    admin.AdminPassword = Users.UserPassword;
                    _context.Admins.Add(admin);
                }
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            else
            {
                return(RedirectToPage("/Login/Login"));
            }
        }
Exemple #2
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 (_session.Get("admin") != null)
            {
                if (!ModelState.IsValid)
                {
                    return(Page());
                }

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

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommentsExists(Comments.CommentID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToPage("./Index"));
            }
            else
            {
                return(RedirectToPage("/Login/Login"));
            }
        }
        // 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(Posts).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostsExists(Posts.PostID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemple #4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (_session.Get("admin") != null)
            {
                if (id == null)
                {
                    return(NotFound());
                }

                Comments = await _context.Comments.Include(x => x.Post).Where(x => x.CommentID == id).FirstOrDefaultAsync();

                if (Comments != null)
                {
                    Comments.Post.PostCommentCount--;
                    _context.Comments.Remove(Comments);
                    await _context.SaveChangesAsync();
                }

                return(RedirectToPage("./Index"));
            }
            else
            {
                return(RedirectToPage("/Login/Login"));
            }
        }
Exemple #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            int        CategoryID = Posts.Category.CategoryID;
            Categories category   = new Categories();

            category       = this._context.Categories.Where(x => x.CategoryID == CategoryID).FirstOrDefault();
            Posts.Category = category;
            Posts.User     = this._context.Users.Where(x => x.UserID == BitConverter.ToInt32(_session.Get("id"))).FirstOrDefault();
            _context.Posts.Add(Posts);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            return(RedirectToPage("./Index"));
        }
        // 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 (_session.Get("admin") == null)
            {
                return(RedirectToPage("/Login/Login"));
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(Page());
                }

                _context.Categories.Add(Categories);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
        }
Exemple #8
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (_session.Get("admin") == null)
            {
                return(RedirectToPage("/Login/Login"));
            }
            else
            {
                int        CategoryID = Posts.Category.CategoryID;
                Categories category   = new Categories();
                category       = this._context.Categories.Where(x => x.CategoryID == CategoryID).FirstOrDefault();
                Posts.Category = category;

                _context.Posts.Add(Posts);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
        }
Exemple #9
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (_session.Get("admin") == null)
            {
                return(RedirectToPage("/Login/Login"));
            }
            else
            {
                if (id == null)
                {
                    return(NotFound());
                }

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

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

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