public AddFixPriceActionViewModel(IUnitOfWork UoW, PromotionalSet promotionalSet, ICommonServices commonServices, IEntityAutocompleteSelectorFactory nomenclatureSelectorFactory) { NomenclatureSelectorFactory = nomenclatureSelectorFactory ?? throw new ArgumentNullException(nameof(nomenclatureSelectorFactory)); CreateCommands(); PromotionalSet = promotionalSet; CommonServices = commonServices; this.UoW = UoW; }
/// <summary> /// Возврат словаря, у которого ключ это <see cref="PromotionalSet.Id"/>, /// а значение - массив с <see cref="VodovozOrder.Id"/>, для всех точек доставок /// похожих по полям <see cref="DeliveryPoint.City"/>, /// <see cref="DeliveryPoint.Street"/>, <see cref="DeliveryPoint.Building"/>, /// <see cref="DeliveryPoint.Room"/> /// </summary> /// <returns>Словарь</returns> /// <param name="uow">Unit Of Work</param> /// <param name="currOrder">Заказ, из которого берётся точка доставки</param> /// <param name="ignoreCurrentOrder">Если <c>true</c>, то в выборке будет /// игнорироваться заказ передаваемы в качестве параметра <paramref name="currOrder"/></param> public Dictionary <int, int[]> GetPromotionalSetsAndCorrespondingOrdersForDeliveryPoint(IUnitOfWork uow, VodovozOrder currOrder, bool ignoreCurrentOrder = false) { if (GetPromotionalSetsAndCorrespondingOrdersForDeliveryPointTestGap != null) { return(GetPromotionalSetsAndCorrespondingOrdersForDeliveryPointTestGap(uow, currOrder, ignoreCurrentOrder)); } VodovozOrder ordersAlias = null; PromotionalSet promotionalSetAlias = null; DeliveryPoint deliveryPointAlias = null; var dp = currOrder.DeliveryPoint; var oId = !ignoreCurrentOrder ? -1 : currOrder.Id; var acceptableStatuses = new[] { OrderStatus.Accepted, OrderStatus.InTravelList, OrderStatus.WaitForPayment, OrderStatus.OnLoading, OrderStatus.OnTheWay, OrderStatus.Shipped, OrderStatus.UnloadingOnStock, OrderStatus.Closed }; var subQuerySimilarDP = QueryOver.Of(() => deliveryPointAlias) .Where(p => p.City == dp.City) .Where(p => p.Street == dp.Street) .Where(p => p.Building == dp.Building) .Where(p => p.Room == dp.Room) .Select(Projections.Property(() => deliveryPointAlias.Id)) ; var result = uow.Session.QueryOver(() => promotionalSetAlias) .JoinAlias(() => promotionalSetAlias.Orders, () => ordersAlias) .JoinAlias(() => ordersAlias.DeliveryPoint, () => deliveryPointAlias) .Where(() => ordersAlias.Id != oId) .Where(() => ordersAlias.OrderStatus.IsIn(acceptableStatuses)) .WithSubquery.WhereProperty(() => deliveryPointAlias.Id).In(subQuerySimilarDP) .SelectList(list => list.Select(() => promotionalSetAlias.Id) .Select(() => ordersAlias.Id)) .List <object[]>() .GroupBy(x => (int)x[0]) .ToDictionary(g => g.Key, g => g.Select(x => (int)x[1]).ToArray()); return(result); }
public WidgetViewModelBase Resolve(PromotionalSet promotionalSet, PromotionalSetActionType setActionType) { switch (setActionType) { case PromotionalSetActionType.FixedPrice: var filter = new NomenclatureFilterViewModel(); filter.RestrictCategory = NomenclatureCategory.water; var nomenclatureSelectorFactory = new NomenclatureAutoCompleteSelectorFactory <Nomenclature, NomenclaturesJournalViewModel>( ServicesConfig.CommonServices, filter, counterpartySelectorFactory, nomenclatureRepository, userRepository); return(new AddFixPriceActionViewModel(uow, promotionalSet, ServicesConfig.CommonServices, nomenclatureSelectorFactory)); default: throw new ArgumentException(); } }