public bool CanBuild(SessionDto session, int furnitureItemId) { SessionService.CheckSession(session); InvariantPartStore itemPartStore = GetPartStore(furnitureItemId); InvariantPartStore userPartStore = PartService.GetOwnedInvariant(session); return(userPartStore.Contains(itemPartStore)); }
public IEnumerable <FurnitureItemModel> GetBuildList(SessionDto session) { return(ProtectedExecute <SessionDto, FurnitureItemModel>(sessionDto => { SessionService.CheckSession(session); Dictionary <FurnitureItemModel, InvariantPartStore> partStores = GetAll().ToDictionary( furniture => furniture, furniture => GetPartStore(furniture.Id) ); InvariantPartStore userPartStore = PartService.GetOwnedInvariant(sessionDto); return partStores.Where(store => userPartStore.Contains(store.Value)) .Select(store => store.Key).ToList(); }, session)); }
public InvariantPartStore GetPartStore(int furnitureItemId) { FurnitureItemModel furniture = FurnitureRepo.Get(furnitureItemId); if (furniture == null) { throw new NotFoundException("furniture"); } IEnumerable <IGrouping <int, UsedPartModel> > usedParts = furniture.UsedParts.Where(part => part.PartId.HasValue) .GroupBy(part => part.PartId.Value); InvariantPartStore store = new InvariantPartStore(); foreach (IGrouping <int, UsedPartModel> used in usedParts) { PartModel part = PartRepo.Get(used.Key); InvariantPartStorePosition position = new InvariantPartStorePosition(part, used.Count()); store.Positions.Add(position); } return(store); }