public async Task <PageResult <GetAllStatisticByDto> > GetAllStatisticBy(StatisticReportFilterByDto input) { var counts = 0; var results = (from category in _categoryRepository.GetAll() join book in _bookRepository.GetAll() on category.Id equals book.CategoryId join brDetail in _borrowBookDetailRepository.GetAll() on book.Id equals brDetail.BookId into TempBrDetail from brDetailTB in TempBrDetail.DefaultIfEmpty() join borrow in _borrowBookRepository.GetAll() on brDetailTB.BorrowBookId equals borrow.Id into TempBr from borrowTB in TempBr.DefaultIfEmpty() join library in _libraryRepository.GetAll() on brDetailTB.LibraryId equals library.Id into TempLib from libraryTB in TempLib.DefaultIfEmpty() join district in _districtRepository.GetAll() on libraryTB.DistrictId equals district.Id into TempDistrict from districtTB in TempDistrict.DefaultIfEmpty() join province in _provinceRepository.GetAll() on districtTB.ProvinceId equals province.Id into TempProvince from provinceTB in TempProvince.DefaultIfEmpty() select new { CategoryId = category.Id, CategoryName = category.Name, LibraryId = libraryTB != null ? libraryTB.Id : Guid.Empty, LibraryName = libraryTB != null ? libraryTB.Name : null, DistrictId = districtTB != null ? districtTB.Id : Guid.Empty, DistrictName = districtTB != null ? districtTB.Name : null, ProvinceId = provinceTB != null ? provinceTB.Id : Guid.Empty, ProvinceName = provinceTB != null ? provinceTB.Name : null, Qty = brDetailTB != null ? brDetailTB.Qty : 0, DateBorrow = borrowTB.DateBorrow }) .ToList() .WhereIf( input.LibraryId != Guid.Empty || input.ProvinceId != Guid.Empty || input.DistrictId != Guid.Empty || input.FromDate.HasValue && input.ToDate.HasValue || input.Month != null || input.Quarter != null , x => x.LibraryId == input.LibraryId || x.ProvinceId == input.ProvinceId || x.DistrictId == input.DistrictId || x.DateBorrow.Date >= input.FromDate && x.DateBorrow.Date <= input.ToDate || x.DateBorrow.Month == input.Month || ((1 <= x.DateBorrow.Month && x.DateBorrow.Month <= 3) ? 1 : ((4 <= x.DateBorrow.Month && x.DateBorrow.Month <= 6) ? 2 : ((7 <= x.DateBorrow.Month && x.DateBorrow.Month <= 9) ? 3 : ((10 <= x.DateBorrow.Month && x.DateBorrow.Month <= 12) ? 4 : 0)))) == input.Quarter ) .GroupBy(x => x.CategoryId) .Select(data => new GetAllStatisticByDto { CategoryId = data.Key, CategoryName = data.Select(x => x.CategoryName).FirstOrDefault(), LibraryId = data.Select(x => x.LibraryId).FirstOrDefault(), LibraryName = data.Select(x => x.LibraryName).FirstOrDefault(), DistrictId = data.Select(x => x.DistrictId).FirstOrDefault(), DistrictName = data.Select(x => x.DistrictName).FirstOrDefault(), ProvinceId = data.Select(x => x.ProvinceId).FirstOrDefault(), ProvinceName = data.Select(x => x.ProvinceName).FirstOrDefault(), Quantity = data.Sum(x => x == null ? 0 : x.Qty), }).OrderByDescending(x => x.Quantity); counts = results.Count(); var result = new PageResult <GetAllStatisticByDto> { Count = counts, PageIndex = input.PageIndex, PageSize = input.PageSize, Items = await Task.FromResult(results.Skip((input.PageIndex - 1) * input.PageSize).Take(input.PageSize).ToList()) }; return(result); }
private void MakeConnectedSet(TempProvince start, IDictionary<string, TempProvince> todo, IList<TempProvince> result) { if ((start.North != null) && todo.ContainsKey(start.North)) { var doing = todo[start.North]; doing.X = start.X; doing.Y = start.Y - 1; todo.Remove(start.North); result.Add(doing); MakeConnectedSet(doing, todo, result); } if ((start.South != null) && todo.ContainsKey(start.South)) { var doing = todo[start.South]; doing.X = start.X; doing.Y = start.Y + 1; todo.Remove(start.South); result.Add(doing); MakeConnectedSet(doing, todo, result); } if ((start.West != null) && todo.ContainsKey(start.West)) { var doing = todo[start.West]; doing.X = start.X - 1; doing.Y = start.Y; todo.Remove(start.West); result.Add(doing); MakeConnectedSet(doing, todo, result); } if ((start.East != null) && todo.ContainsKey(start.East)) { var doing = todo[start.East]; doing.X = start.X + 1; doing.Y = start.Y; todo.Remove(start.East); result.Add( doing); MakeConnectedSet(doing, todo, result); } if (todo.ContainsKey(start.Id)) { todo.Remove(start.Id); result.Add(start); } }