public IActionResult Create() { var model = new NewsItemCreateViewModel() { Title = "Create A News Item" }; return(View(model)); }
public async Task <IActionResult> Create(NewsItemCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } await _NewsItemsService.InsertNewsItemAsync(model); return(RedirectToAction("List")); }
public async Task <NewsItem> InsertNewsItemAsync(NewsItemCreateViewModel model) { var newNewsItem = new NewsItem() { Article = model.Article, AuthorFirstName = model.AuthorFirstName, AuthorMiddleName = model.AuthorMiddleName, AuthorLastName = model.AuthorLastName, Createdon = DateTime.Now, Headline = model.Headline, IsPinned = model.IsPinned, IsVisible = model.IsVisible, PublishStart = model.PublishStart, PublishStop = model.PublishStop }; _NewsItemsRepository.Insert(newNewsItem); await _NewsItemsRepository.SaveChangesAsync(); return(newNewsItem); }