Esempio n. 1
0
        public IActionResult Edit(PostEditModel postEditModel, int id)
        {
            var post = _db.Posts.Include(u => u.User)
                       .FirstOrDefault(p => p.Id == id);

            if (post.User.UserName == User.Identity.Name)
            {
                post.Name = postEditModel.PostName;
                post.Text = postEditModel.PostText;
                _db.SaveChanges();
            }
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 2
0
        public IActionResult Create(CommentCreateModel commentCreateModel, int id)
        {
            var userName = User.Identity.Name;
            var e        = _db.Comments.Add(new CommentModel
            {
                Author     = _db.Users.FirstOrDefault(u => u.UserName == userName),
                CreateDate = DateTime.Now,
                Text       = commentCreateModel.CommentText,
                Post       = _db.Posts.FirstOrDefault(p => p.Id == id)
            });

            _db.SaveChanges();
            return(RedirectToAction("Index", "Comment", new { id = id }));
        }
Esempio n. 3
0
        public bool Add([FromBody] User user)
        {
            if (_context.Users.Any(x => x.Email == user.Email))
            {
                return(false);
            }

            _context.Users.Add(user);
            _context.SaveChanges();
            return(true);
        }