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 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. 3
0
        public IActionResult SaveAbout(AboutViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                string message = "";
                var    _errors = new List <string>();
                foreach (var _values in ModelState.Values)
                {
                    foreach (var _error in _values.Errors)
                    {
                        _errors.Add(_error.ErrorMessage);
                    }
                }
                message = string.Join(", ", _errors);
                return(Ok(new { check = false, message }));
            }

            var _abouts = _aboutService.Search(x => x.IsSelected);

            foreach (var about in _abouts)
            {
                about.IsSelected = false;
                _aboutService.Update(about);
            }


            var _about = new About
            {
                IsSelected = true,
                Id         = Support.GetID(),
                Body       = viewModel.Body,
                Title      = viewModel.Title,
                CreatedOn  = DateTime.UtcNow
            };

            try
            {
                _aboutService.Add(_about);
                return(Ok(new { check = true, message = "About us information has been updated" }));
            }
            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 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. 5
0
        public IActionResult Edit(int id, string name)
        {
            var _tag = _tagService.Search(x => x.Id == id).FirstOrDefault();

            _tag.Name = name;

            try
            {
                _tagService.Update(_tag);
                return(Ok(new { check = true, message = "Tag has been updated 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. 6
0
        public IActionResult Edit(AuthorViewModel authorView)
        {
            var _author = _authorService.Search(x => x.Id == authorView.Id).FirstOrDefault();

            _author.FirstName = authorView.FirstName;
            _author.LastName  = authorView.LastName;

            try
            {
                _authorService.Update(_author);
                return(Ok(new { check = true, message = "Author has been updated 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. 7
0
        public async Task <IActionResult> SaveAll(string categories)
        {
            var cats = categories.Split(',')
                       .ToList();

            var user = Session.GetString("user")
                       .FromJson <User>();


            var userData = await _userService.Get(user.Id);

            userData.Address     = user.Address;
            userData.Occupation  = user.Occupation;
            userData.DateOfBirth = user.DateOfBirth;
            userData.Education   = user.Education;
            userData.ClassId     = user.ClassId;

            await _userService.Update(userData);

            foreach (var category in cats)
            {
                var following = new Follow
                {
                    Id        = Support.Id,
                    UserId    = userData.Id,
                    CreatedOn = DateTime.UtcNow,
                    LibraryId = category
                };

                await _followService.Add(following);
            }


            return(Ok(new
            {
                code = 0,
                message = "update"
            }));
        }