Exemple #1
0
        public bool CanBuild(SessionDto session, int furnitureItemId)
        {
            SessionService.CheckSession(session);
            InvariantPartStore itemPartStore = GetPartStore(furnitureItemId);
            InvariantPartStore userPartStore = PartService.GetOwnedInvariant(session);

            return(userPartStore.Contains(itemPartStore));
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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);
        }