public IActionResult GetAttraction([FromQuery] AttractionSM attractionSM, [FromQuery] DefaultSearch defaultSearch) { try { var list = _IAtrractionService.GetAllAtrraction(null, _ => _.City, _ => _.Category); if (!String.IsNullOrWhiteSpace(attractionSM.City)) { list = list.Where(_ => _.City.Name.ToLower() == attractionSM.City.ToLower()); } if (!String.IsNullOrWhiteSpace(attractionSM.Name)) { list = list.Where(_ => _.Name.ToLower().Contains(attractionSM.Name.ToLower())); } if (attractionSM.IsTemporarityClosed != null) { list = list.Where(_ => _.IsTemporarityClosed == attractionSM.IsTemporarityClosed); } if (!String.IsNullOrWhiteSpace(attractionSM.Category)) { list = list.Where(_ => _.Category.Name.ToLower() == attractionSM.Category.ToLower()); } int total = list.ToList().Count(); switch (defaultSearch.SortBy) { case "name": list = GenericSorter.Sort(list, _ => _.Name, defaultSearch.SortDir); break; case "category": list = GenericSorter.Sort(list, _ => _.Category.Name, defaultSearch.SortDir); break; case "city": list = GenericSorter.Sort(list, _ => _.City.Name, defaultSearch.SortDir); break; default: list = GenericSorter.Sort(list, _ => _.CreateAt, defaultSearch.SortDir); break; } var data = list.Skip(defaultSearch.PageIndex) .Take(defaultSearch.PageSize) .Select(_ => _mapper.Map <AttractionVM>(_)) .ToList(); return(Ok(new { data, total })); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult GetTicketType([FromQuery] TicketTypeSM ticketType, [FromQuery] DefaultSearch defaultSearch) { try { var list = _ITicketTypeService.GetAllTicketType(_ => _.IsDelete == ticketType.IsDelete, _ => _.Atrraction, _ => _.Atrraction.City, _ => _.Atrraction.Category, _ => _.Tickets); if (!String.IsNullOrWhiteSpace(ticketType.Name)) { list = list.Where(_ => _.Name.ToLower().Contains(ticketType.Name.ToLower())); } if (!String.IsNullOrWhiteSpace(ticketType.Attraction)) { list = list.Where(_ => _.Atrraction.Name.ToLower().Contains(ticketType.Attraction.ToLower())); } if (!String.IsNullOrWhiteSpace(ticketType.City)) { list = list.Where(_ => _.Atrraction.City.Name.ToLower().Contains(ticketType.City.ToLower())); } if (ticketType.CategoryId != 0) { list = list.Where(_ => _.Atrraction.Category.Id == ticketType.CategoryId); } if (ticketType.PriceFrom != 0 && ticketType.PriceTo != 0) { list = list.Where(_ => _.AdultPrice >= ticketType.PriceFrom && _.AdultPrice <= ticketType.PriceTo); } int total = list.Count(); switch (defaultSearch.SortBy) { case "name": list = GenericSorter.Sort(list, _ => _.Name, defaultSearch.SortDir); break; case "attraction": list = GenericSorter.Sort(list, _ => _.Atrraction.Name, defaultSearch.SortDir); break; case "city": list = GenericSorter.Sort(list, _ => _.Atrraction.City.Name, defaultSearch.SortDir); break; case "adultPrice": list = GenericSorter.Sort(list, _ => _.AdultPrice, defaultSearch.SortDir); break; case "childrenPrice": list = GenericSorter.Sort(list, _ => _.ChildrenPrice, defaultSearch.SortDir); break; default: list = GenericSorter.Sort(list, _ => _.CreateAt, defaultSearch.SortDir); break; } var data = list.Skip(defaultSearch.PageIndex) .Take(defaultSearch.PageSize) .Select(_ => _mapper.Map <TicketTypeVM>(_)) .ToList(); return(Ok(new { data, total })); } catch (Exception e) { return(BadRequest(e.Message)); } }