public bool Delete(int id) { Storage storage = Find(id); if (storage == null) { return(false); } List <StorageRegion> storageRegions = _storageRegionService.GetAll(c => c.StorageId == id); foreach (var storageRegion in storageRegions) { _storageRegionService.Delete(storageRegion); } List <GoodsStorage> goodsStorages = _goodsStorageService.GetAll(c => c.StorageId == id); foreach (var goodsStorage in goodsStorages) { _goodsStorageService.Delete(goodsStorage); } List <GoodsLeave> goodsLeaves = _leaveRepository.Select(c => c.StorageId == id); foreach (var goodsLeaf in goodsLeaves) { _leaveRepository.Delete(goodsLeaf); _unitOfWork.Commit(); } _repository.Delete(storage); return(_unitOfWork.Commit() > 0); }
public HomeModel GetHomeModel() { List <Storage> storageList = _storageService.GetAll(); HomeModel homeModel = new HomeModel() { UserTotal = _usersService.GetUsers().Count, GoodsTotal = _goodsService.GetAll().Count, StorageTotal = storageList.Count, RegionTotal = _regionService.GetAll().Count }; var storageInfoList = new List <ViewModel.StorageInfo>(); foreach (var storage in storageList) { ViewModel.StorageInfo temp = new StorageInfo() { JoinTotal = _goodsStorageService.GetAll(c => c.StorageId == storage.Id && c.State == 0).Count, StorageName = storage.Name }; List <StorageRegion> storageRegions = _storageRegionService.GetAll(c => c.StorageId == storage.Id); int total = 0; foreach (var storageRegion in storageRegions) { total += storageRegion.Capacity; } temp.Capacity = total - temp.JoinTotal; storageInfoList.Add(temp); } homeModel.StorageInfos = storageInfoList; return(homeModel); }
public List <Region> GetAllNotAdd(int id) { List <StorageRegion> storageRegions = _storageRegionService.GetAll(c => c.StorageId == id); int[] storageRegionArray = new int[storageRegions.Count]; int i = 0; foreach (var storageRegion in storageRegions) { storageRegionArray[i] = storageRegion.RegionId; i++; } List <Region> regions = GetAll(); int[] regionArray = new int[regions.Count]; int j = 0; foreach (var region in regions) { regionArray[j] = region.Id; j++; } int[] notAddArray = regionArray.Except(storageRegionArray).ToArray(); List <Region> allNotAddRegion = new List <Region>(); foreach (var t in notAddArray) { foreach (var t1 in regions) { if (t == t1.Id) { allNotAddRegion.Add(t1); break; } } } return(allNotAddRegion); }