Example #1
0
        private void SaveMethod()
        {
            StockUnit.UnitList = UnitList;
            if (!SetCard())
            {
                return;
            }

            foreach (var unit in UnitList)
            {
                unit.StockUnit = StockUnit;
            }

            if (!CheckValues())
            {
                return;
            }

            _stockUnitRepository.Save(StockUnit);

            var unitRepository = new UnitRepository();

            unitRepository.Save(UnitList);
            unitRepository.Delete(_itemsToDelete);

            foreach (var note in StockUnitNoteList)
            {
                note.StockUnit = StockUnit;
            }
            _stockUnitNoteRepository.Save(StockUnitNoteList);

            var fileRepository = new StockUnitFileRepository();

            if (!SaveStockUnitFiles())
            {
                return;
            }
            fileRepository.Save(StockUnitFiles);
            fileRepository.Delete(_deletedStockUnitFiles);

            var         user       = ApplicationState.GetValue <UserAcc>("User");
            ILogFactory logFactory = new LogFactory();
            var         logEntity  = logFactory.CreateMessage(user, StockUnit);
            var         repository = new Repository <Log>();

            repository.Save(logEntity);

            CloseAction();
        }
Example #2
0
        private void InitViewModel(StockUnit stockUnit)
        {
            _itemsToDelete         = new List <Unit>();
            _addedFiles            = new List <string>();
            _deletedFiles          = new List <string>();
            _deletedStockUnitFiles = new List <StockUnitFile>();

            StockUnit = stockUnit;
            if (StockUnit.IsNew && StockUnit.UnitList == null)
            {
                StockUnit.UnitList = new List <Unit>();
            }

            InitLists();
            UnitList = new ObservableCollection <Unit>(StockUnit.UnitList);
            UnitList.CollectionChanged += UnitList_CollectionChanged;

            var documentRepository = new DocumentRepository();

            DocumnetsList = new ObservableCollection <Document>(documentRepository.GetByStockUnit(StockUnit));
            var repairRepository = new RepairRepository();

            RepairList = new ObservableCollection <Repair>(repairRepository.GetAllByStockUnit(StockUnit));
            var filesRepository = new StockUnitFileRepository();

            StockUnitFiles = new ObservableCollection <StockUnitFile>(filesRepository.GetByStockUnitId(StockUnit));

            StockUnitNoteList = !StockUnit.IsNew ?
                                new ObservableCollection <StockUnitNote>(_stockUnitNoteRepository.GetByStockUnitId(StockUnit))
                : new ObservableCollection <StockUnitNote>();

            var repository = new UnitRepository();

            ManufactureList = repository.GetManufactureList();
            ModelList       = repository.GetModelList();

            AddUnitCommand    = new RelayCommand(x => UnitList.Add(new Unit()));
            RemoveUnitCommand = new RelayCommand(x => RemoveMethod());
            ReportsCommand    = new RelayCommand(x => ReportsMethod());
            SaveCommand       = new RelayCommand(x => SaveMethod());
            CloseCommand      = new RelayCommand(x => CloseMethod());
            AddFileCommand    = new RelayCommand(x => AddFileMethod());
            RemoveFileCommand = new RelayCommand(x => RemoveFileMethod());
            OpenFileCommand   = new RelayCommand(x => OpenFileMethod());
            OpenFolderCommand = new RelayCommand(x => OpenFolderMethod());
        }