public void CreateCourse(Course course)
 {
     try
     {
         database.GetCollection<Course>("courses").InsertOneAsync(course);
     }
     catch (Exception exception)
     {
         throw new Exception("Error during new course creating", exception);
     }
 }
 public ActionResult AddLOsToCourse(Course course)
 {
     string stringOfLoIds = Request["selectedIds"];
     if (!stringOfLoIds.IsEmpty())
     {
         List<string> listOfLoIds = stringOfLoIds.Split(',').ToList();
         foreach (var id in listOfLoIds)
         {
             //var lo = db.GetLOByID(id);
             var lo = _dbContext.LOs.Find(x => x.Id == ObjectId.Parse(id)).ToListAsync().Result;
             if (lo != null)
             {
                 course.AddLo(ObjectId.Parse(id));
             }
         }
     }
     return View("ManualCourseCreating", course);
 }
 public ActionResult ManualCourseCreating(Course course)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _dbContext.Courses.InsertOneAsync(course);
             //db.CreateCourse(course);
             //MessageOnPage msg = new MessageOnPage("Succes", "Course succesfully added to DB");
             return RedirectToAction("CoursesList", "Home");
         }
         catch (Exception ex)
         {
             string exceptionMessage = ex.Message;
             string wholeMessage = @"<script language=""javascript"">alert('\n" + "Error during saving to database\n" + exceptionMessage + @"\n')</script>";
             Response.Write(wholeMessage);
         }
     }
     return View(course);
 }
 public ActionResult ManualCourseCreating()
 {
     Course course = new Course();
     return View(course);
 }
        public ActionResult DeleteLoFromCourse(Course course)
        {
            string stringOfLoId = Request["loidtodelete"];
            for(int i = 0; i < course.ListOfLosId.Count; i++)
            {
                if (course.ListOfLosId[i].ToString() == stringOfLoId)
                {
                    course.ListOfLosId.RemoveAt(i);
                    break;
                }
            }

            return View("ManualCourseCreating", course);
        }
 public void EditCourse(Course course)
 {
     try
     {
         database.GetCollection<Course>("courses").ReplaceOneAsync(a => a.Id == course.Id, course);
     }
     catch (Exception exception)
     {
         throw new Exception("Error during course edit", exception);
     }
 }