public Dictionary <int, double> GetStatisticsByWeek(int clientId) { DateTime now = DateTime.Now; DayOfWeek dayOfWeek = now.DayOfWeek; DateTime start = DateTime.Now; if (dayOfWeek == DayOfWeek.Sunday) { start = start.AddDays(-6); } else { start = start.AddDays(-(int)dayOfWeek + 1); } start = start.AddHours(-now.Hour).AddMinutes(-now.Minute); DateTime finish = DateTime.Now; finish = start.AddDays(6); finish = finish.AddHours(24).AddMinutes(60); IEnumerable <WorkplaceOrder> workplaceOrders = workplaceOrderDB .GetFilteredWorkplaceOrdersByClient(start, finish, clientId); Dictionary <int, double> weekStatistics = new Dictionary <int, double>(); for (int i = 1; i <= 7; i++) { weekStatistics[i] = 0; } foreach (WorkplaceOrder workplaceOrder in workplaceOrders) { double hours = workplaceOrder.FinishTime.Hour - workplaceOrder.StartTime.Hour; double minutes = workplaceOrder.FinishTime.Minute - workplaceOrder.StartTime.Minute; hours += (minutes / 60); int day; if ((int)workplaceOrder.FinishTime.DayOfWeek == 0) { day = 7; } else { day = (int)workplaceOrder.FinishTime.DayOfWeek; } weekStatistics[day] += hours; } for (int i = 1; i <= 7; i++) { double realTime = weekStatistics[i]; weekStatistics[i] = Math.Round(realTime / 12, 2); } return(weekStatistics); }
public FilteredPagedResult GetFilteredWorkplaceOrdersListByClient([FromQuery] DateFilter filter, int pageNumber) { string userJWTId = User.FindFirst("id")?.Value; Client client = clientDB.GetCurrentClient(userJWTId); if (client == null) { return(null); } int take = 3; int skip = (pageNumber - 1) * take; IEnumerable <WorkplaceOrder> workplaceOrders; int totalCount = 0; string likeString = (String.IsNullOrEmpty(filter.Like)) ? null : filter.Like; if (filter == null || (filter.StartTime == null && filter.FinishTime == null)) { workplaceOrders = WorkplaceOrderDB.GetCurrentWorkplaceOrdersByClient(client.Id, skip, take); totalCount = WorkplaceOrderDB.GetCurrentWorkplaceOrdersByClientCount(client.Id); } else if (filter.StartTime == null) { workplaceOrders = WorkplaceOrderDB.GetPreviousWorkplaceOrdersByClient ((DateTime)filter.FinishTime, client.Id, skip, take); totalCount = WorkplaceOrderDB.GetPreviousWorkplaceOrdersByClientCount((DateTime)filter.FinishTime, client.Id); } else if (filter.FinishTime == null) { workplaceOrders = WorkplaceOrderDB.GetFutureWorkplaceOrdersByClient ((DateTime)filter.StartTime, client.Id, skip, take, likeString); totalCount = WorkplaceOrderDB.GetFutureWorkplaceOrdersByClientCount((DateTime)filter.StartTime, client.Id, likeString); } else { workplaceOrders = WorkplaceOrderDB.GetFilteredWorkplaceOrdersByClient ((DateTime)filter.StartTime, (DateTime)filter.FinishTime, client.Id, skip, take, likeString); totalCount = WorkplaceOrderDB.GetFilteredWorkplaceOrdersByClientCount ((DateTime)filter.StartTime, (DateTime)filter.FinishTime, client.Id, likeString); } double pageDecimal = (double)totalCount / take; int pageCount = totalCount / take; if (pageDecimal - (double)pageCount != 0.0) { pageCount++; } return(new FilteredPagedResult { WorkplaceOrders = workplaceOrders, TotalCount = pageCount }); }