public IActionResult Create(Topic topic) { if (ModelState.IsValid) { _repository.AddTopic(topic); return RedirectToAction("Index"); } return View(topic); }
public static void Initialize(IServiceProvider serviceProvider) { var context = serviceProvider.GetService<ApplicationDbContext>(); context.Database.Migrate(); if (!context.Topic.Any()) { var topicOne = new Topic() {TopicName = "City", TopicCategory = "Tourism"}; var topicTwo = new Topic() { TopicName = "Direction", TopicCategory = "Life" }; var topicThree = new Topic() { TopicName = "Wedding", TopicCategory = "Parties" }; context.Topic.AddRange( topicOne, topicTwo, topicThree ); context.SaveChanges(); } }
public void UpdateTopic(Topic topic) { _context.Update(topic); _context.SaveChanges(); }
public void AddTopic(Topic topic) { _context.Topic.Add(topic); _context.SaveChanges(); }