Exemplo n.º 1
0
        public async Task <IActionResult> UploadPresentation()
        {
            var categoriesResult = await _categoriesRepository.GetCurrentCategories();

            var vm = new UploadPresentationViewModel
            {
                ViewInput = new UploadPresentationViewModel.Input
                {
                    Categories = categoriesResult.Value
                }
            };

            return(View(vm));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UploadPresentation(UploadPresentationViewModel vm)
        {
            Action <UploadPresentationViewModel> populateVMWithCategories = async(UploadPresentationViewModel m) =>
            {
                m.ViewInput = new UploadPresentationViewModel.Input();
                var result = await _categoriesRepository.GetCurrentCategories();

                m.ViewInput.Categories = result.Value;
            };

            if (!ModelState.IsValid)
            {
                populateVMWithCategories(vm);
                return(View(vm));
            }

            var userId = _userManager.GetUserId(User);
            var tags   = vm.ViewOutput.TagsList != null?vm.ViewOutput.TagsList.Split(new char[] { ',', ' ' }) : new string[]
            {
            };
            var tagsList = new List <string>(tags);

            var uploadModel = new UploadPresentationModel
            {
                CategoryId   = vm.ViewOutput.CategoryId,
                Name         = vm.ViewOutput.Name,
                Description  = vm.ViewOutput.Description,
                Tags         = tagsList,
                IsPublic     = vm.ViewOutput.IsPublic,
                SourceStream = vm.ViewOutput.File.OpenReadStream()
            };

            var opResult = await _presentationsRepository.UploadPresentationForUser(userId, uploadModel);


            if (opResult.ErrorMessageIfAny != null)
            {
                populateVMWithCategories(vm);
                vm.ViewInput.ErrorMessageIfAny = opResult.ErrorMessageIfAny;
                return(View(vm));
            }

            return(new RedirectToActionResult("Index", "Home", new { }));
        }