public async Task <IActionResult> GetFilteredLessonsInDocx([FromBody] LessonFilter lessonFilter) { var fileDto = await _timetableService.GetTimetableInDocxAsync(lessonFilter); if (fileDto is null) { throw new ArgumentException(); } return(File(fileDto.FileData, fileDto.FileType, fileDto.FileName)); }
public List <Lesson> SearchLessons(LessonFilter filter) { // find the tags with exact match //var tagsQuery = from t in _ctx.LessonTags // where filter.Tags.Contains(t.Tag) // select t; // the include doens't work when performing a join (changes shape) //var lessons = from l in _ctx.Lessons.Include("Business") // from t in l.Tags // where tagsQuery.Contains(t) // select l.Include("Business") /* * var lessons = from l in _ctx.Lessons.Include("Business") * where l.Tags.Any(t => tagsQuery.Contains(t)) * select l; */ IQueryable <Lesson> lessonSessions = _ctx.Lessons .OrderBy(l => l.Id); // rank if (filter.Tags != null) { foreach (string tag in filter.Tags) { string temp = tag; lessonSessions = lessonSessions.Where(l => l.Tags.Any(t => t.Tag == temp)); } } if (filter.SuburbId != 0) { lessonSessions = lessonSessions.Where(l => l.SuburbId == filter.SuburbId); } if (filter.Offset > 0) { lessonSessions = lessonSessions.Skip(filter.Offset); } if (filter.Size > 0) { lessonSessions = lessonSessions.Take(filter.Size); } var query = lessonSessions.Select(l => new { Lesson = l, Suburb = l.Suburb, Business = l.Business, Sessions = l.Sessions.Where(s => s.StartDate >= DateTime.Today).Take(1) }); var lessons = query.ToList().Select(a => a.Lesson).ToList(); return(lessons); }
// GET api/lessons public IEnumerable <LessonSessionDTO> Get(string tags = null, int suburb = 0, int offset = 0, int size = 10) { if (tags == null && suburb == 0) { return(Get(offset, size)); } else { string[] tagsArray = string.IsNullOrEmpty(tags) ? null : tags.Split(','); LessonFilter filter = new LessonFilter() { Tags = tagsArray, SuburbId = suburb, Offset = offset, Size = Math.Min(size, 100) }; var lessons = _lessonRepository.SearchLessons(filter); var lessonHeaders = lessons.ConvertAll(l => new LessonSessionDTO(l)); return(lessonHeaders); } }
public async Task <IEnumerable <Lesson> > GetFilteredAsync(LessonFilter LessonFilter, CancellationToken cancellationToken = default) { var DefaultDate = new DateTime(1991, 10, 11); FilterDefinition <Lesson> filter = Builders <Lesson> .Filter.Eq(new ExpressionFieldDefinition <Lesson, bool>(x => x.IsDeleted), false); if (LessonFilter?.FilterBy?.Lectural != null) { filter = filter & Builders <Lesson> .Filter.Eq(new ExpressionFieldDefinition <Lesson, string>(x => x.LecturalName), LessonFilter?.FilterBy?.Lectural.ToUpper()); } if (!String.IsNullOrEmpty(LessonFilter?.FilterBy?.Group)) { filter = filter & Builders <Lesson> .Filter.Eq(new ExpressionFieldDefinition <Lesson, string>(x => x.GroupNumber), LessonFilter?.FilterBy?.Group.ToUpper()); } if (!String.IsNullOrEmpty(LessonFilter?.FilterBy?.Discipline)) { filter = filter & Builders <Lesson> .Filter.Eq(new ExpressionFieldDefinition <Lesson, string>(x => x.DisciplineName), LessonFilter?.FilterBy?.Discipline.ToUpper()); } if (!String.IsNullOrEmpty(LessonFilter?.FilterBy?.AuditoreNumber)) { filter = filter & Builders <Lesson> .Filter.Eq(new ExpressionFieldDefinition <Lesson, string>(x => x.AuditoreNumber), (string)LessonFilter?.FilterBy?.AuditoreNumber.ToUpper()); } if (LessonFilter?.FilterBy?.DateStart != DefaultDate) { filter = filter & Builders <Lesson> .Filter.Gte(new ExpressionFieldDefinition <Lesson, DateTime>(x => x.LessonDate), (DateTime)LessonFilter?.FilterBy?.DateStart); } if (LessonFilter?.FilterBy?.DateEnd != DefaultDate) { filter = filter & Builders <Lesson> .Filter.Lte(new ExpressionFieldDefinition <Lesson, DateTime>(x => x.LessonDate), (DateTime)LessonFilter?.FilterBy?.DateEnd.AddDays(1)); } return(await GetCollection().Find(filter).ToListAsync(cancellationToken)); }
public async Task <PageResultModel <LessonModel> > GetList(LessonFilter filter) { var query = _db.Lessons.AsQueryable(); if (filter.CourseId != 0) { query = query.OrderBy(x => x.CourseId) .Skip((filter.Page - 1) * filter.Size) .Take(filter.Size); var count = await query.CountAsync(); var list = await MapQuery(query).ToListAsync(); return(new PageResultModel <LessonModel> { Size = filter.Size, Page = filter.Page, TotalCount = count, List = list }); } if (filter.Duration != null) { } query = query.OrderByDescending(x => x.Id) .Skip((filter.Page - 1) * filter.Size) .Take(filter.Size); var count1 = await query.CountAsync(); var list1 = await MapQuery(query).ToListAsync(); return(new PageResultModel <LessonModel> { Size = filter.Size, Page = filter.Page, TotalCount = count1, List = list1 }); }
public async Task <ActionResult <ResultDto <IEnumerable <LessonDto> > > > GetFilteredLessons([FromBody] LessonFilter lessonFilter) { return(Ok(await _timetableService.GetFilteredTimetable(lessonFilter))); }
public async Task <IEnumerable <IEnumerable <LessonDto> > > GetFilteredTimetable(LessonFilter lessonFilter, CancellationToken cancellationToken = default) { if (lessonFilter is null) { throw new ArgumentNullException(); } var lessons = await _timetableRepository.GetFilteredAsync(lessonFilter, cancellationToken); if (lessons is null) { throw new ArgumentNullException(); } var lessonDto = _mapper.Map <List <LessonDto> >(lessons); return(lessonDto.OrderBy(p => p.LessonDate).GroupBy(g => g.LessonDate).Select(g => g.ToList())); }
public async Task <FileDto> GetTimetableInDocxAsync(LessonFilter lessonFilter, CancellationToken cancellationToken = default) { FileDto fileDto = new FileDto(); var timetableList = await GetFilteredTimetable(lessonFilter, cancellationToken); if (timetableList.Count() == 0) { throw new ArgumentNullException(); } using (MemoryStream memoryStream = new MemoryStream()) { using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(memoryStream, WordprocessingDocumentType.Document, true)) { MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); mainPart.Document = new Document(new Body()); Table table = new Table(); TableRow tr1 = new TableRow(); TableCell tc11 = new TableCell(); tc11.Append(new Paragraph(new Run(new Text("Date of lesson")))); tr1.Append(tc11); TableCell tc12 = new TableCell(); tc12.Append(new Paragraph(new Run(new Text("Count of lesson")))); tr1.Append(tc12); TableCell tc13 = new TableCell(); tc13.Append(new Paragraph(new Run(new Text("Type of lesson")))); tr1.Append(tc13); TableCell tc14 = new TableCell(); tc14.Append(new Paragraph(new Run(new Text("Disciplines name")))); tr1.Append(tc14); TableCell tc15 = new TableCell(); tc15.Append(new Paragraph(new Run(new Text("Auditore")))); tr1.Append(tc15); table.Append(tr1); foreach (var lesson in timetableList) { foreach (var l in lesson) { TableRow tr2 = new TableRow(); TableCell tc21 = new TableCell(); tc21.Append(new Paragraph(new Run(new Text(l.LessonDate.ToString())))); tr2.Append(tc21); TableCell tc22 = new TableCell(); ParagraphProperties pp22 = new ParagraphProperties(); tc22.Append(new Paragraph(new Run(new Text(l.LessonInDayNumber.ToString())))); tr2.Append(tc22); TableCell tc23 = new TableCell(); tc23.Append(new Paragraph(new Run(new Text(l.LessonType + " " + l.LessonNumber)))); tr2.Append(tc23); TableCell tc24 = new TableCell(); tc24.Append(new Paragraph(new Run(new Text(l.DisciplineName)))); tr2.Append(tc24); TableCell tc25 = new TableCell(); tc25.Append(new Paragraph(new Run(new Text(l.AuditoreNumber)))); tr2.Append(tc25); table.Append(tr2); } } mainPart.Document.Body.Append(table); mainPart.Document.Save(); } fileDto.FileData = memoryStream.ToArray(); fileDto.FileName = "timetable.docx"; fileDto.FileType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; return(fileDto); } }