Пример #1
0
 public LearnerGroupCourseController(ablemusicContext ablemusicContext, ILogger <LearnerGroupCourseController> log, IMapper mapper) : base(ablemusicContext, log)
 {
     _mapper = mapper;
     _logger = log;
     _lessonGenerateService      = new LessonGenerateService(_ablemusicContext, _mapper);
     _groupCourseGenerateService = new GroupCourseGenerateService(_ablemusicContext, _logger);
 }
Пример #2
0
        public async Task <IActionResult> TestGroupCourseGenerate(short termId)
        {
            var _groupCourseGenerateService = new GroupCourseGenerateService(_ablemusicContext, _logger);
            var result = await _groupCourseGenerateService.GenerateLessons(termId);

            return(Ok(result));
        }
Пример #3
0
        public async Task <IActionResult> PostgroupCourseInstance([FromBody] GroupCourseInstanceModel groupinstance)
        {
            Result <string> result = new Result <string>();

            try
            {
                if (_ablemusicContext.Course.FirstOrDefault(s => s.CourseId == groupinstance.CourseId).CourseType != 2)
                {
                    throw new Exception("This course is not group course");
                }
                var duration = _ablemusicContext.Course.FirstOrDefault(s => s.CourseId == groupinstance.CourseId).Duration;
                for (var i = 0; i < groupinstance.CourseSchedule.Count; i++)
                {
                    groupinstance.CourseSchedule[i].EndTime =
                        GetEndTimeForOnetoOneCourseSchedule(groupinstance.CourseSchedule[i].BeginTime.Value, duration);
                }
                var newGroupInstance = new GroupCourseInstance();
                _mapper.Map(groupinstance, newGroupInstance);
                newGroupInstance.IsActivate = 1;
                _ablemusicContext.Add(newGroupInstance);
                var _groupCourseGenerateService = new GroupCourseGenerateService(_ablemusicContext, _logger);
                var today = DateTime.UtcNow.ToNZTimezone();

                var term = await _ablemusicContext.Term.Where(t => t.BeginDate <= today.Date && t.EndDate >= today.Date)
                           .FirstOrDefaultAsync();

                await _ablemusicContext.SaveChangesAsync();

                if (term != null)
                {
                    var resultGenerate = await _groupCourseGenerateService.GenerateLessons(term.TermId);
                }

                result.Data = "success";
            }
            catch (Exception ex)
            {
                result.IsSuccess    = false;
                result.ErrorMessage = ex.Message;
                return(BadRequest(result));
            }

            return(Ok(result));
        }