Пример #1
0
        /// <summary>
        /// Add News
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <NewsDto> AddNewsAsync(NewsModel model, CancellationToken token = default)
        {
            var entity = model.ToEntity();

            entity.PostDate = DateTime.Now;

            await _NewsRepository.AddAsync(entity, token);

            return(await GetNewsByIdAsync(entity.Id, token));
        }
Пример #2
0
        public async Task <IActionResult> PublishArticle(ArticleEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            IdentityUser user = await _userManager.FindByNameAsync(User.Identity.Name);

            var article = new Article(model.Title, model.Body, user.Id);

            await _newsRepository.AddAsync(article);

            return(RedirectToAction("GetMyArticles"));
        }
Пример #3
0
        public async Task <NewsViewModel> AddAsync(NewsViewModel newsViewModel)
        {
            var news = mapper.Map <News>(newsViewModel);

            using (var transaction = unitOfWork.BeginTransaction())
            {
                try
                {
                    var author = await unitOfWork.Repository <AppUser>().GetAsync(newsViewModel.AuthorId);

                    var created = DateTime.Now;

                    news.Category = await unitOfWork.Repository <Category>().GetAsync(newsViewModel.CategoryId);

                    news.Author    = author;
                    news.Created   = created;
                    news.UpdatedBy = author;
                    news.Updated   = created;

                    await newsRepository.AddAsync(news);

                    await unitOfWork.SaveChangesAsync();

                    if (!string.IsNullOrEmpty(newsViewModel.StringTags))
                    {
                        var addedTags = newsViewModel.StringTags.Split(",");
                        await AddToTagsAsync(news.Id, addedTags);

                        await unitOfWork.SaveChangesAsync();
                    }

                    transaction.Commit();

                    newsViewModel = mapper.Map <NewsViewModel>(news);

                    return(newsViewModel);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
        }
Пример #4
0
 public async Task AddAsync(NewsItem news)
 {
     await _repositoryNews.AddAsync(news);
 }
        public async Task <bool> PublishNewsAsync(NewsDto newsDto)
        {
            NewsEntity news = new NewsEntity(newsDto);

            return(await _newsRepository.AddAsync(news));
        }
Пример #6
0
 public async Task CreateNewsItem(NewsItem entity)
 {
     await _NewsRepository.AddAsync(entity);
 }
Пример #7
0
 public async Task <int> AddAsync(News news)
 => await newsRepository.AddAsync(news);
Пример #8
0
        public async Task ModelTest()
        {
            var model = TempModel;
            await _newsRepository.AddAsync(model);

            Assert.True(model.Id > 0);
        }