public void GetAllUpgradedDowngradedOrderswithFilterTest() { int totalRecords = 0; var filter = new CustomerUpsellListModelFilter { FromDate = DateTime.Now.AddDays(-30), ToDate = DateTime.Now.AddDays(30), UpSellRole = 10 }; var orders = _orderRepository.GetAllUpgradedDowngradedOrders(1, 20, filter, out totalRecords); Assert.IsNotNull(orders); Assert.IsNotEmpty(orders.ToList()); }
public ActionResult Upsell(CustomerUpsellListModelFilter filter = null, int pageNumber = 1) { if (!filter.FromDate.HasValue && !filter.ToDate.HasValue) { filter.FromDate = DateTime.Now.AddMonths(-1).Date; filter.ToDate = DateTime.Now.Date; } int totalRecords = 0; var model = _financeReportingService.GetCustomerUpsellModel(pageNumber, _pageSize, filter, out totalRecords); if (model == null) { model = new CustomerUpsellListModel(); } model.Filter = filter; var currentAction = ControllerContext.RouteData.Values["action"].ToString(); Func <int, string> urlFunc = pn => Url.Action(currentAction, new { pageNumber = pn, filter.FromDate, filter.ToDate, filter.Vehicle, filter.ZipCode, filter.Territory, filter.UpSellRole, filter.CorporateAccountId }); model.PagingModel = new PagingModel(pageNumber, _pageSize, totalRecords, urlFunc); return(View(model)); }
public IEnumerable <Core.Finance.Domain.Order> GetAllUpgradedDowngradedOrders(int pageNumber, int pageSize, CustomerUpsellListModelFilter filter, out int totalRecords) { var orders = new List <Core.Finance.Domain.Order>(); using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); //var ordersWithCancelStatusItem = from o in linqMetaData.OrderDetail // join oi in linqMetaData.OrderItem on o.OrderItemId equals oi.OrderItemId // where o.Status == (short)EventPackageItemStatus.Cancelled.StatusCode // select o.OrderId; var ordersWithCancelStatusItem = (from o in linqMetaData.Order join od in linqMetaData.OrderDetail on o.OrderId equals od.OrderId where od.DateCreated > o.DateCreated.AddMinutes(5) select o.OrderId); var orderDetailMaxDateGrouping = (from od in linqMetaData.OrderDetail where ordersWithCancelStatusItem.Contains(od.OrderId) group od by od.OrderId).Select(od => new { OrderId = od.Key, MaxDate = od.Max(o => o.DateCreated) }); if (filter == null) { var query = (from o in linqMetaData.OrderDetail join ecod in linqMetaData.EventCustomerOrderDetail on o.OrderDetailId equals ecod.OrderDetailId join ec in linqMetaData.EventCustomers on ecod.EventCustomerId equals ec.EventCustomerId join od in orderDetailMaxDateGrouping on o.OrderId equals od.OrderId where ecod.IsActive && o.Status == (short)EventPackageItemStatus.Availed.StatusCode && ordersWithCancelStatusItem.Contains(o.OrderId) && ec.AppointmentId.HasValue orderby od.MaxDate descending select new { ec.EventId, ec.CustomerId, o.OrderId }); totalRecords = query.Count(); var ordersAvailedwithUpDownSell = query.TakePage(pageNumber, pageSize); foreach (var ecustomerOrder in ordersAvailedwithUpDownSell) { var order = GetOrder(ecustomerOrder.OrderId); order.EventId = ecustomerOrder.EventId; order.CustomerId = ecustomerOrder.CustomerId; orders.Add(order); } return(orders); } else { var fromDate = filter.FromDate.HasValue ? filter.FromDate.Value : DateTime.Now; var toDate = filter.ToDate.HasValue ? filter.ToDate.Value : DateTime.Now; string zip = string.IsNullOrEmpty(filter.ZipCode) ? "" : filter.ZipCode; string vehicle = string.IsNullOrEmpty(filter.Vehicle) ? "" : filter.Vehicle; long upselledRole = filter.UpSellRole == 0 ? 0 : filter.UpSellRole; long corporateAccountId = filter.CorporateAccountId <= 0 ? 0 : filter.CorporateAccountId; var eventFilterQuery = (from e in linqMetaData.Events join eh in linqMetaData.HostEventDetails on e.EventId equals eh.EventId join prospect in linqMetaData.Prospects on eh.HostId equals prospect.ProspectId join a in linqMetaData.Address on prospect.AddressId equals a.AddressId join z in linqMetaData.Zip on a.ZipId equals z.ZipId join ep in linqMetaData.EventPod on e.EventId equals ep.EventId join p in linqMetaData.PodDetails on ep.PodId equals p.PodId where (filter.FromDate != null ? fromDate <= e.EventDate : true) && (filter.ToDate != null ? toDate >= e.EventDate : true) && ep.IsActive && (z.ZipCode.Contains(zip)) && (p.Name.Contains(vehicle)) select new { e, z }); if (!string.IsNullOrEmpty(filter.Territory)) { eventFilterQuery = (from ez in eventFilterQuery join tz in linqMetaData.TerritoryZip on ez.z.ZipId equals tz.ZipId join t in linqMetaData.Territory on tz.TerritoryId equals t.TerritoryId where (t.Name.Contains(filter.Territory)) select ez); } var corporateEventIds = from ea in linqMetaData.EventAccount select ea.EventId; if (corporateAccountId > 0) { //eventFilterQuery = from ea in linqMetaData.EventAccount // join efq in eventFilterQuery on ea.EventId equals efq.e.EventId // where ea.AccountId == filter.CorporateAccountId // select efq; corporateEventIds = (from ea in linqMetaData.EventAccount where ea.AccountId == filter.CorporateAccountId select ea.EventId); //eventFilterQuery = (from efq in eventFilterQuery where corporateEventIds.Contains(efq.e.EventId) select efq); } var eventIds = eventFilterQuery.Select(ez => ez.e.EventId); var b = from od in linqMetaData.OrderDetail where ordersWithCancelStatusItem.Contains(od.OrderId) group od by od.OrderId into a select a.Max(od => od.OrderDetailId); var queryOrderIdsforUpsellRoleFilter = (from od in linqMetaData.OrderDetail join oru in linqMetaData.OrganizationRoleUser on od.OrganizationRoleUserCreatorId equals oru.OrganizationRoleUserId where b.Contains(od.OrderDetailId) //&& ordersWithCancelStatusItem.Contains(od.OrderId) && oru.RoleId == (upselledRole > 0 ? upselledRole : oru.RoleId) select od.OrderId); var query = (from o in linqMetaData.OrderDetail join ecod in linqMetaData.EventCustomerOrderDetail on o.OrderDetailId equals ecod.OrderDetailId join ec in linqMetaData.EventCustomers on ecod.EventCustomerId equals ec.EventCustomerId where ecod.IsActive && o.Status == (short)EventPackageItemStatus.Availed.StatusCode && ec.AppointmentId.HasValue && queryOrderIdsforUpsellRoleFilter.Contains(o.OrderId) && eventIds.Contains(ec.EventId) && (corporateAccountId <= 0 || corporateEventIds.Contains(ec.EventId)) orderby o.DateCreated descending select new { ec.EventId, ec.CustomerId, o.OrderId }); totalRecords = query.Count(); var ordersAvailedwithUpDownSell = query.TakePage(pageNumber, pageSize).ToArray(); foreach (var ecustomerOrder in ordersAvailedwithUpDownSell) { var order = GetOrder(ecustomerOrder.OrderId); order.EventId = ecustomerOrder.EventId; order.CustomerId = ecustomerOrder.CustomerId; orders.Add(order); } return(orders); } } }