public void AddPost([FromBody] Posts post)
 {
     post.ReleaseDate    = DateTime.Now;
     post.LastEditedDate = DateTime.Now;
     _context.Posts.Add(post);
     _context.SaveChanges();
 }
Esempio n. 2
0
        public void AddPosts(Posts post)
        {
            try
            {
                _bloggingDBContext.Posts.Add(post);

                _bloggingDBContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 3
0
        public void AddAuthor(Author author)
        {
            try
            {
                _bloggingDBContext.Author.Add(author);

                _bloggingDBContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 public void AddCommentToPost([FromBody] Comments comment)
 {
     comment.ReleaseDate = DateTime.Now;
     comment.Edited      = false;
     _context.Comments.Add(comment);
     _context.SaveChanges();
 }
Esempio n. 5
0
        public IActionResult Post([FromBody] Comments comments)
        {
            if (comments == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
            try
            {
                _bloggingDBContext.Comments.Add(comments);

                _bloggingDBContext.SaveChanges();
                return(StatusCode(StatusCodes.Status201Created));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Esempio n. 6
0
 public RequestStatus AddUser([FromBody] Users user)
 {
     try
     {
         user.PasswordHash = _hasher.HashString(user.PasswordHash);
         _context.Users.Add(user);
         _context.SaveChanges();
     } catch (DbUpdateException ex)
     {
         if (ex.InnerException.Message.Contains("UNIQUE"))
         {
             return(new RequestStatus {
                 Status = -1, Message = "specyfic email already egsists"
             });
         }
     }
     return(new RequestStatus {
         Status = 1, Message = "account created"
     });
 }
 public Users AddUser(Users user)
 {
     _context.Users.Add(user);
     _context.SaveChanges();
     return(user);
 }