public IList <Proposal> GetProposals(ParamResource resource) { var activeSemester = Context.Semesters.FirstOrDefault(x => x.Status == StatusDetails.Active); var proposals = Entities .Include(x => x.Student) .Include(x => x.Student.Supervisor) .Include(x => x.Student.Reviewer) .Where(x => x.Student.SemesterId == activeSemester.Id) .AsQueryable(); foreach (var filter in resource.Filters) { switch (filter.Column) { case "seminarAllow": proposals = proposals.Where(x => x.Student.IsSeminar.Value == (bool)filter.Value); break; case "ProposalTypeId" when !string.IsNullOrEmpty(filter.Value.ToString()): proposals = proposals.Where(x => x.ProposalTypeId == (int)filter.Value); break; case "Status" when !string.IsNullOrEmpty(filter.Value.ToString()): proposals = proposals.Where(x => x.Status == (byte)filter.Value); break; default: break; } } return(proposals.ToList()); }
public IActionResult GetExcel([FromBody] ParamResource resource) { try { var workBook = new XLWorkbook(); var sheet = workBook.Worksheets.Add("Proposals"); //.Cell(1, 1).SetValue("Hello World"); sheet.ColumnWidth = 30; sheet.Author = User.Identity.Name; sheet.RowHeight = 30; sheet.Cell(1, 1).SetValue("Serial").Style.Font.Bold = true; sheet.Cell(1, 1).Style.Alignment.Indent = 1; sheet.Cell(1, 2).SetValue("Student Name").Style.Font.Bold = true; sheet.Cell(1, 3).SetValue("Status").Style.Font.Bold = true; sheet.Cell(1, 4).SetValue("Type").Style.Font.Bold = true; sheet.Cell(1, 5).SetValue("Supervisor Name").Style.Font.Bold = true; sheet.Cell(1, 6).SetValue("Reviewer Name").Style.Font.Bold = true; sheet.Cell(1, 7).SetValue("Comments").Style.Font.Bold = true; var proposals = Repository.GetProposals(resource); var length = proposals.Count; for (var i = 2; i <= length + 1; i++) { sheet.Cell(i, 1).SetValue(i - 1); sheet.Cell(i, 2).SetValue(proposals[i - 2].Student?.FullName); sheet.Cell(i, 3).SetValue(ProposalStatus[proposals[i - 2].Status]); sheet.Cell(i, 4).SetValue(ProjectTypes[proposals[i - 2].ProposalTypeId]); sheet.Cell(i, 5).SetValue(proposals[i - 2].Student?.Supervisor?.FullName); sheet.Cell(i, 6).SetValue(proposals[i - 2].Student?.Reviewer?.FullName); sheet.Cell(i, 7).SetValue(proposals[i - 2].Comments); sheet.Cell(i, 7).Style.Alignment.WrapText = true; } sheet.Columns().AdjustToContents(); var stream = new MemoryStream(); workBook.SaveAs(stream); return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "HelloWorld.xlsx")); } catch (Exception e) { return(BadRequest()); } }