Exemple #1
0
        public async Task <AvatarBundle> AddBundleAsync(AvatarBundle bundle,
                                                        List <int> itemIds)
        {
            VerifyManagementPermission();
            var items = await _avatarItemRepository.GetByIdsAsync(itemIds);

            if (items.Where(_ => _.Unlockable != bundle.CanBeUnlocked).Any())
            {
                throw new GraException($"Not all items are {(bundle.CanBeUnlocked ? "Unlockable" : "Available")}.");
            }

            if (bundle.CanBeUnlocked == false &&
                items.GroupBy(_ => _.AvatarLayerId).Where(_ => _.Skip(1).Any()).Any())
            {
                throw new GraException($"Default bundles cannot have multiple items per layer.");
            }

            bundle.SiteId = GetCurrentSiteId();
            var newBundle = await _avatarBundleRepository.AddSaveAsync(
                GetClaimId(ClaimType.UserId), bundle);

            await _avatarBundleRepository.AddItemsAsync(newBundle.Id, itemIds);

            return(newBundle);
        }
Exemple #2
0
        public async Task <IActionResult> BundleEdit(int id)
        {
            AvatarBundle bundle = null;

            try
            {
                bundle = await _avatarService.GetBundleByIdAsync(id);
            }
            catch (GraException gex)
            {
                ShowAlertWarning("Unable to view bundle: ", gex);
                return(RedirectToAction("Bundles"));
            }
            foreach (var item in bundle.AvatarItems)
            {
                item.Thumbnail = _pathResolver.ResolveContentPath(item.Thumbnail);
            }

            var viewModel = new BundlesDetailViewModel()
            {
                Bundle    = bundle,
                Action    = "Edit",
                ItemsList = string.Join(",", bundle.AvatarItems.Select(_ => _.Id)),
                Layers    = new SelectList(await _avatarService.GetLayersAsync(), "Id", "Name")
            };

            if (bundle.CanBeUnlocked)
            {
                viewModel.TriggersAwardingBundle = await _avatarService
                                                   .GetTriggersAwardingBundleAsync(id);
            }

            PageTitle = "Edit Bundle";
            return(View("BundleDetail", viewModel));
        }
Exemple #3
0
        public async Task <AvatarBundle> EditBundleAsync(AvatarBundle bundle,
                                                         List <int> itemIds)
        {
            VerifyManagementPermission();

            var currentBundle = await _avatarBundleRepository.GetByIdAsync(bundle.Id, false);

            if (currentBundle.HasBeenAwarded)
            {
                throw new GraException($"This bundle has been awarded to a participant and can no longer be edited. ");
            }

            var items = await _avatarItemRepository.GetByIdsAsync(itemIds);

            if (items.Where(_ => _.Unlockable != currentBundle.CanBeUnlocked).Any())
            {
                throw new GraException($"Not all items are {(bundle.CanBeUnlocked ? "Unlockable" : "Available")}.");
            }

            if (currentBundle.CanBeUnlocked == false &&
                items.GroupBy(_ => _.AvatarLayerId).Where(_ => _.Skip(1).Any()).Any())
            {
                throw new GraException($"Default bundles cannot have multiple items per layer.");
            }

            currentBundle.Name = bundle.Name;
            await _avatarBundleRepository.UpdateSaveAsync(GetClaimId(ClaimType.UserId),
                                                          currentBundle);

            var currentItemIds = currentBundle.AvatarItems.Select(_ => _.Id).ToList();
            var itemsToRemove  = currentItemIds.Except(itemIds).ToList();
            var itemsToAdd     = itemIds.Except(currentItemIds).ToList();

            await _avatarBundleRepository.RemoveItemsAsync(currentBundle.Id, itemsToRemove);

            await _avatarBundleRepository.AddItemsAsync(currentBundle.Id, itemsToAdd);

            return(currentBundle);
        }