protected override void AddCommand_Execute() { //создаем новый юнит и привязываем его к объекту var salesUnit = new OfferUnitWrapper(new OfferUnit()); if (_offerWrapper != null) { salesUnit.Offer = _offerWrapper; } //создаем модель для диалога var viewModel = new OfferUnitsViewModel(salesUnit, Container, UnitOfWork); //заполняем юнит начальными данными if (Groups.SelectedGroup != null) { viewModel.ViewModel.Item.Cost = Groups.SelectedGroup.Cost; viewModel.ViewModel.Item.Facility = new FacilityWrapper(Groups.SelectedGroup.Facility.Model); viewModel.ViewModel.Item.PaymentConditionSet = new PaymentConditionSetWrapper(Groups.SelectedGroup.PaymentConditionSet.Model); viewModel.ViewModel.Item.ProductionTerm = Groups.SelectedGroup.ProductionTerm; viewModel.ViewModel.Item.Product = new ProductWrapper(Groups.SelectedGroup.Product.Model); //создаем зависимое оборудование foreach (var prodIncl in Groups.SelectedGroup.ProductsIncluded) { var pi = new ProductIncluded { Product = prodIncl.Model.Product, Amount = prodIncl.Model.Amount }; viewModel.ViewModel.Item.ProductsIncluded.Add(new ProductIncludedWrapper(pi)); } } //диалог с пользователем var result = Container.Resolve <IDialogService>().ShowDialog(viewModel); if (!result.HasValue || !result.Value) { return; } //клонируем юниты var units = new List <OfferUnit>(); for (int i = 0; i < viewModel.Amount; i++) { var unit = (OfferUnit)viewModel.ViewModel.Item.Model.Clone(); unit.Id = Guid.NewGuid(); unit.ProductsIncluded = new List <ProductIncluded>(); units.Add(unit); } var group = new OfferUnitsGroup(units); Groups.Add(group); RefreshPrice(group); Groups.SelectedGroup = group; }
private void GenerateOfferUnits() { var productIncluded = new ProductIncluded { Product = ProductZip1, Amount = 1 }; OfferUnitVeb1101.Clone(new OfferUnit { Offer = OfferMrsk, Product = ProductVeb110, Cost = 3100000, ProductionTerm = 120, PaymentConditionSet = PaymentConditionSet50Na50, Facility = FacilityStation, ProductsIncluded = new List <ProductIncluded> { productIncluded } }); OfferUnitVeb1102.Clone(new OfferUnit { Offer = OfferMrsk, Product = ProductVeb110, Cost = 3100000, ProductionTerm = 120, PaymentConditionSet = PaymentConditionSet50Na50, Facility = FacilityStation, ProductsIncluded = new List <ProductIncluded> { productIncluded } }); OfferUnitZng1101.Clone(new OfferUnit { Offer = OfferMrsk, Product = ProductZng110, Cost = 550000, ProductionTerm = 180, PaymentConditionSet = PaymentConditionSet50Na50, Facility = FacilitySubstation, ProductsIncluded = new List <ProductIncluded> { new ProductIncluded { Product = ProductZip1, Amount = 3 } } }); OfferUnitZng1102.Clone(new OfferUnit { Offer = OfferMrsk, Product = ProductZng110, Cost = 550000, ProductionTerm = 180, PaymentConditionSet = PaymentConditionSet50Na50, Facility = FacilitySubstation, ProductsIncluded = new List <ProductIncluded> { new ProductIncluded { Product = ProductZip1, Amount = 2 } } }); OfferUnitZng1103.Clone(new OfferUnit { Offer = OfferMrsk, Product = ProductZng110, Cost = 550000, ProductionTerm = 180, PaymentConditionSet = PaymentConditionSet50Na50, Facility = FacilitySubstation, ProductsIncluded = new List <ProductIncluded> { new ProductIncluded { Product = ProductZip1, Amount = 2 } } }); OfferUnitZng1104.Clone(new OfferUnit { Offer = OfferMrsk, Product = ProductZng110, Cost = 550000, ProductionTerm = 150, PaymentConditionSet = PaymentConditionSet30Na70, Facility = FacilitySubstation }); OfferUnitZng1105.Clone(new OfferUnit { Offer = OfferMrsk, Product = ProductZng110, Cost = 550000, ProductionTerm = 150, PaymentConditionSet = PaymentConditionSet30Na70, Facility = FacilitySubstation }); OfferUnitZng1106.Clone(new OfferUnit { Offer = OfferMrsk, Product = ProductZng110, Cost = 550000, ProductionTerm = 150, PaymentConditionSet = PaymentConditionSet30Na70, Facility = FacilitySubstation }); }
///// <summary> ///// Загрузка при создании нового предложения. ///// </summary> ///// <param name="offerUnits"></param> ///// <returns></returns> //private async Task LoadOfferUnitsAsync(IEnumerable<OfferUnit> offerUnits) //{ // //копия единиц с оборудованием // var units = new List<OfferUnit>(); // foreach (var offerUnit in offerUnits) // { // //клонируем входящий // var offerUnitNew = new OfferUnit(); // //меняем ссылочные свойства на объекты текущего контекста // offerUnitNew.Cost = offerUnit.Cost; // offerUnitNew.ProductionTerm = offerUnit.ProductionTerm; // offerUnitNew.Product = await UnitOfWork.Repository<Product>().GetByIdAsync(offerUnit.Product.Id); // offerUnitNew.PaymentConditionSet = await UnitOfWork.Repository<PaymentConditionSet>().GetByIdAsync(offerUnit.PaymentConditionSet.Id); // offerUnitNew.Facility = await UnitOfWork.Repository<Facility>().GetByIdAsync(offerUnit.Facility.Id); // //копия включенного оборудования // offerUnitNew.ProductsIncluded = new List<ProductIncluded>(); // foreach (var productIncluded in offerUnit.ProductsIncluded) // { // var productIncludedNew = new ProductIncluded // { // Product = await UnitOfWork.Repository<Product>().GetByIdAsync(productIncluded.Product.Id), // Amount = productIncluded.Amount // }; // offerUnitNew.ProductsIncluded.Add(productIncludedNew); // } // units.Add(offerUnitNew); // } // //добавляем созданное в группы // InitGroupsViewModel(new List<OfferUnit>()); // var groups = units.GroupBy(x => x, new OfferUnitsGroupsComparer()).OrderByDescending(x => x.Key.Cost).Select(x => new OfferUnitsGroup(x)).ToList(); // groups.ForEach(x => // { // x.Offer = Item; // GroupsViewModel.Groups.Add(x); // }); // await GroupsViewModel.LoadAsync(); // await base.AfterLoading(); //} private IEnumerable <OfferUnit> CloneOfferUnits(IEnumerable <OfferUnit> offerUnits) { //копия единиц с оборудованием var offerUnitsDictionary = new Dictionary <OfferUnit, OfferUnit>(); foreach (var offerUnit in offerUnits) { //клонируем входящий //меняем ссылочные свойства на объекты текущего контекста var offerUnitNew = new OfferUnit { Cost = offerUnit.Cost, Comment = offerUnit.Comment, CostDelivery = offerUnit.CostDelivery, ProductionTerm = offerUnit.ProductionTerm, Product = UnitOfWork.Repository <Product>().GetById(offerUnit.Product.Id), PaymentConditionSet = UnitOfWork.Repository <PaymentConditionSet>().GetById(offerUnit.PaymentConditionSet.Id), Facility = UnitOfWork.Repository <Facility>().GetById(offerUnit.Facility.Id) }; offerUnitsDictionary.Add(offerUnit, offerUnitNew); } //копия включенного оборудования var productsIncluded = offerUnits.SelectMany(x => x.ProductsIncluded).Distinct().ToList(); foreach (var productIncluded in productsIncluded) { var productIncludedNew = new ProductIncluded { Product = UnitOfWork.Repository <Product>().GetById(productIncluded.Product.Id), Amount = productIncluded.Amount }; var targetNewOfferUnits = offerUnitsDictionary .Where(x => x.Key.ProductsIncluded.Contains(productIncluded)) .Select(x => x.Value) .ToList(); targetNewOfferUnits.ForEach(x => x.ProductsIncluded.Add(productIncludedNew)); } return(offerUnitsDictionary.Select(x => x.Value)); }
/// <summary> /// Заполнение юнита по выбранной группе /// </summary> /// <param name="salesUnitWrapper"></param> private void FillingSalesUnit(SalesUnitWrapper salesUnitWrapper) { if (Groups.SelectedGroup == null) { var paymentConditionSet = UnitOfWork.Repository <PaymentConditionSet>() .Find(conditionSet => conditionSet.Id == GlobalAppProperties.Actual.PaymentConditionSet.Id) .First(); salesUnitWrapper.PaymentConditionSet = new PaymentConditionSetWrapper(paymentConditionSet); salesUnitWrapper.ProductionTerm = GlobalAppProperties.Actual.StandartTermFromStartToEndProduction; return; } salesUnitWrapper.Cost = Groups.SelectedGroup.Cost; salesUnitWrapper.Facility = new FacilityWrapper(Groups.SelectedGroup.Facility.Model); salesUnitWrapper.PaymentConditionSet = new PaymentConditionSetWrapper(Groups.SelectedGroup.PaymentConditionSet.Model); salesUnitWrapper.ProductionTerm = Groups.SelectedGroup.ProductionTerm; salesUnitWrapper.Product = new ProductWrapper(Groups.SelectedGroup.Product.Model); salesUnitWrapper.DeliveryDateExpected = Groups.SelectedGroup.DeliveryDateExpected; if (Groups.SelectedGroup.CostDelivery.HasValue) { if (Groups.SelectedGroup.Groups != null && Groups.SelectedGroup.Groups.Any() && !Groups.SelectedGroup.Groups.First().CostDelivery.HasValue) { salesUnitWrapper.CostDelivery = null; } else { salesUnitWrapper.CostDelivery = Groups.SelectedGroup.CostDelivery / Groups.SelectedGroup.Amount; } } //создаем зависимое оборудование foreach (var prodIncl in Groups.SelectedGroup.ProductsIncluded) { var pi = new ProductIncluded { Product = prodIncl.Model.Product, Amount = prodIncl.Model.Amount }; salesUnitWrapper.ProductsIncluded.Add(new ProductIncludedWrapper(pi)); } }