Esempio n. 1
0
        public IActionResult LoadLatest()
        {
            var _articles = _articleService.Search(x => true).Take(4).OrderByDescending(x => x.CreatedOn).ToList();

            var _articleList = new List <ArticleViewModel>();

            foreach (var _article in _articles)
            {
                var _author = _authorService.Search(x => x.AuthorId == _article.AuthorId).FirstOrDefault();
                var shares  = _shareService.Search(x => x.ArticleId == _article.Id.ToString());
                var _tag    = _tagService.Search(x => x.TagId == _article.TagIds).FirstOrDefault();
                _articleList.Add(new ArticleViewModel
                {
                    Author     = _author != null ? _author.FirstName + " " + _author.LastName : "Niche",
                    Body       = _article.Body,
                    Id         = _article.Id,
                    ImageURl   = _article.ImageURl,
                    Tags       = _tag.Name,
                    Title      = _article.Title,
                    Duration   = _article.CreatedOn.GetRelativetime(),
                    ShareCount = shares.Count()
                });
            }

            return(Ok(_articleList));
        }
Esempio n. 2
0
        public IActionResult Load(int id)
        {
            var _author = _authorService.Search(x => x.Id == id).FirstOrDefault();

            var author = new AuthorViewModel
            {
                AddedOn   = _author.CreatedOn.GetRelativetime(),
                FirstName = _author.FirstName,
                LastName  = _author.LastName,
                Id        = _author.Id,
                index     = 0
            };

            return(Ok(author));
        }
Esempio n. 3
0
        public IActionResult Delete(int id)
        {
            var _author = _authorService.Get(id);

            var _articles = _articleService.Search(x => x.AuthorId == _author.AuthorId);

            if (_articles.Count() > 0)
            {
                foreach (var _article in _articles)
                {
                    _article.AuthorId = default;
                    _articleService.Update(_article);
                }
            }

            try
            {
                _logger.Log(Niche.Core.Enums.LogLevel.INFORMATION, $"Delete: {_author.ToJson()} on {DateTime.UtcNow} UTC time");

                _authorService.Delete(_author);

                return(Ok(new { check = true, message = "Author has been deleted successfully" }));
            }
            catch (Exception ex)
            {
                _logger.Log(Niche.Core.Enums.LogLevel.ERROR, ex.Message + ex.InnerException != null ? $" ,InnerException: {ex.InnerException.Message}" : "");
                return(Ok(new { check = false, message = "Failed, try again" }));
            }
        }
Esempio n. 4
0
        public IActionResult LoadAll(string articleId)
        {
            var _comments = _commentService.Search(x => x.ArticleId == articleId).OrderByDescending(x => x.CreatedOn);

            var commentViewList = new List <CommentViewModel>();
            var index           = 0;

            foreach (var _comment in _comments)
            {
                index++;
                commentViewList.Add(new CommentViewModel
                {
                    Email        = _comment.Email,
                    Message      = _comment.Message,
                    Name         = _comment.Name,
                    Subject      = _comment.Subject,
                    DateDuration = _comment.CreatedOn.GetRelativetime(),
                    Index        = index,
                    IsApproved   = _comment.IsApproved,
                    Id           = _comment.Id
                });
            }


            return(Ok(commentViewList));
        }
Esempio n. 5
0
        public IActionResult ViewArticle(int id)
        {
            var _article = _articleService.Get(id);

            _session.SetString("aId", _article.ArticleId);

            var _comments = _commentService.Search(x => x.ArticleId == _article.ArticleId).OrderBy(x => x.CreatedOn).ToList();
            var shares    = _shareService.Search(x => x.ArticleId == _article.Id.ToString());
            var _author   = _authorService.Search(x => x.AuthorId == _article.AuthorId).FirstOrDefault();

            var _articleViewModel = new ArticleViewModel
            {
                Author     = _author != null ? _author.FirstName + " " + _author.LastName : "Niche",
                Body       = _article.Body,
                Id         = _article.Id,
                ImageURl   = _article.ImageURl,
                Tags       = _article.TagIds,
                Title      = _article.Title,
                Duration   = _article.CreatedOn.GetRelativetime(),
                ShareCount = shares.Count()
            };

            var _commentList = new List <CommentViewModel>();

            foreach (var _comment in _comments)
            {
                if (_comment.IsApproved)
                {
                    _commentList.Add(new CommentViewModel
                    {
                        Email        = _comment.Email,
                        Message      = _comment.Message,
                        Name         = _comment.Name,
                        Subject      = _comment.Subject,
                        DateDuration = _comment.CreatedOn.GetRelativetime(),
                        IsApproved   = _comment.IsApproved,
                        Index        = _commentList.Count + 1
                    });
                }
            }
            _articleViewModel.Comments = _commentList;

            return(View(_articleViewModel));
        }
Esempio n. 6
0
        public IActionResult LoadAbouts()
        {
            var _abouts    = _aboutService.Search(x => true).OrderByDescending(x => x.CreatedOn).OrderByDescending(x => x.CreatedOn);
            var _aboutList = new List <AboutViewModel>();

            foreach (var _about in _abouts)
            {
                _aboutList.Add(new AboutViewModel
                {
                    Body       = _about.Body,
                    Index      = _aboutList.Count + 1,
                    Id         = _about.Id,
                    IsSelected = _about.IsSelected ? "active" : "-",
                    Title      = _about.Title,
                    AddedOn    = _about.CreatedOn.GetRelativetime()
                });
            }
            return(Ok(_aboutList));
        }
Esempio n. 7
0
        public IActionResult LoadAll()
        {
            var _tagList = new List <TagViewModel>();
            var index    = 0;
            var _tags    = _tagService.Search(x => true).OrderByDescending(x => x.CreatedOn);

            foreach (var _tag in _tags)
            {
                index++;
                _tagList.Add(new TagViewModel
                {
                    AddedOn = _tag.CreatedOn.GetRelativetime(),
                    Name    = _tag.Name,
                    Id      = _tag.Id,
                    Index   = index
                });
            }

            return(Ok(_tagList));
        }
        public IActionResult Login(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(Ok(new { check = false, message = "Provide both username and password" }));
            }

            var _accounts = _accountService.Search(x => x.Username == username && x.Password == password);

            if (_accounts.Count() == 0)
            {
                return(Ok(new { check = false, message = "Wrong username or password" }));
            }

            var _account = _accounts.FirstOrDefault();

            _session.SetString("account", (new AccountViewModel
            {
                Name = _account.Name,
                Username = _account.Username
            }).ToJson());

            return(Ok(new { check = true, message = $"Hello {_account.Name}, we are redirecting you..." }));
        }
Esempio n. 9
0
        public IActionResult About()
        {
            var _about = _aboutService.Search(x => x.IsSelected).FirstOrDefault();

            return(View(_about));
        }