Esempio n. 1
0
        public MethodResult CanBuyOffer(MarketOffer offer, int amount, House house, Entity entity)
        {
            if (offer == null)
            {
                return(new MethodResult(MarketOfferErrors.OfferNotExist));
            }

            var productType = ((ProductTypeEnum)offer.ProductID);

            if (offer.Amount < amount)
            {
                return(new MethodResult(MarketOfferErrors.NotEnoughProducts));
            }

            if (amount <= 0)
            {
                return(new MethodResult("Are you crazy?"));
            }

            if (productType != ProductTypeEnum.UpgradePoints && productType != ProductTypeEnum.ConstructionMaterials)
            {
                return(new MethodResult(MarketOfferErrors.NotAllowedProduct));
            }

            if (offer.Company.GetCompanyType() != CompanyTypeEnum.Manufacturer)
            {
                return(new MethodResult("You cannot buy that offer!"));
            }

            var cost = marketService.GetOfferCost(offer, entity, amount);

            if (cost == null)
            {
                return(new MethodResult("You cannot buy that offer!"));
            }

            if (walletService.HaveMoney(entity.WalletID, cost.ClientPriceMoney) == false)
            {
                return(new MethodResult(MarketOfferErrors.NotEnoughMoney));
            }

            if (productType == ProductTypeEnum.ConstructionMaterials)
            {
                var chest = houseFurnitureRepository.GetHouseChest(house.ID);

                if (houseChestService.GetUnusedSpace(chest) < amount)
                {
                    return(new MethodResult("You do not have enough space in chest!"));
                }
            }



            return(MethodResult.Success);
        }
Esempio n. 2
0
        public ActionResult Chest(long houseID)
        {
            var house  = houseRepository.GetById(houseID);
            var result = houseService.CanModifyHouse(house, SessionHelper.CurrentEntity);

            if (result.IsError)
            {
                return(RedirectBackWithError(result));
            }

            var equipment = equipmentRepository.GetByEntityID(SessionHelper.LoggedCitizen.ID);
            var chest     = houseFurnitureRepository.GetHouseChest(houseID);

            var vm = new HouseChestViewModel(house, equipment, chest, houseService.GetHouseRights(house, SessionHelper.CurrentEntity));

            return(View(vm));
        }