Пример #1
0
        public async Task <ActionResult> AddClass(CourseClassInsertDTO courseClass)
        {
            CourseClass newClass = new CourseClass()
            {
                CourseId    = courseClass.CourseId,
                Description = courseClass.Description,
                Date        = DateTime.Now
            };
            var classId = await _courseRepository.AddClass(newClass);

            if (classId != 0)
            {
                List <StudentCourse> stdCourses = await _courseRepository.GetStudentCoursesByCourseid(courseClass.CourseId);

                List <StudentAttendance> studentAttendances = new List <StudentAttendance>();
                foreach (var item in stdCourses)
                {
                    bool attended = false;
                    foreach (var id in courseClass.StudentIds)
                    {
                        if (item.StudentId == id)
                        {
                            StudentAttendance sa = new StudentAttendance()
                            {
                                CourseClassId   = classId,
                                StudentCourseId = item.Id,
                                Present         = true
                            };
                            studentAttendances.Add(sa);
                            attended = true;
                        }
                    }
                    if (attended == false)
                    {
                        StudentAttendance sa = new StudentAttendance()
                        {
                            CourseClassId   = classId,
                            StudentCourseId = item.Id,
                            Present         = false
                        };
                        studentAttendances.Add(sa);
                    }
                }

                _studentRepository.AddStudentAttendance(studentAttendances);

                return(Ok());
            }



            return(BadRequest());
        }
Пример #2
0
        public async Task <Response> AddClass(Course course, Class Class)
        {
            Response response = new Response();

            try
            {
                response = await _repository.AddClass(course, Class);

                return(response);
            }
            catch (Exception e)
            {
                StringBuilder sb = new StringBuilder();
                log.Error(sb.AppendLine(e.Message).AppendLine(e.StackTrace).ToString());
                response.Success = false;
                response.ErrorList.Add("Error while adding Class to Course");
                return(response);
            }
        }