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 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 List <GoodsStorageModel> GetAll(int state) { List <GoodsStorageModel> goodsStorageModels = new List <GoodsStorageModel>(); List <GoodsStorage> goodsStorageList = _goodsStorageService.GetAll(c => c.State == state); foreach (var goodsStorage in goodsStorageList) { GoodsStorageModel tempGoodsStorageModel = new GoodsStorageModel { Id = goodsStorage.Id, GoodsName = _goodsService.Find(goodsStorage.GoodsId).Name, StorageName = _storageService.Find(goodsStorage.StorageId).Name, RegionName = _regionService.Find(goodsStorage.RegionId).Name, CreatedTime = goodsStorage.CreatedTime.ToString("F") }; goodsStorageModels.Add(tempGoodsStorageModel); } return(goodsStorageModels); }