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); }
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()); } }
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()); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public AdminApi( string server ) { _server = server; Process = new AdminProcessMethods(this); Settings = new SettingsMethods(this); Log = new LogMethods(this); }