public async Task CreateHomeworkAsync(NewHomeworkDto homeworkDto)
        {
            _logService.LogInfo($"Start creating homework {homeworkDto.HomeworkTitle} for group with id {homeworkDto.GroupId}, subject {homeworkDto.SubjectId}");

            var number = await _repository.GetAll <HomeworkInfo>()
                         .Where(homework => homework.SubjectId == homeworkDto.SubjectId)
                         .CountAsync();

            number++;

            var dbHomework = new HomeworkInfo
            {
                SubjectId = homeworkDto.SubjectId,
                MaxPoints = homeworkDto.MaxPoints,
                Number    = number,
                Title     = homeworkDto.HomeworkTitle
            };

            _repository.Add(dbHomework);

            await _repository.SaveContextAsync();

            var studentPerformanceIds = await _repository.GetAll <StudentPerformance>()
                                        .Where(performance => performance.Subject.SubjectId == dbHomework.SubjectId)
                                        .Select(performance => performance.StudentPerformanceId)
                                        .ToListAsync();

            foreach (var studentPerformanceId in studentPerformanceIds)
            {
                _repository.Add(new HomeworkResult
                {
                    HomeworkInfoId       = dbHomework.HomeworkInfoId,
                    StudentPerformanceId = studentPerformanceId,
                    Points = 0
                });
            }

            await _repository.SaveContextAsync();

            _logService.LogInfo($"Homework {homeworkDto.HomeworkTitle} for group with id {homeworkDto.GroupId}, subject {homeworkDto.SubjectId} created");
        }
Exemplo n.º 2
0
 public async Task <ActionResult> Create(int subjectId, int groupId)
 {
     try
     {
         var homework = new NewHomeworkDto
         {
             SubjectId = subjectId,
             GroupId   = groupId,
             DataDto   = await _homeworkService.GetCreateHomeworkDataAsync(subjectId)
         };
         return(View(homework));
     }
     catch (SPCException ex)
     {
         return(View("ErrorView", new ErrorDto(ex.Message, ex.StatusCode)));
     }
     catch
     {
         return(View("Error"));
     }
 }
Exemplo n.º 3
0
        public async Task <ActionResult> Create(NewHomeworkDto homeworkDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(homeworkDto));
                }

                await _homeworkService.CreateHomeworkAsync(homeworkDto);

                return(RedirectToAction("Edit", "Group", new { groupId = homeworkDto.GroupId }));
            }
            catch (SPCException ex)
            {
                return(View("ErrorView", new ErrorDto(ex.Message, ex.StatusCode)));
            }
            catch
            {
                return(View("Error"));
            }
        }
 public async Task <IActionResult> Create([FromBody] NewHomeworkDto homeworkDto)
 {
     return(await HandleRequestAsync(async() => await _homeworkService.CreateHomeworkAsync(homeworkDto)));
 }