コード例 #1
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);
        }
コード例 #2
0
        public BuildSessionModel InitBuildSession(StartBuildDto startBuildDto)
        {
            SessionService.CheckSession(startBuildDto.Session);
            FurnitureItemModel furniture = FurnitureRepo.Get(startBuildDto.FurnitureId.Value);

            if (furniture == null)
            {
                throw new NotFoundException("furniture");
            }

            bool canBuild = FurnitureService.CanBuild(startBuildDto.Session, startBuildDto.FurnitureId.Value);

            if (!canBuild)
            {
                throw new NotFoundException("all owned parts");
            }

            int userId = startBuildDto.Session.UserId.Value;

            if (UserBuildTokens.ContainsKey(userId))
            {
                RemoveSessionByUserId(userId);
            }
            //throw new ConflictException("build sessions");

            string token = HashingService.GetHash(Guid.NewGuid().ToString());

            IEnumerable <ConcretePartModel> possiblePartsToUse = ConcretePartRepo
                                                                 .GetOwnedByUser(userId)
                                                                 .Where(part => !part.IsForSell && !part.IsInUse)
                                                                 .ToList();

            BuildSessionManager buildSessionInfo = new BuildSessionManager(
                userId, possiblePartsToUse, furniture,
                new BuildSessionModel(token, furniture.Id)
                );

            UserBuildTokens.Add(userId, token);
            BuildSessions.Add(token, buildSessionInfo);
            return(buildSessionInfo.BuildSession);
        }