Exemplo n.º 1
0
        public async Task <IActionResult> BundleEdit(int id)
        {
            var bundle = new Domain.Model.AvatarBundle();

            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));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> BundleCreate()
        {
            var viewModel = new BundlesDetailViewModel()
            {
                Action = "Create",
                Layers = new SelectList(await _avatarService.GetLayersAsync(), "Id", "Name")
            };

            PageTitle = "Create Bundle";
            return(View("BundleDetail", viewModel));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> BundleEdit(BundlesDetailViewModel model)
        {
            var itemList = new List <int>();

            if (!string.IsNullOrWhiteSpace(model.ItemsList))
            {
                itemList = model.ItemsList
                           .Split(',')
                           .Where(_ => !string.IsNullOrWhiteSpace(_))
                           .Select(int.Parse)
                           .ToList();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var bundle = await _avatarService.EditBundleAsync(model.Bundle, itemList);

                    ShowAlertSuccess($"Bundle '<strong>{bundle.Name}</strong>' successfully edited!");
                    return(RedirectToAction("Bundles"));
                }
                catch (GraException gex)
                {
                    ShowAlertDanger("Unable to edit bundle: ", gex);
                }
            }

            if (itemList.Count > 0)
            {
                model.Bundle.AvatarItems = await _avatarService.GetItemsByIdsAsync(itemList);

                foreach (var item in model.Bundle.AvatarItems)
                {
                    item.Thumbnail = _pathResolver.ResolveContentPath(item.Thumbnail);
                }
            }
            model.Layers = new SelectList(await _avatarService.GetLayersAsync(), "Id", "Name");
            PageTitle    = "Edit Bundle";
            return(View("BundleDetail", model));
        }