Пример #1
0
        public async Task <IActionResult> RemoveContactAsync(int id)
        {
            try
            {
                var user = await _dbcontext.phonebooks.FindAsync(id);

                _dbcontext.phonebooks.Remove(user);

                await _dbcontext.SaveChangesAsync();

                return(RedirectToAction("Contact"));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Contact"));
            }
        }
Пример #2
0
        public async Task <Comment> Post(long postId, [FromBody] Comment comment)
        {
            comment.PostId = postId;
            comment.Author = User.Identity.Name;
            comment.Posted = DateTime.Now;

            _db.Comments.Add(comment);
            await _db.SaveChangesAsync();

            return(comment);
        }
Пример #3
0
        public async Task <Comment> Post(long postId, [FromBody] Comment comment)
        {
            comment.PostId     = postId;
            comment.Author     = comment.Author;
            comment.PostedDate = DateTime.Now;

            _blogDataContext.Comments.Add(comment);
            await _blogDataContext.SaveChangesAsync();

            return(comment);
        }
Пример #4
0
        public async Task <IActionResult> Create(Post post)
        {
            if (!ModelState.IsValid)
            {
                return(View(post));
            }

            post.PostedDate = DateTime.Now;
            post.Author     = User.Identity.Name;

            _dataContext.Posts.Add(post);
            await _dataContext.SaveChangesAsync();

            return(RedirectToAction("Post", new { post.PostedDate.Year, post.PostedDate.Month, post.Key }));
        }
        public async Task <IActionResult> Create(Post post)
        {
            if (!ModelState.IsValid)
            {
                return(View(post));
            }

            post.PostedDate = DateTime.Now;
            post.Author     = User.Identity.Name;

            var db = new BlogDataContext();

            db.Posts.Add(post);
            await db.SaveChangesAsync();

            return(View());
        }
Пример #6
0
 public async Task CommitAsync()
 {
     await _context.SaveChangesAsync();
 }