Beispiel #1
0
        public async Task <ClassLesson> CreateLesson(ClassLesson lesson)
        {
            var tokenResponse = await _tokenService.GetToken("teachingapi.read");

            _httpClient
            .SetBearerToken(tokenResponse.AccessToken);

            _httpClient.BaseAddress = new Uri("https://localhost:5449/");

            var request = new HttpRequestMessage(HttpMethod.Post, $"ClassLessons");

            request.Content = new StringContent(JsonConvert.SerializeObject(lesson), System.Text.Encoding.UTF8, "application/json");

            var response = await _httpClient.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                var readTask = response.Content.ReadAsAsync <ClassLesson>();
                readTask.Wait();

                return(readTask.Result);
            }
            else
            {
                throw new Exception("Unable to get content");
            }
        }
        public ClassLessonEditViewModel Update(ClassLessonEditViewModel ClassLessonEditViewModel)
        {
            ClassLesson ClassLesson = ClassLessonRepo.Update(ClassLessonEditViewModel.ToModel());

            unitOfWork.commit();
            return(ClassLesson.ToEditableViewModel());
        }
Beispiel #3
0
        public async Task <ClassLesson> UpdateLesson(ClassLesson lesson)
        {
            var tokenResponse = await _tokenService.GetToken("teachingapi.read");

            _httpClient
            .SetBearerToken(tokenResponse.AccessToken);

            _httpClient.BaseAddress = new Uri("https://localhost:5449/");

            var request = new HttpRequestMessage(HttpMethod.Put, $"ClassLessons/{lesson}");

            request.Content = JsonContent.Create <ClassLesson>(lesson);

            var response = await _httpClient.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                var readTask = response.Content.ReadAsAsync <ClassLesson>();
                readTask.Wait();

                return(readTask.Result);
            }
            else
            {
                throw new Exception("Unable to get content");
            }
        }
 public IActionResult PostClassLesson([FromBody] ClassLesson lesson)
 {
     using (var scope = new TransactionScope())
     {
         _lessonRepository.Add(lesson);
         scope.Complete();
         return(CreatedAtAction(nameof(GetClassLesson), new { id = lesson.LessonId }, lesson));
     }
 }
        public async Task <IActionResult> Create(ClassLesson lesson)
        {
            if (ModelState.IsValid)
            {
                await apiClient.CreateLesson(lesson);

                return(RedirectToAction("Index"));
            }
            return(View(lesson));
        }
Beispiel #6
0
        public static ClassLessonEditViewModel ToEditableViewModel(this ClassLesson Model)
        {
            return(new ClassLessonEditViewModel()
            {
                ID = Model.ID,

                SubjectID = Model.SubjectID,
                LessonID = Model.LessonID,
                TeacherID = Model.TeacherID,
                ClassDayID = Model.ClassDayID,
            });
        }
        public IActionResult PutClassLesson([FromBody] ClassLesson lesson)
        {
            if (lesson != null)
            {
                using (var scope = new TransactionScope())
                {
                    _lessonRepository.Update(lesson);
                    scope.Complete();
                    return(new OkResult());
                }
            }

            return(new NoContentResult());
        }
Beispiel #8
0
 public static ClassLessonViewModel ToViewModel(this ClassLesson Model)
 {
     return(new ClassLessonViewModel()
     {
         ID = Model.ID,
         ClassDayID = Model.ClassDayID,
         ClassDay = Model.ClassDay.ToViewModel(),
         TeacherID = Model.TeacherID,
         Teacher = Model.Teacher.ToViewModel(),
         LessonID = Model.LessonID,
         Lesson = Model.Lesson.ToViewModel(),
         SubjectID = Model.SubjectID,
         Subject = Model.Subject.ToViewModel(),
     });
 }
Beispiel #9
0
        public void Update(ClassLesson lesson)
        {
            var update = _dbContext.ClassLessons
                         .Where(update => update.LessonId.Equals(lesson.LessonId))
                         .SingleOrDefault();

            if (update != default(ClassLesson))
            {
                update.Name        = lesson.Name;
                update.ClassName   = lesson.ClassName;
                update.Description = lesson.Description;
            }

            Save();
        }
Beispiel #10
0
 public void Add(ClassLesson lesson)
 {
     _dbContext.Add(lesson);
     Save();
 }
Beispiel #11
0
        public ActionResult AddClass(int lessonId, int classId)
        {
            //1. Create new ClassLesson
            var les = db.Lessons.Find(lessonId);
            var cls = db.Classes.Find(classId);

            if (les != null && cls != null)
            {
                var newClsLes = new ClassLesson
                {
                    Class  = cls,
                    Lesson = les
                };

                db.ClassLessons.Add(newClsLes);

                var students = db.Students
                               .Where(s => s.Class.Id == classId)
                               .ToList();

                //2. Create StudentLesson for all students in the class
                foreach (var stu in students)
                {
                    var newStuLes = new StudentLesson
                    {
                        Student = stu,
                        Lesson  = les
                    };

                    db.StudentLessons.Add(newStuLes);

                    //3. Create StudentGroup for all students in the class
                    var groups = db.Groups
                                 .Where(g => g.Lesson.Id == lessonId)
                                 .ToList();

                    foreach (var grp in groups)
                    {
                        var newStuGrp = new StudentGroup
                        {
                            Student = stu,
                            Group   = grp
                        };

                        db.StudentGroups.Add(newStuGrp);

                        //4. Create StudentVocabulary for all students in the class
                        var vocabularies = db.Vocabularies
                                           .Where(v => v.Group.Id == grp.Id)
                                           .ToList();

                        foreach (var voca in vocabularies)
                        {
                            var newStuVocabulary = new StudentVocabulary
                            {
                                Student     = stu,
                                Vocabulary  = voca,
                                UpdatedDate = DateTime.Now
                            };

                            db.StudentVocabularies.Add(newStuVocabulary);
                        }
                    }
                }



                db.SaveChanges();
            }

            return(RedirectToAction("Details", new { Id = lessonId }));
        }
        public async Task <IActionResult> Edit(ClassLesson lesson)
        {
            await apiClient.UpdateLesson(lesson);

            return(RedirectToAction("Index"));
        }