public IActionResult ChangeName(string name, int id)
        {
            var _account = _accountService.Get(id);

            if (_account == null)
            {
                return(Ok(new { check = false, message = "Account does not exist" }));
            }

            if (string.IsNullOrEmpty(name))
            {
                return(Ok(new { check = false, message = "The account name can not be empty" }));
            }

            _account.Name = name;
            try
            {
                _accountService.Update(_account);
                _logger.Log(Niche.Core.Enums.LogLevel.INFORMATION, $"Account-name: {_account.ToJson()} was updated on {DateTime.UtcNow} UTC");
                return(Ok(new { check = true, message = "Name was changed 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 to update" }));
            }
        }
Esempio n. 2
0
        public IActionResult Approve(int id)
        {
            var _comment = _commentService.Get(id);

            if (_comment != null)
            {
                _comment.IsApproved = true;
                _commentService.Update(_comment);
                return(Ok(new { check = true, message = "Comment has been approved" }));
            }
            return(NotFound(new { message = "Comment not found" }));
        }
Esempio n. 3
0
        public IActionResult Load(int id)
        {
            var _tag = _tagService.Get(id);

            var tag = new TagViewModel
            {
                AddedOn = _tag.CreatedOn.GetRelativetime(),
                Name    = _tag.Name,
                Id      = _tag.Id,
                Index   = 0
            };

            return(Ok(_tag));
        }
Esempio n. 4
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. 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 AddArticle(NewArticleViewModel articleModel)
        {
            if (!ModelState.IsValid)
            {
                var _errors = new List <string>();
                foreach (var _values in ModelState.Values)
                {
                    foreach (var _error in _values.Errors)
                    {
                        _errors.Add(_error.ErrorMessage);
                    }
                }
                return(Ok(new { check = false, message = string.Join(",  ", _errors) }));
            }

            string url = "";

            if (articleModel.File != null)
            {
                bool check;
                (check, url) = ImageHelper.SaveImage(articleModel.File, _webHostEnvironment);
                if (!check)
                {
                    if (url != null)
                    {
                        _logger.Log(Niche.Core.Enums.LogLevel.ERROR, url);
                    }

                    return(Ok(new { check = false, message = "Image could not be saved, try again later" }));
                }
            }

            try
            {
                var _author  = _authorService.Get(int.Parse(articleModel.AuthorId));
                var _tag     = _tagService.Get(int.Parse(articleModel.TagIds));
                var _article = _articleService.Add(new Article
                {
                    Id        = Support.GetID(),
                    AuthorId  = _author.AuthorId,
                    Body      = articleModel.Content,
                    CreatedOn = DateTime.UtcNow,
                    ImageURl  = url,
                    TagIds    = _tag.TagId,
                    Title     = articleModel.Title
                });

                return(Ok(new { check = true, message = "The article was successfully saved" }));
            }
            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 to save" }));
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> Index(string id)
        {
            var book = await _libraryService.Get(id);

            if (book == default)
            {
                ViewData["Error"] = "File not found";
            }

            return(View(book));
        }
Esempio n. 8
0
        public async Task <IActionResult> SaveAbout(AboutViewModel model)
        {
            if (model.EducationLevel == default)
            {
                return(Ok(new
                {
                    code = -1,
                    message = "Select highest level of education"
                }));
            }

            if (model.EducationLevel != Education.STAY_AT_HOME)
            {
                if (model.EducationClass == default)
                {
                    return(Ok(new
                    {
                        code = -1,
                        message = "Select the class you are attending"
                    }));
                }
            }

            var user = await _userService.Get(User.GetUserId());

            user.Address     = model.Address;
            user.Occupation  = model.Occupation;
            user.DateOfBirth = model.Dob;
            user.Education   = model.EducationLevel;
            user.ClassId     = model.EducationClass;

            Session.SetString("user", user.ToJson());

            return(Ok(new
            {
                code = 0
            }));
        }
Esempio n. 9
0
        public IActionResult DeleteAbout(int id)
        {
            var about = _aboutService.Get(id);

            if (about.IsSelected)
            {
                return(Ok(new { check = false, message = "Please, this about is active, first set another as active then delete." }));
            }

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

                _aboutService.Delete(about);

                return(Ok(new { check = true, message = "About text 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" }));
            }
        }