void ConfigureDlg()
        {
            if (StoreDocumentHelper.CheckAllPermissions(UoW.IsNew, WarehousePermissions.RegradingOfGoodsEdit, Entity.Warehouse))
            {
                FailInitialize = true;
                return;
            }

            var editing = StoreDocumentHelper.CanEditDocument(WarehousePermissions.RegradingOfGoodsEdit, Entity.Warehouse);

            ytextviewCommnet.Editable           = editing;
            regradingofgoodsitemsview.Sensitive = editing;

            ylabelDate.Binding.AddFuncBinding(Entity, e => e.TimeStamp.ToString("g"), w => w.LabelProp).InitializeFromSource();

            var userHasOnlyAccessToWarehouseAndComplaints =
                ServicesConfig.CommonServices.CurrentPermissionService.ValidatePresetPermission("user_have_access_only_to_warehouse_and_complaints") &&
                !ServicesConfig.CommonServices.UserService.GetCurrentUser(UoW).IsAdmin;

            if (userHasOnlyAccessToWarehouseAndComplaints)
            {
                warehouseEntry.CanEditReference = false;
            }
            else
            {
                warehouseEntry.CanEditReference = true;
            }

            var availableWarehousesIds = StoreDocumentHelper.GetRestrictedWarehousesIds(UoW, WarehousePermissions.RegradingOfGoodsEdit);
            var warehouseFilter        = new WarehouseJournalFilterViewModel
            {
                IncludeWarehouseIds = availableWarehousesIds
            };

            warehouseEntry.SetEntityAutocompleteSelectorFactory(new WarehouseSelectorFactory(warehouseFilter));
            warehouseEntry.Binding.AddBinding(Entity, e => e.Warehouse, w => w.Subject).InitializeFromSource();
            ytextviewCommnet.Binding.AddBinding(Entity, e => e.Comment, w => w.Buffer.Text).InitializeFromSource();

            regradingofgoodsitemsview.DocumentUoW = UoWGeneric;
            if (Entity.Items.Count > 0)
            {
                warehouseEntry.Sensitive = false;
            }

            var permmissionValidator = new EntityExtendedPermissionValidator(PermissionExtensionSingletonStore.GetInstance(), _employeeRepository);

            Entity.CanEdit = permmissionValidator.Validate(typeof(RegradingOfGoodsDocument), _userRepository.GetCurrentUser(UoW).Id, nameof(RetroactivelyClosePermission));
            if (!Entity.CanEdit && Entity.TimeStamp.Date != DateTime.Now.Date)
            {
                ytextviewCommnet.Binding.AddFuncBinding(Entity, e => e.CanEdit, w => w.Sensitive).InitializeFromSource();
                warehouseEntry.Binding.AddFuncBinding(Entity, e => e.CanEdit, w => w.Sensitive).InitializeFromSource();
                regradingofgoodsitemsview.Sensitive = false;

                buttonSave.Sensitive = false;
            }
            else
            {
                Entity.CanEdit = true;
            }
        }
        protected override void ConfigureWithUow()
        {
            var warehousesList = StoreDocumentHelper.GetRestrictedWarehousesList(UoW, new[] { WarehousePermissions.WarehouseView })
                                 .OrderBy(w => w.Name).ToList();

            bool accessToWarehouseAndComplaints =
                ServicesConfig.CommonServices.CurrentPermissionService.ValidatePresetPermission("user_have_access_only_to_warehouse_and_complaints") &&
                !ServicesConfig.CommonServices.UserService.GetCurrentUser(UoW).IsAdmin;

            if (warehousesList.Count > 5)
            {
                entryWarehouses.Subject = CurrentUserSettings.Settings.DefaultWarehouse ?? null;
                var warehouseFilter = new WarehouseJournalFilterViewModel
                {
                    IncludeWarehouseIds = warehousesList.Select(x => x.Id)
                };
                entryWarehouses.SetEntityAutocompleteSelectorFactory(new WarehouseSelectorFactory(warehouseFilter));

                entryWarehouses.Visible     = true;
                yspeccomboWarehouse.Visible = false;
            }
            else
            {
                yspeccomboWarehouse.ItemsList    = warehousesList;
                yspeccomboWarehouse.SelectedItem = CurrentUserSettings.Settings.DefaultWarehouse ?? null;

                entryWarehouses.Visible     = false;
                yspeccomboWarehouse.Visible = true;
            }

            if (accessToWarehouseAndComplaints)
            {
                entryWarehouses.Sensitive = yspeccomboWarehouse.Sensitive = false;
            }
        }
 public WarehouseSelectorFactory(WarehouseJournalFilterViewModel filterViewModel = null)
 {
     _filterViewModel = filterViewModel;
 }
        void ConfigureDlg()
        {
            if (StoreDocumentHelper.CheckAllPermissions(UoW.IsNew, WarehousePermissions.IncomingWaterEdit, Entity.IncomingWarehouse, Entity.WriteOffWarehouse))
            {
                FailInitialize = true;
                return;
            }

            var editing = StoreDocumentHelper.CanEditDocument(WarehousePermissions.IncomingWaterEdit, Entity.IncomingWarehouse, Entity.WriteOffWarehouse);

            buttonFill.Sensitive = yentryProduct.IsEditable = spinAmount.Sensitive = editing;
            incomingwatermaterialview1.Sensitive = editing;

            labelTimeStamp.Binding.AddBinding(Entity, e => e.DateString, w => w.LabelProp).InitializeFromSource();
            spinAmount.Binding.AddBinding(Entity, e => e.Amount, w => w.ValueAsInt).InitializeFromSource();

            var userHasOnlyAccessToWarehouseAndComplaints =
                ServicesConfig.CommonServices.CurrentPermissionService.ValidatePresetPermission("user_have_access_only_to_warehouse_and_complaints") &&
                !ServicesConfig.CommonServices.UserService.GetCurrentUser(UoW).IsAdmin;

            if (userHasOnlyAccessToWarehouseAndComplaints)
            {
                sourceWarehouseEntry.CanEditReference = destinationWarehouseEntry.CanEditReference = false;
            }
            else
            {
                sourceWarehouseEntry.CanEditReference = destinationWarehouseEntry.CanEditReference = true;
            }

            var availableWarehousesIds = StoreDocumentHelper.GetRestrictedWarehousesIds(UoW, WarehousePermissions.IncomingWaterEdit);
            var warehouseFilter        = new WarehouseJournalFilterViewModel
            {
                IncludeWarehouseIds = availableWarehousesIds
            };
            var warehouseAutocompleteSelectorFactory = new WarehouseSelectorFactory(warehouseFilter);

            sourceWarehouseEntry.SetEntityAutocompleteSelectorFactory(warehouseAutocompleteSelectorFactory);
            sourceWarehouseEntry.Binding.AddBinding(Entity, e => e.WriteOffWarehouse, w => w.Subject).InitializeFromSource();
            destinationWarehouseEntry.SetEntityAutocompleteSelectorFactory(warehouseAutocompleteSelectorFactory);
            destinationWarehouseEntry.Binding.AddBinding(Entity, e => e.IncomingWarehouse, w => w.Subject).InitializeFromSource();

            incomingwatermaterialview1.DocumentUoW = UoWGeneric;

            var permmissionValidator =
                new EntityExtendedPermissionValidator(PermissionExtensionSingletonStore.GetInstance(), _employeeRepository);

            Entity.CanEdit =
                permmissionValidator.Validate(
                    typeof(IncomingWater), _userRepository.GetCurrentUser(UoW).Id, nameof(RetroactivelyClosePermission));

            if (!Entity.CanEdit && Entity.TimeStamp.Date != DateTime.Now.Date)
            {
                spinAmount.Binding.AddFuncBinding(Entity, e => e.CanEdit, w => w.Sensitive).InitializeFromSource();
                yentryProduct.Sensitive             = false;
                destinationWarehouseEntry.Sensitive = false;
                sourceWarehouseEntry.Sensitive      = false;
                buttonFill.Sensitive = false;
                incomingwatermaterialview1.Sensitive = false;
                buttonSave.Sensitive = false;
            }
            else
            {
                Entity.CanEdit = true;
            }

            var nomenclatureFilter = new NomenclatureFilterViewModel()
            {
                HidenByDefault = true
            };
            var nomenclatureRepository =
                new EntityRepositories.Goods.NomenclatureRepository(new NomenclatureParametersProvider(new ParametersProvider()));
            var counterpartyJournalFactory = new CounterpartyJournalFactory();

            var nomenclatureAutoCompleteSelectorFactory =
                new NomenclatureAutoCompleteSelectorFactory <Nomenclature, NomenclaturesJournalViewModel>(
                    ServicesConfig.CommonServices,
                    nomenclatureFilter,
                    counterpartyJournalFactory,
                    nomenclatureRepository,
                    _userRepository
                    );

            yentryProduct.SetEntityAutocompleteSelectorFactory(nomenclatureAutoCompleteSelectorFactory);
            yentryProduct.Binding.AddBinding(Entity, e => e.Product, w => w.Subject).InitializeFromSource();
        }