Beispiel #1
0
        public ActionResult Create(TrainerLessonCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var lesson = new Lesson
                {
                    Title = viewModel.Title,
                    AuthorId = (int)Membership.GetUser().ProviderUserKey,
                    Content = viewModel.Content,
                    CreationDate = DateTime.Now,
                    SubcategoryId = viewModel.SubcategoryId,
                };
                lessonService.CreateLesson(lesson);
                return Redirect("/trainer/lesson");
            }

            var userId = (int)Membership.GetUser().ProviderUserKey;
            var groups = groupService.GetGroupsByTrainerId(userId);
            viewModel.Groups = new SelectList(groups, "Id", "Name");
            return View(viewModel);
        }
Beispiel #2
0
 /// <summary>
 /// Edits lesson
 /// </summary>
 /// <param name="lesson">The lesson to be edited</param>
 public void EditLesson(Lesson lesson)
 {
     lessonRepo.Update(lesson);
     lessonRepo.Save();
 }
Beispiel #3
0
 /// <summary>
 /// Creates lesson
 /// </summary>
 /// <param name="lesson">The lesson to be created</param>
 public void CreateLesson(Lesson lesson)
 {
     lessonRepo.Add(lesson);
     lessonRepo.Save();
 }
Beispiel #4
0
 public ActionResult Edit(int id, TrainerLessonEditViewModel viewModel)
 {
     if (viewModel.Id == id)
     {
         if (ModelState.IsValid)
         {
             var getLesson = lessonService.GetLesson(id);
             var lesson = new Lesson
             {
                 Id = viewModel.Id,
                 Title = viewModel.Title,
                 Content = viewModel.Content,
                 CreationDate = getLesson.CreationDate,
             };
             lessonService.EditLesson(lesson);
             return Redirect("/trainer/lesson");
         }
         return View(viewModel);
     }
     else
     {
         throw new Exception("Dont do this");
     }
 }
 public void Update(Lesson item)
 {
     var temp = this.setList.Where(x => x.Id == item.Id).First();
     this.setList.Remove(temp);
     this.setList.Add(item);
 }
 public void Delete(Lesson item)
 {
     this.setList.Remove(item);
 }
 public void Add(Lesson item)
 {
     this.setList.Add(item);
 }