Пример #1
0
        public JsonResult Create([FromBody] CreateSourceViewModel source)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;

                var errors        = ModelState.Values.Where(x => x.Errors.Count > 0);
                var errorMessages = new List <string>();

                foreach (var error in errors)
                {
                    errorMessages.Add(error.Errors[0].ErrorMessage);
                }

                return(Json(errorMessages.ToArray()));
            }

            _unifyDbContext.Sources.Add(new Source()
            {
                UnifyUserId = _userManager.GetUserId(User),
                Name        = source.Name,
                Url         = source.Url,
                Tags        = source.Tags
            });

            _unifyDbContext.SaveChanges();

            return(Json("Success"));
        }
Пример #2
0
        public JsonResult MarkAllAsRead()
        {
            var articles = _unifyDbContext.Articles.Where(x => x.UnifyUserId == _userManager.GetUserId(User)).ToList();

            foreach (var article in articles)
            {
                article.State = ArticleState.Read;
            }

            _unifyDbContext.SaveChanges();

            return(Json("success"));
        }
Пример #3
0
        public IActionResult Index()
        {
            foreach (var source in _unifyDbContext.Sources.ToList())
            {
                var newArticles = _sourceSynchronizer.GetNewArticles(source).ToList();

                foreach (var article in newArticles)
                {
                    article.UnifyUserId = _userManager.GetUserId(User);
                    article.SourceId    = source.Id;
                    article.State       = ArticleState.New;

                    _unifyDbContext.Articles.Add(article);
                }
            }

            _unifyDbContext.SaveChanges();

            return(View());
        }