// GET: Competitions/Create
        public IActionResult Create()
        {
            var vm = new CategoriesViewModelIEnumerable();

            //vm.PopulateCategoriesList();
            foreach (var categoryDefault in _context.CategoryDefault)
            {
                vm.CategoriesList.Add(new SelectListItem {
                    Value = categoryDefault.CategoryName, Text = categoryDefault.CategoryName
                });
            }
            return(View(vm));
        }
        //public async Task<IActionResult> Create([Bind("ID,CompetitionName,Status,BucketName")] Competition competition, [Bind("CategoryName")] CompetitionCategory competitionCategory, string[] SelectedCategories)
        public async Task <IActionResult> Create(CategoriesViewModelIEnumerable model)
        //public async Task<IActionResult> Create(string[] CategoriesList)
        {
            /*foreach (var CategoryName in model.SelectedCategories)
             * {
             *  Console.WriteLine(CategoryName);
             * }*/
            //Console.WriteLine(model.competition.BucketName);
            //Tested and working^
            //Console.WriteLine(model.SelectedCategories.ElementAt(0));
            //Console.WriteLine(competitionCategory.Categories.ElementAt(0).CategoryName);
            if (model.SelectedCategories == null)
            {
                return(RedirectToAction("Create"));
            }

            model.Competition.Status = "Upcoming";
            if (ModelState.IsValid)
            {
                //Generate bucketname programtically
                model.Competition.BucketName            = GenerateBucketName(model.Competition.CompetitionName);
                model.Competition.CompetitionCategories = new Collection <CompetitionCategory>();
                foreach (var CategoryName in model.SelectedCategories)
                {
                    //model.competitionCategory = _context.CompetitionCategories.Find("CompetitionID");
                    //model.competitionCategory.CompetitionID = model.competition.ID;
                    //model.competitionCategory.CategoryName = CategoryName;

                    //competitionCategory.CategoryName = CategoryName;
                    //competitionCategory.CompetitionID = model.competition.ID;

                    //CompetitionCategoriesTempList.Add

                    model.Competition.CompetitionCategories.Add(new CompetitionCategory {
                        CompetitionID = model.Competition.ID, CategoryName = CategoryName
                    });

                    //competitionCategory.competitionID = _context.Competitions.Find("ID");\
                    //model.competition = new Competition();
                    //model.competition.CompetitionCategories.Add(new CompetitionCategory { CompetitionID = model.competition.ID, CategoryName = CategoryName });
                    //await _context.SaveChangesAsync();
                }
                _context.Add(model.Competition);
                await _context.SaveChangesAsync();

                try
                {
                    PutBucketResponse response = await S3Client.PutBucketAsync(model.Competition.BucketName);

                    if (response.HttpStatusCode == HttpStatusCode.OK)
                    {
                        //return RedirectToAction("");
                    }
                    else
                    {
                        //return RedirectToAction("");
                        //return RedirectToAction(nameof(Index));
                    }
                }
                catch (AmazonS3Exception e)
                {
                    ViewData["Exception"] = e.Message;
                    //return View();
                }
                //return RedirectToAction(nameof(Index));
            }
            else
            {
            }
            //return View(competition);
            //return View(model);
            //Testing create folder dynamically
            foreach (var CategoryName in model.SelectedCategories)
            {
                CreateFolder(model.Competition.BucketName, CategoryName);
            }
            //Testing create folder dynamically
            return(RedirectToAction("Index"));
        }