Advertisement
ivaylokenov

Untitled

Nov 18th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. public class ArticleService : IArticleService
  2. {
  3.         private readonly BlogDbContext db;
  4.         private readonly IDateTimeProvider dateTimeProvider;
  5.  
  6.         public ArticleService(
  7.             BlogDbContext db,
  8.             IDateTimeProvider dateTimeProvider)
  9.         {
  10.             this.db = db;
  11.             this.dateTimeProvider = dateTimeProvider;
  12.         }
  13.  
  14.         public async Task<int> Add(string title, string content, string userId)
  15.         {
  16.             var article = new Article
  17.             {
  18.                 Title = title,
  19.                 Content = content,
  20.                 UserId = userId,
  21.                 PublishedOn = this.dateTimeProvider.Now();  
  22.             };
  23.  
  24.             this.db.Articles.Add(article);
  25.  
  26.             await this.db.SaveChangesAsync();
  27.  
  28.             return article.Id;
  29.         }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement