public async Task <IActionResult> Create([Bind("Id,Name")] Tag tag) { if (ModelState.IsValid) { _context.Add(tag); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tag)); }
public async Task <IActionResult> Create([Bind("Id,Name,Slug")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("Id,Name,CountryId")] City city) { if (ModelState.IsValid) { _context.Add(city); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CountryId"] = new SelectList(_context.Countries, "Id", "Name", city.CountryId); return(View(city)); }
public async Task <IActionResult> Create([Bind("Id,Text,PostId,UserId")] Comment comment) { if (ModelState.IsValid) { _context.Add(comment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PostId"] = new SelectList(_context.Posts, "Id", "Text", comment.PostId); ViewData["UserId"] = new SelectList(_context.Users, "Id", "Email", comment.UserId); return(View(comment)); }
public async Task <IActionResult> Create(PostVM viewmodel) { if (viewmodel.Post == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest()); } Post post = viewmodel.Post; post.CreatedAt = DateTime.Now; _context.Add(post); await _context.SaveChangesAsync(); // _logger.LogInformation("viewmodel.SelectedTags {0}", viewmodel.SelectedTags); if (!(viewmodel.SelectedTags is null)) { List <PostTag> postTags = new List <PostTag>(); foreach (var postTagId in viewmodel.SelectedTags) { postTags.Add(new PostTag { TagId = postTagId, PostId = post.Id }); } _logger.LogInformation($"postTags {postTags}"); post.PostTags = postTags; await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); }
public void Store(Country country) { _context.Add(country); }