コード例 #1
0
        //Admin only, Accessible from CourseController since Lecturecises are always added to a course
        public async Task <string> CreateAsync(LectureciseCreateBindingModel lecturecise)
        {
            var newLecturecise = Mapper.Map <Lecturecise>(lecturecise);

            await this.lectureciseRepository.AddAsync(newLecturecise);

            await this.lectureciseRepository.SaveChangesAsync();

            return(newLecturecise.Id);
        }
コード例 #2
0
        public async Task <IActionResult> AddLecturecise(LectureciseCreateBindingModel lectureciseModel)
        {
            if (!this.ModelState.IsValid)
            {
                this.View(lectureciseModel);
            }

            var newLectureciseId = await this.lectureciseService.CreateAsync(lectureciseModel);

            if (lectureciseModel.EducatorIds != null || lectureciseModel.Day1 != null || lectureciseModel.Day2 != null)
            {
                var lecturecise = this.lectureciseService.GetByOriginal(newLectureciseId);

                if (lectureciseModel.EducatorIds != null)
                {
                    var course = this.courseService.GetByIdOriginal(lectureciseModel.CourseId);

                    foreach (var educatorId in lectureciseModel.EducatorIds)
                    {
                        lecturecise.LectureciseEducators.Add(new EducatorLecturecise()
                        {
                            EducatorId = educatorId, LectureciseId = lecturecise.Id
                        });

                        //Add the Educators to the course if not added previously.
                        if (course != null && !course.CourseEducators.Any(ce => ce.EducatorId == educatorId))
                        {
                            course.CourseEducators.Add(new EducatorCourse()
                            {
                                EducatorId   = educatorId,
                                CourseId     = course.Id,
                                TeachingRole = lectureciseModel.Type == LectureciseType.Lecture ? TeachingRole.Lecturer : TeachingRole.Assistant
                            });
                        }
                    }
                }

                if (lectureciseModel.Day1 != null && lectureciseModel.StartTime1 != null)
                {
                    var weekTime1 = new WeekTime()
                    {
                        DayOfWeek = lectureciseModel.Day1.Value, StartHour = lectureciseModel.StartTime1.Value.TimeOfDay.ToString()
                    };

                    if (lectureciseModel.EndTime1 != null)
                    {
                        weekTime1.EndHour = lectureciseModel.EndTime1.Value.TimeOfDay.ToString();
                    }

                    lecturecise.WeekTimes.Add(weekTime1);
                }

                if (lectureciseModel.Day2 != null && lectureciseModel.StartTime2 != null)
                {
                    var weekTime2 = new WeekTime()
                    {
                        DayOfWeek = lectureciseModel.Day2.Value, StartHour = lectureciseModel.StartTime2.Value.TimeOfDay.ToString()
                    };

                    if (lectureciseModel.EndTime2 != null)
                    {
                        weekTime2.EndHour = lectureciseModel.EndTime1.Value.TimeOfDay.ToString();
                    }

                    lecturecise.WeekTimes.Add(weekTime2);
                }

                await this.lectureciseService.SaveLecturecises();

                //await this.lectureciseService.EditLecturecise(lecturecise);
            }

            return(RedirectToAction("AddLecturecise", new { courseId = lectureciseModel.CourseId }));
        }