Ejemplo n.º 1
0
        public ActionResult RemoveTopic(TopicPostData data)
        {
            var courseInDb = _context.Courses.SingleOrDefault(p => p.Id == data.courseId);
            var topicInDb  = _context.Topics.Include("Course").SingleOrDefault(p => p.Id == data.topicId);

            if (courseInDb == null || topicInDb == null)
            {
                return(HttpNotFound());
            }

            if (topicInDb.Course == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            else
            {
                topicInDb.Course = null;
                _context.SaveChanges();

                this.AddNotification("Topic removed!", NotificationType.SUCCESS);
            }

            return(RedirectToAction("Details/" + data.courseId));
        }
Ejemplo n.º 2
0
        public ActionResult AddTopic(TopicPostData data)
        {
            var courseInDb = _context.Courses.SingleOrDefault(p => p.Id == data.courseId);
            var topicInDb  = _context.Topics.Include("Course").SingleOrDefault(p => p.Id == data.topicId);

            if (courseInDb == null || topicInDb == null)
            {
                return(HttpNotFound());
            }

            if (topicInDb.Course == null)
            {
                topicInDb.Course = courseInDb;
                _context.SaveChanges();

                this.AddNotification("Topic added!", NotificationType.SUCCESS);
            }
            else
            {
                this.AddNotification(String.Format("{0} is already added to {1}", topicInDb.Name, topicInDb.Course.Name), NotificationType.INFO);
            }

            return(RedirectToAction("Details/" + data.courseId));
        }