示例#1
0
        public ActionResult BuyOffer(long houseID, int offerID, int amount)
        {
            var house  = houseRepository.GetById(houseID);
            var entity = SessionHelper.CurrentEntity;

            var result = houseService.CanViewHouse(house, entity);

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

            var offer = marketOfferRepository.GetById(offerID);

            using (var trs = transactionScopeProvider.CreateTransactionScope())
            {
                result = houseService.CanBuyOffer(offer, amount, house, SessionHelper.CurrentEntity);

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

                int productID = offer.ProductID;
                marketService.Buy(offer, SessionHelper.LoggedCitizen.Entity, amount);

                var item  = equipmentRepository.GetEquipmentItem(SessionHelper.CurrentEntity.EquipmentID.Value, productID, 1);
                var chest = houseFurnitureRepository.GetHouseChest(houseID);
                houseChestService.TransferItemToChest(SessionHelper.CurrentEntity, item, chest, amount);
                trs.Complete();
            }

            return(RedirectBackWithSuccess("Item has been transfered!"));
        }