public async Task <IActionResult> GenerateReport(string test_id) { if (int.TryParse(test_id, out int testIdInt) && await testsService.GetByIdAsync(testIdInt) != null) { int usersCount = reportService.GetAllTestingUsersCount(testIdInt); double avg = reportService.GetAvgRate(testIdInt); int passedCount = reportService.GetPassedCount(testIdInt); ReportDTO report = new ReportDTO() { AllTestingUser = usersCount, AvgRate = avg, PassedUserCount = passedCount, TestId = testIdInt, CreateDate = DateTime.Now }; var mapper = new MapperConfiguration(cfg => { cfg.CreateMap <ReportDTO, ReportModel>(); }).CreateMapper(); ReportModel model = mapper.Map <ReportDTO, ReportModel>(report); await reportService.AddAsync(report); return(Ok(new { model })); } return(BadRequest("Wrong id!")); }
public async Task HandleAsync(ReportRemark command) { await _handler .Run(async() => await _reportService.AddAsync(command.RemarkId, command.ResourceId, command.Type, command.UserId)) .OnSuccess(async() => await _bus.PublishAsync(new RemarkReported(command.Request.Id, command.UserId, command.RemarkId, command.ResourceId, command.Type)) ) .OnCustomError(async ex => await _bus.PublishAsync(new ReportRemarkRejected(command.Request.Id, command.UserId, command.RemarkId, command.ResourceId, command.Type, ex.Code, ex.Message))) .OnError(async(ex, logger) => { logger.Error(ex, "Error occured while reporting a remark."); await _bus.PublishAsync(new ReportRemarkRejected(command.Request.Id, command.UserId, command.RemarkId, command.ResourceId, command.Type, OperationCodes.Error, ex.Message)); }) .ExecuteAsync(); }
public async Task AddAsyncTest_AddNullItem_RepositoryMethodNotInvoked() { await _reportService.AddAsync(null); _repository.Verify(x => x.AddAsync(null), Times.Never); }