예제 #1
0
        public IActionResult CollectReward(
            [Bind(Prefix = "Reward")] Reward reward,
            [Bind(Prefix = "Quest")] Quest quest,
            [Bind(Prefix = "Rewards")] List <ItemReward> itemRewards
            )
        {
            var user   = _userManager.GetByEmail(User.Identity.Name);
            var player = _playerManager.Get(new Guid(user.Id));

            ViewData["Player"] = player.Username;

            quest  = ServicesAutoMapperConfig.Mapped.Map <Quest>(_questManager.Get(quest.QuestId));
            reward = ServicesAutoMapperConfig.Mapped.Map <Reward>(_rewardManager.Get(reward.RewardId));

            foreach (var items in itemRewards)
            {
                Inventory inventory = new Inventory
                {
                    ItemId   = items.ItemId,
                    PlayerId = new Guid(player.UserId),
                    Quantity = items.ItemQuantity
                };
                _inventoryManager.Create(ServicesAutoMapperConfig.Mapped.Map <Dto.Inventory>(inventory));
            }

            var playerUpdated = _playerManager.ExperienceGain(new Guid(player.UserId), reward.Experience, reward.Gold);

            _playerManager.Update(playerUpdated);

            _questManager.Delete(ServicesAutoMapperConfig.Mapped.Map <Dto.Quest>(quest));

            return(RedirectToAction("Index", "Home"));
        }