public string CreateReport(CreateReportDto report, User user) { var dbReport = new Report { Name = report.Name, ReportGUID = CreateGUID.GetGUID(), Query = _reportRepository.GetQuery(report.QueryGUID), Columns = StringArraySerializer(report.Columns), Filter = report.Filter, Sort = JsonConvert.SerializeObject(report.Sort, Formatting.None), Rows = report.Rows, Author = user }; _reportRepository.Add(dbReport); _userReportRel.Add(new ReportUserRel { Report = dbReport, User = user, AuthoryLayer = (int)ReportUserPermissions.CanModify }); return(dbReport.ReportGUID); }
public async Task <IActionResult> PostReport([FromBody] CreateReportDto createReportDto) { MonthReportModel model = new MonthReportModel { Month = createReportDto.DateReport.ToString("MMMM", CultureInfo.CreateSpecificCulture("en-US")), Year = createReportDto.DateReport.Year.ToString(), Procedures = await _reportService.GetPerformedProcedures(createReportDto.DateReport), Doctors = await _reportService.GetDoctors(), RentExpense = createReportDto.RentExpense, AdvertisingExpense = createReportDto.AdvertisingExpense, UtilitiesExpense = createReportDto.UtilitiesExpense }; byte[] bin = await _reportService.SaveExcelReportFile(model); //clear the buffer stream Response.Headers.Clear(); Response.Clear(); //set the correct contenttype Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; //set the correct length of the data being send Response.Headers.Add("content-length", bin.Length.ToString()); //set the filename for the excel package Response.Headers.Add("content-disposition", "attachment; filename=\"MonthReport.xlsx\""); //send the byte array to the browser await Response.Body.WriteAsync(bin, 0, bin.Length); //cleanup await Response.CompleteAsync(); return(Ok()); }
public async Task <bool> CreateReportAsync(int announcementId, CreateReportDto report) { var response = await _httpClient.PostAsJsonAsync( ApiRoutes.Reports.Create.Replace("{announcementId}", announcementId.ToString()), report); return(response.IsSuccessStatusCode); }
public IActionResult PostReport([FromBody] CreateReportDto report) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _reportService.AddReport(report); return(Ok()); }
public void AddReport(CreateReportDto report) { var dog = _dogService.Add(report.Dog); var reportEntity = new ReportEntity { ContactEmail = report.ContactEmail, ContactNumber = report.ContactNumber, DateReported = DateTime.UtcNow, DogId = dog.Id }; _reportRepository.SaveAll(); _reportRepository.AddReport(reportEntity); _reportRepository.SaveAll(); }
public async Task Get_ReturnsOk_WhenAdminLoggedIn() { //Arrange await LoginAsAdminAsync(); var createdAnnouncement = new CreateAnnouncementDto { Name = "Announcement To Report", Type = "Other", Description = "Report", Image = null }; var announcementResponse = await TestClient.PostAsJsonAsync( ApiRoutes.Announcements.Create, createdAnnouncement); var announcementContent = await announcementResponse.Content.ReadAsAsync <AnnouncementResponse>(); int announcementId = announcementContent.Id; var createdReport = new CreateReportDto { ReportCause = "Test", ReportDescription = "Test", }; var reportResponse = await TestClient.PostAsJsonAsync( ApiRoutes.Reports.Create.Replace("{announcementId}", announcementId.ToString()), createdReport); var reportResponseContent = await reportResponse.Content.ReadAsAsync <ReportResponse>(); //Act var response = await TestClient.GetAsync( ApiRoutes.Reports.Get.Replace( "{reportId}", reportResponseContent.Id.ToString())); var content = await response.Content.ReadAsAsync <Report>(); //Assert response.StatusCode.Should().Be(HttpStatusCode.OK); content.Should().NotBeNull(); content.ReportCause.Should().Be("Test"); content.ReportDescription.Should().Be("Test"); }
public async Task <IActionResult> Create( [FromRoute] int announcementId, [FromBody] CreateReportDto reportDto) { var report = new Report { ReportCause = reportDto.ReportCause, ReportDescription = reportDto.ReportDescription, ReportDate = DateTime.UtcNow, AnnouncementId = announcementId }; await _reportsRepository.CreateAsync(report); var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; var locationUri = baseUrl + ApiRoutes.Reports.Get.Replace("{reportId}", report.Id.ToString()); var response = new ReportResponse { Id = report.Id }; return(Created(locationUri, response)); }
public IActionResult CreateReport([FromBody] CreateReportDto report) { try { if (report == null) { throw new BasicException("Invalid input format!"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } User user = _userRep.GetByEmailAdd(this.User.Claims.SingleOrDefault(x => x.Type == "EmailAddress").Value); var guid = _manager.CreateReport(report, user); return(Created(string.Empty, guid)); } catch (BasicException ex) { _logger.LogError(ex.Message); return(BadRequest(ex.Message)); } catch (NotFoundException ex) { _logger.LogError(ex.Message); return(NotFound(ex.Message)); } catch (PermissionException ex) { _logger.LogError(ex.Message); return(Unauthorized()); } catch (Exception ex) { _logger.LogError(ex.Message); return(BadRequest()); } }