public DataBaseBackupViewModel(IUnityContainer container) { _container = container; BackupDataBaseCommand = new DelegateLogCommand( () => { try { //var connection = new ServerConnection { ConnectionString = ConnectionString }; //var server = new Server(connection); //var backup = new Backup //{ // Action = BackupActionType.Database, // Database = DataBaseName //}; //backup.Devices.AddDevice($"{Directory}hvt.bak", DeviceType.File); //backup.SqlBackup(server); //_container.Resolve<IMessageService>().ShowOkMessageDialog("Info", "Success"); } catch (Exception e) { _container.Resolve <IMessageService>().ShowOkMessageDialog("Error", e.PrintAllExceptions()); } }); }
protected override void InitSpecialCommands() { NewItemCommand = new DelegateLogCommand(() => { RegionManager.RequestNavigateContentRegion <ProductTypeDesignationView>(new NavigationParameters()); }); }
protected override void InitSpecialCommands() { EditItemCommand = new DelegateLogCommand(EditItemCommandExecute, () => SelectedItem != null); RemoveItemCommand = new DelegateLogCommand( () => { var dr = MessageService.ShowYesNoMessageDialog("Удаление", $"Вы действительно хотите удалить \"{SelectedLookup.DisplayMember}\"?", defaultNo: true); if (dr != MessageDialogResult.Yes) { return; } var unitOfWork = Container.Resolve <IUnitOfWork>(); var specification = unitOfWork.Repository <Specification>().GetById(SelectedLookup.Id); if (specification != null) { var salesUnits = unitOfWork.Repository <SalesUnit>().Find(x => x.Specification?.Id == specification.Id); salesUnits.ForEach(salesUnit => salesUnit.Specification = null); try { unitOfWork.Repository <Specification>().Delete(specification); unitOfWork.SaveChanges(); } catch (DbUpdateException e) { MessageService.ShowOkMessageDialog(e.GetType().ToString(), e.PrintAllExceptions()); return; } } EventAggregator.GetEvent <AfterRemoveSpecificationEvent>().Publish(specification); }, () => SelectedItem != null); }
protected DirectumTasksViewModelBase(IUnityContainer container) : base(container) { CreateDirectumTaskCommand = new DelegateLogCommand( () => { RegionManager.RequestNavigateContentRegion <DirectumTaskView>(new NavigationParameters()); }); }
/// <summary> /// /// </summary> /// <param name="container"></param> /// <param name="load">Необходимость автоматической загрузки.</param> public PaymentsPlanViewModel(IUnityContainer container, bool load = true) : base(container) { ReloadCommand = new DelegateLogCommand(Load); if (load) { Load(); } }
public TabNavigation(IUnityContainer container) { InitializeComponent(); Container = container; RegionManager = Container.Resolve <IRegionManager>(); GoForwardCommand = new DelegateLogCommand(GoForwardCommand_Execute, GoForwardCommand_CanExecute); GoBackCommand = new DelegateLogCommand(GoBackCommand_Execute, GoBackCommand_CanExecute); }
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 ShippingViewModel(IUnityContainer container) : base(container) { SaveCommand = new DelegateLogCommand( () => { _salesUnits.AcceptChanges(); UnitOfWork.SaveChanges(); }, () => _salesUnits != null && _salesUnits.IsChanged && _salesUnits.IsValid); }
protected UnitsContainer(IUnityContainer container) : base(container) { DetailsViewModel = container.Resolve <TDetailsViewModel>(); GroupsViewModel = container.Resolve <TGroupsViewModel>(); SaveCommand = new DelegateLogCommand( () => { //отписка от событий изменения строк с оборудованием this.GroupsViewModel.GroupChanged -= OnGroupChanged; GroupsViewModel.AcceptChanges(); //добавляем сущность, если ее не существовало if (UnitOfWork.Repository <TModel>().GetById(DetailsViewModel.Item.Model.Id) == null) { UnitOfWork.Repository <TModel>().Add(DetailsViewModel.Item.Model); } DetailsViewModel.Item.AcceptChanges(); Container.Resolve <IEventAggregator>().GetEvent <TAfterSaveModelEvent>().Publish(DetailsViewModel.Item.Model); //сохраняем try { UnitOfWork.SaveChanges(); } catch (DbUpdateConcurrencyException e) { Container.Resolve <IMessageService>().ShowOkMessageDialog("Ошибка при сохранении", e.PrintAllExceptions()); } //регистрация на события изменения строк с оборудованием this.GroupsViewModel.GroupChanged += OnGroupChanged; SaveCommand.RaiseCanExecuteChanged(); }, () => { //все сущности должны быть валидны if (!GroupsViewModel.IsValid || !DetailsViewModel.Item.IsValid) { return(false); } //какая-то сущность должна быть изменена return(DetailsViewModel.Item.IsChanged || GroupsViewModel.IsChanged); }); RoundUpCommand = new DelegateLogCommand( () => { GroupsViewModel.RoundUpGroupsCosts(RoundUpAccuracy); }); }
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; }); }
public OffersViewModel(IUnityContainer container) : base(container) { PrintOfferCommand = new DelegateLogCommand( () => { Container.Resolve <IPrintOfferService>().PrintOffer(SelectedItem.Id); }, () => SelectedItem != null); this.SelectedLookupChanged += lookup => { PrintOfferCommand.RaiseCanExecuteChanged(); }; }
public IncomingRequestViewModel(IUnityContainer container) : base(container) { _messageService = container.Resolve <IMessageService>(); _fileManagerService = container.Resolve <IFileManagerService>(); InstructRequestCommand = new DelegateLogCommand( () => { Item.IsActual = true; Item.InstructionDate = DateTime.Now; //сохраняем запрос SaveCommand.Execute(null); //закрываем запрос GoBackCommand.Execute(null); }, () => Item.IsValid && Item.IsChanged && Item.Performers.Any()); RequestIsNotActualCommand = new DelegateLogCommand( () => { var dr = _messageService.ShowYesNoMessageDialog("Подтверждение", "Вы уверены, что запрос не актуален?", defaultYes: true); if (dr != MessageDialogResult.Yes) { return; } Item.IsActual = false; Item.Performers.Clear(); //сохраняем запрос if (Item.IsChanged) { SaveCommand.Execute(null); } //закрываем запрос GoBackCommand.Execute(null); }, () => Item.IsValid); OpenFolderCommand = new DelegateLogCommand( () => { if (string.IsNullOrEmpty(GlobalAppProperties.Actual.IncomingRequestsPath)) { _messageService.ShowOkMessageDialog("Информация", "Путь к хранилищу приложений не назначен"); return; } var path = _fileManagerService.GetPath(Item.Model.Document); Process.Start($"\"{path}\""); }); }
protected override void InitSpecialCommands() { SelectProductCommand = new DelegateLogCommand( () => { var product = Container.Resolve <IGetProductService>().GetProduct(Item.Model.Product); if (product != null) { product = UnitOfWork.Repository <Product>().GetById(product.Id); Item.Product = new ProductWrapper(product); } }); }
public PaymentsViewModel(IUnityContainer container) : base(container) { SaveCommand = new DelegateLogCommand( () => { List <SalesUnit> changedSalesUnits = _salesUnitWrappers .Where(salesUnitWrapper1 => salesUnitWrapper1.IsChanged) .Select(salesUnitWrapper1 => salesUnitWrapper1.Model) .ToList(); _salesUnitWrappers.AcceptChanges(); UnitOfWork.SaveChanges(); var afterSaveSalesUnitEvent = container.Resolve <IEventAggregator>().GetEvent <AfterSaveSalesUnitEvent>(); foreach (var changedSalesUnit in changedSalesUnits) { afterSaveSalesUnitEvent.Publish(changedSalesUnit); } }, () => _salesUnitWrappers != null && _salesUnitWrappers.IsChanged && _salesUnitWrappers.IsValid); RefreshCommand = new DelegateLogCommand(RefreshPayments); RemoveCommand = new DelegateLogCommand( () => { (SelectedItem as PaymentsGroup)?.RemovePayments(UnitOfWork); (SelectedItem as PaymentWrapper)?.Remove(UnitOfWork); }, () => { if (SelectedItem is PaymentsGroup paymentsGroup) { if (paymentsGroup.IsCustom != null) { return(paymentsGroup.IsCustom.Value); } return(false); } if (SelectedItem is PaymentWrapper item) { return(item.IsInPlanPayments); } return(false); }); }
public PriceCalculationsViewModel(IUnityContainer container) : base(container) { Load(); this.SelectedLookupChanged += lookup => { EditCalculationCommand.RaiseCanExecuteChanged(); RemoveCalculationCommand.RaiseCanExecuteChanged(); LoadFileCommand.RaiseCanExecuteChanged(); }; NewCalculationCommand = new NewCalculationCommand(this.RegionManager); EditCalculationCommand = new EditCalculationCommand(this, this.RegionManager); RemoveCalculationCommand = new RemoveCalculationCommand(this, this.Container); LoadFileCommand = new LoadFileCommand(this, this.Container); ReloadCommand = new DelegateLogCommand(Load); }
public SpecificationSignDatesViewModel(IUnityContainer container) : base(container) { SaveCommand = new DelegateLogCommand( () => { //сохраняем изменения if (_unitOfWork.SaveChanges().OperationCompletedSuccessfully) { //принимаем все изменения _specifications.AcceptChanges(); } //проверяем актуальность команды SaveCommand.RaiseCanExecuteChanged(); }, () => _specifications != null && _specifications.IsValid && _specifications.IsChanged); }
public ServiceRealizationDatesViewModel(IUnityContainer container) : base(container) { SaveCommand = new DelegateLogCommand( () => { _items.PropertyChanged -= ItemsOnPropertyChanged; //принимаем все изменения _items.AcceptChanges(); //сохраняем изменения _unitOfWork.SaveChanges(); //проверяем актуальность команды SaveCommand.RaiseCanExecuteChanged(); _items.PropertyChanged += ItemsOnPropertyChanged; }, () => _items != null && _items.IsValid && _items.IsChanged); }
public UserSettingsViewModel(IUnityContainer container) { _container = container; var eventServiceClient = _container.Resolve <IEventServiceClient>(); StartEventServiceCommand = new DelegateLogCommand( () => { eventServiceClient.Stop(); eventServiceClient.Start(); }); StopEventServiceCommand = new DelegateLogCommand( () => { eventServiceClient.Stop(); }); }
public ProjectDetailsViewModel1(IUnityContainer container) : base(container) { SelectProjectTypeCommand = new DelegateLogCommand( () => { List <ProjectType> projectTypes = UnitOfWork.Repository <ProjectType>().GetAll(); //выбор сущности var selectedProjectType = Container.Resolve <ISelectService>().SelectItem(projectTypes, Item.ProjectType?.Model.Id); //замена текущего значения новым if (selectedProjectType != null && !Equals(selectedProjectType.Id, Item.ProjectType?.Model.Id)) { selectedProjectType = UnitOfWork.Repository <ProjectType>().GetById(selectedProjectType.Id); Item.ProjectType = new ProjectTypeSimpleWrapper(selectedProjectType); } }); ClearProjectTypeCommand = new DelegateLogCommand(() => { Item.ProjectType = null; }); }
public FacilityViewModel(IUnityContainer container) : base(container) { SelectAddressLocalityCommand = new DelegateLogCommand( () => { List <Locality> localities = UnitOfWork.Repository <Locality>().GetAll(); Locality locality = Container.Resolve <ISelectService>().SelectItem(localities, Item.Address.Locality?.Model.Id); if (locality != null && locality.Id != Item.Address.Locality?.Model.Id) { locality = UnitOfWork.Repository <Locality>().GetById(locality.Id); Item.Address.Locality = new LocalityWrapper(locality); } }); ClearAddressLocalityCommand = new DelegateLogCommand( () => { Item.Address.Locality = 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(); }
public DocumentViewModel(IUnityContainer container) : base(container) { _fileManagerService = container.Resolve <IFileManagerService>(); OpenFolderCommand = new DelegateLogCommand( () => { if (string.IsNullOrEmpty(GlobalAppProperties.Actual.IncomingRequestsPath)) { Container.Resolve <IMessageService>().ShowOkMessageDialog("Информация", "Путь к хранилищу приложений не назначен"); return; } var path = _fileManagerService.GetPath(Item.Model); Process.Start("explorer", $"\"{path}\""); }); AddFilesCommand = new DelegateLogCommand( () => { var openFileDialog = new OpenFileDialog { Multiselect = true, RestoreDirectory = true }; if (openFileDialog.ShowDialog() == DialogResult.OK) { var rootDirectoryPath = _fileManagerService.GetPath(Item.Model); foreach (var fileName in openFileDialog.FileNames) { File.Copy(fileName, $"{rootDirectoryPath}\\{Path.GetFileName(fileName)}"); } } }); }
public PickingDatesViewModel(IUnityContainer container) : base(container) { SaveCommand = new DelegateLogCommand( () => { _salesUnits.PropertyChanged -= SalesUnitsOnPropertyChanged; //сохраняем изменения UnitOfWork.SaveChanges(); //принимаем все изменения _salesUnits.Where(x => x.IsChanged).ToList().ForEach(x => x.AcceptChanges()); //проверяем актуальность команды SaveCommand.RaiseCanExecuteChanged(); _salesUnits.PropertyChanged += SalesUnitsOnPropertyChanged; }, () => _salesUnits != null && _salesUnits.IsValid && _salesUnits.IsChanged); ReloadCommand = new DelegateLogCommand(Load); Load(); }
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(); }
protected BaseGroupsViewModel(IUnityContainer container) : base(container) { AddCommand = new DelegateLogCommand(AddCommand_Execute, AddCommand_CanExecute); RemoveCommand = new DelegateLogCommand(RemoveCommand_Execute, () => Groups.SelectedGroup != null); ChangeFacilityCommand = new DelegateCommand <TGroup>(ChangeFacilityCommand_Execute); ChangeProductCommand = new DelegateCommand <TGroup>(ChangeProductCommand_Execute); ChangePaymentsCommand = new DelegateCommand <TGroup>(ChangePaymentsCommand_Execute); #region ProductIncludedCommands //добавление включенного оборудования AddProductIncludedCommand = new DelegateLogCommand( () => { var productIncludedWrapper = new ProductIncludedWrapper(new ProductIncluded()); var productsIncludedViewModel = new ProductsIncludedViewModel(productIncludedWrapper, UnitOfWork, Container); var dr = Container.Resolve <IDialogService>().ShowDialog(productsIncludedViewModel); if (!dr.HasValue || !dr.Value) { return; } Groups.SelectedGroup.AddProductIncluded(productsIncludedViewModel.ViewModel.Entity, productsIncludedViewModel.IsForEach); RefreshPrice(Groups.SelectedGroup); }, () => Groups.SelectedGroup != null); //удаление включенного оборудования RemoveProductIncludedCommand = new DelegateLogCommand( () => { if (Container.Resolve <IMessageService>().ShowYesNoMessageDialog("Удаление", "Удалить?", defaultNo: true) == MessageDialogResult.No) { return; } Groups.SelectedGroup.RemoveProductIncluded(Groups.SelectedProductIncluded); RefreshPrice(Groups.SelectedGroup); }, () => Groups.SelectedProductIncluded != null); //установка нестандартной себестоимости шеф-монтажа SetCustomFixedPriceCommand = new DelegateLogCommand( () => { //шеф-монтажи, которые подлежат изменению var productsIncludedTarget = Groups .Where(x => x.Groups != null) .SelectMany(x => x.Groups) .SelectMany(x => x.ProductsIncluded) .Where(x => Equals(x.Model.Id, Groups.SelectedProductIncluded.Model.Id)) .ToList(); var productIncluded = productsIncludedTarget.Any() ? productsIncludedTarget.Select(x => x.Model).Distinct().Single() : Groups.SelectedProductIncluded.Model; var original = productIncluded.CustomFixedPrice; var viewModel = new SupervisionPriceViewModel(new ProductIncludedWrapper(productIncluded), UnitOfWork, Container); var dr = Container.Resolve <IDialogService>().ShowDialog(viewModel); if (dr.HasValue || dr.Value == true) { productsIncludedTarget.ForEach(x => x.CustomFixedPrice = productIncluded.CustomFixedPrice); } else { productsIncludedTarget.ForEach(x => x.CustomFixedPrice = original); } if (!Equals(productIncluded.CustomFixedPrice, original)) { RefreshPrice(Groups.SelectedGroup); } }, () => Groups.SelectedProductIncluded != null && Groups.SelectedProductIncluded.Model.Product.ProductBlock.IsSupervision); #endregion Groups.SumChanged += () => { RaisePropertyChanged(nameof(Sum)); }; }
protected BaseListViewModel(IUnityContainer container) : base(container) { DialogService = Container.Resolve <IDialogService>(); MessageService = Container.Resolve <IMessageService>(); EventAggregator = Container.Resolve <IEventAggregator>(); Lookups = new ObservableCollection <TLookup>(); NewItemCommand = new DelegateLogCommand(NewItemCommand_Execute, NewItemCommand_CanExecute); EditItemCommand = new DelegateLogCommand(EditItemCommand_Execute, EditItemCommand_CanExecute); RemoveItemCommand = new DelegateLogCommand(RemoveItemCommand_Execute, RemoveItemCommand_CanExecute); SelectItemCommand = new DelegateLogCommand(SelectItemCommand_Execute, SelectItemCommand_CanExecute); SelectItemsCommand = new DelegateLogCommand( () => { CloseRequested?.Invoke(this, new DialogRequestCloseEventArgs(true)); }, () => SelectedItems != null); RefreshCommand = new DelegateLogCommand(RefreshCommand_Execute); UnionCommand = new DelegateLogCommand( () => { var selectedItem = container.Resolve <ISelectService>().SelectItem(SelectedItems); if (selectedItem == null) { return; } IUnitOfWork unitOfWork = container.Resolve <IUnitOfWork>(); var repository = unitOfWork.Repository <TEntity>(); TEntity mainItem = repository.GetById(selectedItem.Id); List <TEntity> otherItems = SelectedItems.Select(entity => repository.GetById(entity.Id)).ToList(); otherItems.Remove(mainItem); if (UnionItemsAction(unitOfWork, mainItem, otherItems) == false) { return; } foreach (var otherItem in otherItems) { EventAggregator.GetEvent <TAfterRemoveEntityEvent>().Publish(otherItem); } repository.DeleteRange(otherItems); unitOfWork.SaveChanges(); container.Resolve <IMessageService>().ShowOkMessageDialog("Информация", "Объединение успешно завершено!"); }, () => SelectedItems != null && SelectedItems.Count() > 1); EventAggregator.GetEvent <TAfterSaveEntityEvent>().Subscribe(OnAfterSaveEntity); EventAggregator.GetEvent <TAfterRemoveEntityEvent>().Subscribe(OnAfterRemoveEntity); this.LoadBegin += () => IsLoaded = false; this.Loaded += () => IsLoaded = true; InitSpecialCommands(); SubscribesToEvents(); LastActionInCtor(); }
public AdminViewModel(IUnityContainer container) { _container = container; Command = new DelegateLogCommand( () => { //try //{ // _container.Resolve<IEmailService>().SendMail("*****@*****.**", "SubjTest", "BodyTest"); // _container.Resolve<IEmailService>().SendMail("*****@*****.**", "SubjTest", "BodyTest"); // _container.Resolve<IMessageService>().ShowOkMessageDialog("Send letter", "Success!"); //} //catch (Exception e) //{ // _container.Resolve<IHvtAppLogger>().LogError(e.PrintAllExceptions(), e); // _container.Resolve<IMessageService>().ShowOkMessageDialog("Error", e.PrintAllExceptions()); //} var unitOfWork = _container.Resolve <IUnitOfWork>(); var requrementsTasks = unitOfWork.Repository <TechnicalRequrementsTask>().GetAll(); var bmb = unitOfWork.Repository <User>().Find(x => x.Employee.Person.Surname == "Игнатенко").FirstOrDefault(); foreach (var requrementsTask in requrementsTasks) { foreach (var historyElement in requrementsTask.HistoryElements) { if (historyElement.User != null) { continue; } switch (historyElement.Type) { case TechnicalRequrementsTaskHistoryElementType.Create: { historyElement.User = requrementsTask.FrontManager; break; } case TechnicalRequrementsTaskHistoryElementType.Start: { historyElement.User = requrementsTask.FrontManager; break; } case TechnicalRequrementsTaskHistoryElementType.Finish: { historyElement.User = requrementsTask.BackManager; break; } case TechnicalRequrementsTaskHistoryElementType.Reject: { historyElement.User = requrementsTask.BackManager; break; } case TechnicalRequrementsTaskHistoryElementType.Stop: { historyElement.User = requrementsTask.FrontManager; break; } case TechnicalRequrementsTaskHistoryElementType.Instruct: { historyElement.User = bmb; break; } case TechnicalRequrementsTaskHistoryElementType.Accept: { historyElement.User = requrementsTask.FrontManager; break; } case TechnicalRequrementsTaskHistoryElementType.RejectByFrontManager: { historyElement.User = requrementsTask.FrontManager; break; } default: throw new ArgumentOutOfRangeException(); } } } var priceCalculations = unitOfWork.Repository <PriceCalculation>().GetAll(); var pricer = unitOfWork.Repository <User>().Find(x => x.Employee.Person.Surname == "Шарапова").FirstOrDefault(); foreach (var priceCalculation in priceCalculations) { foreach (var historyItem in priceCalculation.History) { if (historyItem.User != null) { continue; } switch (historyItem.Type) { case PriceCalculationHistoryItemType.Start: { historyItem.User = priceCalculation.Initiator; break; } case PriceCalculationHistoryItemType.Stop: { historyItem.User = priceCalculation.Initiator; break; } case PriceCalculationHistoryItemType.Reject: { historyItem.User = pricer; break; } case PriceCalculationHistoryItemType.Finish: { historyItem.User = pricer; break; } default: throw new ArgumentOutOfRangeException(); } } } unitOfWork.SaveChanges(); unitOfWork.Dispose(); _container.Resolve <IMessageService>().ShowOkMessageDialog("fin", "!!!"); ////var unitOfWork = container.Resolve<IUnitOfWork>(); //var dependent = new Dependent {Name = "dep1"}; //var mList = new List<Main>(); //for (int i = 0; i < 4; i++) //{ // mList.Add(new Main {Name = $"main{i}", Dependent = dependent}); //} //var serializer = new XmlSerializer(typeof(List<Main>)); //using (var fs = new FileStream(@"G:\main.xml", FileMode.Create)) //{ // serializer.Serialize(fs, mList); //} //using (var fs = new FileStream(@"G:\main.xml", FileMode.Open)) //{ // var list = (List<Main>)serializer.Deserialize(fs); // var dep = list.Select(x => x.Dependent).Distinct().ToList(); //} }); }
protected override void InitSpecialCommands() { SelectProductCommand = new DelegateLogCommand(SelectProductCommand_Execute); }
protected override void InitSpecialCommands() { EditItemCommand = new DelegateLogCommand(EditItemCommandExecute, () => SelectedItem != null); RemoveItemCommand = new DelegateLogCommand(RemoveItemCommand_Execute, () => SelectedItem != null); }