Пример #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));
        }
Пример #2
0
        public void CheckActiveAdmin(SessionDto dto)
        {
            SessionService.CheckSession(dto);

            if (!IsAdmin(dto.UserId.GetValueOrDefault()))
            {
                throw new ForbiddenException("admin");
            }
        }
Пример #3
0
        private void CheckBuildSession(BuildSessionDto buildSession)
        {
            SessionService.CheckSession(buildSession.Session);

            if (!BuildSessions.ContainsKey(buildSession.BuildSessionToken))
            {
                throw new NotFoundException("build session");
            }

            BuildSessionManager sessionInfo = BuildSessions[buildSession.BuildSessionToken];

            if (buildSession.Session.UserId.Value != sessionInfo.UserId)
            {
                throw new NotFoundException("build session");
            }
        }
Пример #4
0
        public PaymentInfo CreateManufacturerTradePromise(AddManufacturerSellDto manufacturerSellDto, string callbackEndpoint)
        {
            if (manufacturerSellDto.NewAccountExtension == null && manufacturerSellDto.ExisitingAccountExtensionId == null)
            {
                throw new NotFoundException("nor old neither new account extension");
            }

            SessionService.CheckSession(manufacturerSellDto.Session);

            if (manufacturerSellDto.NewAccountExtension != null && manufacturerSellDto.NewAccountExtension.AccountId != manufacturerSellDto.Session.UserId)
            {
                throw new ForbiddenException("account owner");
            }

            AccountExtensionModel accountExtension = manufacturerSellDto.ExisitingAccountExtensionId == null ||
                                                     !manufacturerSellDto.ExisitingAccountExtensionId.HasValue ?
                                                     Mapper.Map <AccountExtensionDto, AccountExtensionModel>(manufacturerSellDto.NewAccountExtension) :
                                                     AccountExtensionRepo.Get(manufacturerSellDto.ExisitingAccountExtensionId.Value);

            if (accountExtension == null)
            {
                throw new NotFoundException("account extension");
            }

            if (accountExtension.AccountId != manufacturerSellDto.Session.UserId)
            {
                throw new ForbiddenException("account owner");
            }

            string    orderId   = Guid.NewGuid().ToString();
            SellModel sellModel = BuildOrderFromManufacturer(orderId, accountExtension, manufacturerSellDto.Positions);

            Sell sell = new Sell(orderId, sellModel);

            PendingOrders.Add(orderId, sell);

            PaymentPrepareModel paymentPrepare = new PaymentPrepareModel(orderId, sellModel.TotalPrice);

            paymentPrepare.CallbackUrl = callbackEndpoint;
            paymentPrepare.Expired     = sell.Expires;

            PaymentInfo payment = PaymentService.CreateFromUserPayment(paymentPrepare);

            sell.PaymentInfo = payment;

            return(payment);
        }
Пример #5
0
        public AccountModel Update(UpdateAccountDto dto)
        {
            return(ProtectedExecute <UpdateAccountDto, AccountModel>(accountDto =>
            {
                SessionService.CheckSession(accountDto.Session);

                if (accountDto.Id != accountDto.Session.UserId)
                {
                    throw new ForbiddenException("Account owner");
                }

                accountDto.Password = Hasher.GetHash(accountDto.Password);
                AccountModel model = Mapper.Map <UpdateAccountDto, AccountModel>(accountDto);

                return AccountRepo.Update(model.Id, model);
            }, dto));
        }
Пример #6
0
 public PartStore GetOwned(SessionDto ownerSession)
 {
     SessionService.CheckSession(ownerSession);
     return(new PartStore(GetOwnedConcrete(ownerSession)));
 }