Esempio n. 1
0
        public ArticlePublishResponse Publish(User publisher, Article article)
        {
            DataWriteResult result = _articleRepository.Create(publisher, article);

            ArticlePublishResponse response = result.Success ? ResponseBase.SuccessResponse() : ResponseBase.FailureResponse();
            return response;
        }
Esempio n. 2
0
        public ArticlePublishResponse LikeArticle(User user, Article article)
        {
            DataWriteResult result = _articleRepository.Like(user, article);

            ArticlePublishResponse response = result.Success ? ResponseBase.SuccessResponse() : ResponseBase.FailureResponse();
            return response;
        }
Esempio n. 3
0
 public DataWriteResult Delete(User publisher, Article article)
 {
     try
     {
         User dbPublisher = _context.Users.First(u => u.Id == publisher.Id && u.Role == Role.Publisher);
         Article dbArticle = _context.Articles.FirstOrDefault(a => a.Id == article.Id);
         _context.Articles.Remove(dbArticle);
         _context.SaveChanges();
         return DataWriteResult.SuccessResult();
     }
     catch (Exception exception)
     {
         return DataWriteResult.FailureResult(exception);
     }
 }
Esempio n. 4
0
 public DataWriteResult Create(User publisher, Article article)
 {
     try
     {
         User dbPublisher = _context.Users.First(u => u.Id == publisher.Id && u.Role == Role.Publisher);
         article.Publisher = dbPublisher;
         _context.Articles.Add(article);
         _context.SaveChanges();
         return DataWriteResult.SuccessResult();
     }
     catch (Exception exception)
     {
         return DataWriteResult.FailureResult(exception);
     }
 }
 public DataWriteResult Like(User user, Article article)
 {
     DataWriteResult response;
     if (user.Likes > 0)
     {
         article.Likes += 1;
         user.Likes -= 1;
         response = DataWriteResult.SuccessResult();
     }
     else
     {
         response = DataWriteResult.FailureResult(new Exception("Insufficient likes remaining"));
     }
     return response;
 }
 public DataWriteResult Create(User publisher, Article article)
 {
     DataWriteResult response;
     if (article.Author == null)
     {
         response = DataWriteResult.FailureResult(new Exception("Authour null"));
     }
     else
     {
         _articles.Add(article);
         response = DataWriteResult.SuccessResult();
     }
     _articles.Add(article);
     return response;
 }
Esempio n. 7
0
 public DataWriteResult Like(User user, Article article)
 {
     try
     {
         if (user.Likes > 0)
         {
             var articleDb = _context.Articles.Include(a => a.Author).Include(p => p.Publisher).First(a => a.Id == article.Id);
             var userDb = _context.Users.First(u => u.Id == user.Id);
             articleDb.Likes += 1;
             userDb.Likes -= 1;
             _context.SaveChanges();
             return DataWriteResult.SuccessResult();
         }
         return DataWriteResult.FailureResult(new Exception("Insufficient likes remaining"));
     }
     catch (Exception exception)
     {
         return DataWriteResult.FailureResult(exception);
     }
 }
Esempio n. 8
0
        public void Initilise()
        {
            _author = new Author
            {
                Id = 1,
                Name = "Fake Author 1"
            };

            _publisher = new User
            {
                Id = 1,
                Username = "******",
                Name = "Fake Publisher 1",
                Password = "******",
                Role = Role.Publisher
            };

            _employee = new User
            {
                Id = 1,
                Username = "******",
                Name = "Fake Employee 1",
                Password = "******",
                Role = Role.Employee,
                Likes = 10
            };

            var articles = new List<Article>
            {
                new Article { Id = 1, Title = "News Article 1", Author = _author, Body = "This is a sample body for News Article 1", ArticleType = ArticleType.News, PublishDate = DateTime.Now, Likes = 2},
                new Article { Id = 2, Title = "News Article 2", Author = _author, Body = "This is a sample body for News Article 2", ArticleType = ArticleType.News, PublishDate = DateTime.Now , Likes = 48},
                new Article { Id = 3, Title = "Technology Article 1", Author = _author, Body = "This is a sample body for Technology Article 1", ArticleType = ArticleType.Technology, PublishDate = DateTime.Now , Likes = 0}
            };
            IArticleRepository articleRepository = new FakeArticleRepository(articles, new List<Author>() { _author });
            _articleManager = new ArticleManager(articleRepository);
        }
 public DataWriteResult Update(User publisher, Article article)
 {
     throw new NotImplementedException();
 }
 public static AuthenticationResponse SuccessfulLogin(User user)
 {
     return new AuthenticationResponse { Success = true, ResponseType = LoginResponseType.Success, LoggedInUser = user };
 }
 public void Initilise()
 {
     _context = new NewsPortalContext();
     _articleRepository = new ArticleRepository(_context);
     publisher = _context.Users.First(u => u.Role == Role.Publisher);
 }