public CreateNewProductTasksViewModel(IUnityContainer container) : base(container) { ChangeProductCommand = new DelegateLogCommand(() => { var unitOfWork = Container.Resolve <IUnitOfWork>(); //продукт на замену var targetProduct = Container.Resolve <IGetProductService>().GetProduct(); var task = unitOfWork.Repository <CreateNewProductTask>().GetById(SelectedItem.Id); if (targetProduct == null || targetProduct.Id == task.Product.Id) { return; } targetProduct = unitOfWork.Repository <Product>().GetById(targetProduct.Id); //юниты с новым продуктом var salesUnits = unitOfWork.Repository <SalesUnit>().Find(salesUnit => salesUnit.Product.Id == task.Product.Id); var offerUnits = unitOfWork.Repository <OfferUnit>().Find(offerUnit => offerUnit.Product.Id == task.Product.Id); //меняем продукт в юнитах salesUnits.ForEach(salesUnit => salesUnit.Product = targetProduct); offerUnits.ForEach(offerUnit => offerUnit.Product = targetProduct); //удаление параметров var parameters = task.Product.ProductBlock.Parameters .Where(parameter => parameter.Id != GlobalAppProperties.Actual.NewProductParameter.Id).ToList(); unitOfWork.Repository <Parameter>().DeleteRange(parameters); //удаление связей параметров var relations = unitOfWork.Repository <ParameterRelation>().GetAll() .Where(x => parameters.Select(p => p.Id).Contains(x.ParameterId)).ToList(); unitOfWork.Repository <ParameterRelation>().DeleteRange(relations); //удаление блока unitOfWork.Repository <ProductBlock>().Delete(task.Product.ProductBlock); //удаление продукта unitOfWork.Repository <Product>().Delete(task.Product); //удаление задания unitOfWork.Repository <CreateNewProductTask>().Delete(task); if (unitOfWork.SaveChanges().OperationCompletedSuccessfully) { Container.Resolve <IEventAggregator>().GetEvent <AfterRemoveCreateNewProductTaskEvent>().Publish(task); } }, () => SelectedItem != null); this.SelectedLookupChanged += lookup => { ChangeProductCommand.RaiseCanExecuteChanged(); }; }
public OffersViewModel(IUnityContainer container) : base(container) { PrintOfferCommand = new DelegateLogCommand( () => { Container.Resolve <IPrintOfferService>().PrintOffer(SelectedItem.Id); }, () => SelectedItem != null); this.SelectedLookupChanged += lookup => { PrintOfferCommand.RaiseCanExecuteChanged(); }; }
public PaymentConditionViewModel(PaymentConditionSet paymentConditionSet, IUnityContainer container) { _unitOfWork = container.Resolve <IUnitOfWork>(); PaymentConditionWrapper = new PaymentConditionWrapper2(paymentConditionSet) { Part = 1.0 - paymentConditionSet.PaymentConditions.Sum(condition => condition.Part), PaymentConditionPoint = new PaymentConditionPointWrapper(_unitOfWork.Repository <PaymentConditionPoint>().GetAll().First()) }; OkCommand = new DelegateLogCommand( () => { PaymentCondition paymentCondition = this.PaymentConditionWrapper.Model; //если условие новое if (_unitOfWork.Repository <PaymentCondition>() .Find(condition => Equals(condition, paymentCondition)) .Any() == false) { if (_unitOfWork.SaveEntity(paymentCondition).OperationCompletedSuccessfully) { this.PaymentConditionWrapper.AcceptChanges(); container.Resolve <IEventAggregator>().GetEvent <AfterSavePaymentConditionEvent>().Publish(paymentCondition); } else { return; } } IsOk = true; CloseRequested?.Invoke(this, new DialogRequestCloseEventArgs(true)); }, () => PaymentConditionWrapper.IsValid && PaymentConditionWrapper.IsChanged); PaymentConditionWrapper.PropertyChanged += (sender, args) => OkCommand.RaiseCanExecuteChanged(); SelectPaymentConditionPointCommand = new DelegateLogCommand( () => { ISelectService selectService = container.Resolve <ISelectService>(); PaymentConditionPoint point = selectService.SelectItem(_unitOfWork.Repository <PaymentConditionPoint>().GetAll()); if (point != null) { this.PaymentConditionWrapper.PaymentConditionPoint = new PaymentConditionPointWrapper(point); } }); ClearPaymentConditionPointCommand = new DelegateLogCommand( () => { this.PaymentConditionWrapper.PaymentConditionPoint = null; }); }
protected override void InitSpecialCommands() { RemovePasswordCommand = new DelegateLogCommand( () => { var dr = MessageService.ShowYesNoMessageDialog("Сброс пароля", "Вы действительно хотите сбросить пароль выбранному пользователю?"); if (dr != MessageDialogResult.Yes) { return; } var unitOfWork = Container.Resolve <IUnitOfWork>(); var user = unitOfWork.Repository <User>().GetById(SelectedItem.Id); user.Password = Guid.Empty; unitOfWork.SaveChanges(); EventAggregator.GetEvent <AfterSaveUserEvent>().Publish(user); }, () => SelectedItem != null); this.SelectedLookupChanged += lookup => RemovePasswordCommand.RaiseCanExecuteChanged(); }
public ProductsIncludedViewModel(ProductIncludedWrapper wrapper, IUnitOfWork unitOfWork, IUnityContainer container) : base(container) { ViewModel = container.Resolve <ProductIncludedDetailsViewModel>(); ViewModel.Load(wrapper, unitOfWork); if (ViewModel.Item.Product == null) { var productIncludedDefault = GlobalAppProperties.Actual.ProductIncludedDefault; if (productIncludedDefault != null) { ViewModel.Item.Product = new ProductWrapper(unitOfWork.Repository <Product>().GetById(productIncludedDefault.Id)); } } OkCommand = new DelegateLogCommand( () => { CloseRequested?.Invoke(this, new DialogRequestCloseEventArgs(true)); }, () => { return(ViewModel?.Item.Product != null && ViewModel.Item.Amount > 0); }); ViewModel.Item.PropertyChanged += (s, a) => OkCommand.RaiseCanExecuteChanged(); }
protected override void InitSpecialCommands() { CopyAttachmentsCommand = new DelegateLogCommand( () => { IEventServiceClient eventServiceClient = Container.Resolve <IEventServiceClient>(); IMessageService messageService = Container.Resolve <IMessageService>(); if (SelectedItems != null && SelectedItems.Any()) { var selectedProjects = SelectedItems.ToList(); var managers = selectedProjects.Select(project => project.Manager).Distinct().ToList(); var managersOffline = new List <User>(); foreach (var manager in managers) { if (eventServiceClient.UserConnected(manager.Id) == false) { managersOffline.Add(manager); } } if (managersOffline.Any()) { var dr = messageService.ShowYesNoMessageDialog("Некоторые менеджеры не подключены", $"{managersOffline.ToStringEnum()} не подключены. Продолжаем?"); if (dr != MessageDialogResult.Yes) { return; } } managersOffline.ForEach(user => managers.Remove(user)); if (managers.Any()) { using (var fdb = new FolderBrowserDialog()) { var dialogResult = fdb.ShowDialog(); if (dialogResult == DialogResult.OK && !string.IsNullOrWhiteSpace(fdb.SelectedPath)) { var selectedDirectoryPath = fdb.SelectedPath; foreach (var selectedProject in selectedProjects) { if (!managers.Contains(selectedProject.Manager)) { continue; } var targetDirectoryPath = Path.Combine(selectedDirectoryPath, selectedProject.Id.ToString().Replace("-", string.Empty)); this.Container.Resolve <IFileManagerService>().CreateDirectoryPathIfNotExists(targetDirectoryPath); eventServiceClient.CopyProjectAttachmentsRequest(selectedProject.Manager.Id, selectedProject.Id, targetDirectoryPath); } messageService.ShowOkMessageDialog("Info", $"Started copy proccess to: {selectedDirectoryPath}"); } } } } }, () => SelectedItem != null); this.SelectedLookupChanged += lookup => CopyAttachmentsCommand.RaiseCanExecuteChanged(); }