public async Task <IEnumerable <TicketSalesDTO> > GetPeriodTicketSales (SearchTheaterPerformanceDTO parameters) { List <TheaterPerformance> theaterPerformances = _query.SetBaseTheaterPerformanceWithOrders() .SetTheaterName(parameters.TheaterName) .SetTheaterPerformanceDate(parameters.StartDate, parameters.EndDate) .Build() .ToList(); IEnumerable <IGrouping <int, TheaterPerformance> > grouppedTheaterPerformances = theaterPerformances.GroupBy(t => t.TheaterId); IEnumerable <TicketSalesDTO> ticketSales = grouppedTheaterPerformances.Select(x => new TicketSalesDTO { Id = x.Select(t => t.TheaterId).FirstOrDefault(), TheaterName = x.Select(t => t.Theater.Name).FirstOrDefault(), StartDate = parameters.StartDate, EndDate = parameters.EndDate, Revenue = x.SelectMany(t => t.Orders).Sum(t => t.TheaterPerformance.TicketPrice * t.TicketsAmount) }).OrderByDescending(x => x.Revenue); return(ticketSales); }
public async Task <IActionResult> GetTheaterPerformances ([FromQuery] SearchTheaterPerformanceDTO parameters) { IEnumerable <TheaterPerformanceDTO> performances = await _theaterPerformanceService.SearchTheaterPerformances(parameters); return(Ok(performances)); }
public async Task <IActionResult> GetTisketSales ([FromQuery] SearchTheaterPerformanceDTO parameters) { IEnumerable <TicketSalesDTO> res = await _theaterPerformanceService.GetPeriodTicketSales(parameters); return(Ok(res)); }
public async Task <IEnumerable <TheaterPerformanceDTO> > SearchTheaterPerformances (SearchTheaterPerformanceDTO parameters) { List <TheaterPerformance> theaterPerformances = _query.SetBaseTheaterPerformanceInfo() .SetTheaterName(parameters.TheaterName) .SetPerformanceName(parameters.PerformanceName) .SetTheaterPerformanceDate(parameters.StartDate, parameters.EndDate) .SetTheaterPerformancePrice(parameters.StartPrice, parameters.EndPrice) .Sort(parameters.FieldToSort, parameters.Descending) .Build() .ToList(); return(_mapper.Map <IEnumerable <TheaterPerformanceDTO> >(theaterPerformances)); }