Пример #1
0
 public ActionResult Create(CourseViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var repository = new CourseRepository(context);
             var course     = MapperHelper.Map <Course>(model);
             course.Topics = new List <Topic>();
             var topicRepo = new TopicRepository(context);
             foreach (var topicId in model.SelectedTopics)
             {
                 course.Topics.Add(topicRepo.Find(topicId));
             }
             repository.Insert(course);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             model.AvailableTopics = LoadTopics();
             return(View(model));
         }
     }
     catch (Exception ex)
     {
         return(View(model));
     }
 }
Пример #2
0
        // GET: Topic/Details/5
        public ActionResult Details(int id)
        {
            var repository = new TopicRepository(context);
            var topic      = repository.Find(id);
            var model      = MapperHelper.Map <TopicViewModel>(topic);

            return(View(model));
        }
Пример #3
0
        // GET: Topic/Edit/5
        public ActionResult Edit(int id)
        {
            var repository = new TopicRepository(context);
            var topic      = repository.Find(id);
            var model      = MapperHelper.Map <EditTopicViewModel>(topic);

            model.NombreAnterior = model.Name;
            return(View(model));
        }