예제 #1
0
 public IActionResult Create(Topic topic)
 {
     if (ModelState.IsValid)
     {
         _repository.AddTopic(topic);
         return RedirectToAction("Index");
     }
     return View(topic);
 }
예제 #2
0
        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();
            }

        }
예제 #3
0
 public void UpdateTopic(Topic topic)
 {
     _context.Update(topic);
     _context.SaveChanges();
 }
예제 #4
0
 public void AddTopic(Topic topic)
 {
     _context.Topic.Add(topic);
     _context.SaveChanges();
 }