/// <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)); }
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")); }
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; } } }
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)); }
public async Task CreateNewsItem(NewsItem entity) { await _NewsRepository.AddAsync(entity); }
public async Task <int> AddAsync(News news) => await newsRepository.AddAsync(news);
public async Task ModelTest() { var model = TempModel; await _newsRepository.AddAsync(model); Assert.True(model.Id > 0); }