예제 #1
0
            public void Log <TState>(
                LogLevel logLevel,
                EventId eventId,
                TState state,
                Exception exception,
                Func <TState, Exception, string> formatter)
            {
                var message = formatter(state, exception);

                if (_scopes.Any())
                {
                    message += $" [Scopes: {string.Join(", ", _scopes.Select(lifetime => lifetime.Scope))}]";
                }
                LogMethods[logLevel](_categoryName, message);
            }
예제 #2
0
            public async Task <string> Handle(Query request, CancellationToken cancellationToken)
            {
                var student = _context.Students.Where(x => x.Name.Equals(request.Name));

                if (student.Count() <= 0)
                {
                    var err = new DataObjectNotFoundException(nameof(student));

                    LogMethods.LogError("Student not found", err, request.Logger);

                    throw err;
                }

                var report = new StudentReport()
                {
                    StudentName = student.First().Name,
                    YearGrade   = student.First().Grade
                };

                using (var stream = new MemoryStream())
                {
                    await JsonSerializer.SerializeAsync(stream, report);

                    stream.Position  = 0;
                    using var reader = new StreamReader(stream);
                    return(await reader.ReadToEndAsync());
                }
            }
예제 #3
0
            public async Task <string> Handle(Query request, CancellationToken cancellationToken)
            {
                var lecture = _context.Lectures.Where(x => x.CourseName.Equals(request.Title));

                if (lecture.Count() <= 0)
                {
                    var ex = new DataObjectNotFoundException(nameof(lecture));

                    LogMethods.LogError("Lecture not found", ex, request.Logger);

                    throw ex;
                }

                var report = new LectureReport()
                {
                    LectureTitle = lecture.First().CourseName,
                    //Students = lecture.Students.Select(x => x.Name).ToList()
                    Students = new List <string> {
                        "Test", "AGA"
                    }
                };

                var xmlSer = new XmlSerializer(report.GetType());

                using (var stream = new MemoryStream())
                {
                    xmlSer.Serialize(stream, report);
                    stream.Position  = 0;
                    using var reader = new StreamReader(stream);
                    return(await reader.ReadToEndAsync());
                }
            }
예제 #4
0
            public async Task <Lecturer> Handle(Query request, CancellationToken cancellationToken)
            {
                var lecturer = await _context.Lecturers.FindAsync(request.Id);

                if (lecturer == null)
                {
                    var ex = new DataObjectNotFoundException(nameof(lecturer));

                    LogMethods.LogError("Lecturer not found", ex, request.Logger);

                    throw ex;
                }

                return(lecturer);
            }
예제 #5
0
            public async Task <Student> Handle(Query request, CancellationToken cancellationToken)
            {
                var student = await _context.Students.FindAsync(request.Id);

                if (student == null)
                {
                    var ex = new DataObjectNotFoundException(nameof(student));

                    LogMethods.LogError("Student not found", ex, request.Logger);

                    throw ex;
                }

                return(student);
            }
예제 #6
0
            public async Task <HomeWork> Handle(Query request, CancellationToken cancellationToken)
            {
                var homeWork = await _context.HomeWorks.FindAsync(request.Id);

                if (homeWork == null)
                {
                    var ex = new DataObjectNotFoundException(nameof(homeWork));

                    LogMethods.LogError("HomeWork not found", ex, request.Logger);

                    throw ex;
                }

                return(homeWork);
            }
예제 #7
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var lecturer = await _context.Lecturers.FindAsync(request.Id);

                if (lecturer == null)
                {
                    var ex = new DataObjectNotFoundException(nameof(lecturer));

                    LogMethods.LogError("Lecturer not found", ex, request.Logger);

                    throw ex;
                }

                _context.Remove(lecturer);

                await _context.SaveChangesAsync();

                return(Unit.Value);
            }
예제 #8
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var homeWork = await _context.HomeWorks.FindAsync(request.HomeWork.Id);

                if (homeWork == null)
                {
                    var ex = new DataObjectNotFoundException(nameof(homeWork));

                    LogMethods.LogError("HomeWork not found", ex, request.Logger);

                    throw ex;
                }

                _mapper.Map(request.HomeWork, homeWork);

                await _context.SaveChangesAsync();

                return(Unit.Value);
            }
예제 #9
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var student = await _context.Students.FindAsync(request.Student.Id);

                if (student == null)
                {
                    var ex = new DataObjectNotFoundException(nameof(student));

                    LogMethods.LogError("Student not found", ex, request.Logger);

                    throw ex;
                }

                // activity.Title = request.Activity.Title ?? activity.Title;
                _mapper.Map(request.Student, student);

                await _context.SaveChangesAsync();

                return(Unit.Value);
            }
예제 #10
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var lecturer = await _context.Lecturers.FindAsync(request.Lecturer.Id);

                if (lecturer == null)
                {
                    var ex = new DataObjectNotFoundException(nameof(lecturer));

                    LogMethods.LogError("Lecturer not found", ex, request.Logger);

                    throw ex;
                }

                // homework check
                foreach (var lecture in request.Lecturer.Lectures)
                {
                    foreach (var student in lecture.Students)
                    {
                        student.Grade *= student.LecturesCount;

                        student.LecturesCount++;

                        if (student.HomeWork != null)
                        {
                            student.Grade += new Random().Next(1, 5);
                        }

                        student.Grade /= student.LecturesCount;

                        if (student.Grade < 4)
                        {
                            // Send sms to student
                        }
                    }
                }

                foreach (var lecture in request.Lecturer.Lectures)
                {
                    foreach (var student in _context.Students)
                    {
                        if (!lecture.Students.Contains(student))
                        {
                            student.SkipCount++;
                        }

                        if (student.SkipCount >= 3)
                        {
                            // Send email to student and lecturer
                        }

                        student.Grade *= student.LecturesCount;

                        student.LecturesCount++;

                        student.Grade /= student.LecturesCount;

                        if (student.Grade < 4)
                        {
                            // Send sms to student
                        }
                    }
                }

                // activity.Title = request.Activity.Title ?? activity.Title;
                _mapper.Map(request.Lecturer, lecturer);

                await _context.SaveChangesAsync();

                return(Unit.Value);
            }
예제 #11
0
 public AdminApi( string server ) {
     _server = server;
     Process = new AdminProcessMethods(this);
     Settings = new SettingsMethods(this);
     Log = new LogMethods(this);
 }