public async Task <IActionResult> Edit(int id, [Bind("Id,Code,ProgrammingLanguageId,ChallengeId")] CodeTemplateModel codeTemplateModel)
        {
            if (id != codeTemplateModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(codeTemplateModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CodeTemplateModelExists(codeTemplateModel.Id))
                    {
                        return(NotFound());
                    }
                    throw;
                }
                var contestId = _context.CodeTemplates.Include(s => s.Challenge).FirstOrDefault(s => s.Id == codeTemplateModel.Id).Challenge.ContestId;
                return(RedirectToAction(nameof(Index), new { codeTemplateModel.ChallengeId, contestId }));
            }
            ViewData["ChallengeId"]           = new SelectList(_context.Challenges, "Id", "Name", codeTemplateModel.ChallengeId);
            ViewData["ProgrammingLanguageId"] = new SelectList(_context.ProgrammingLanguages, "Id", "Name", codeTemplateModel.ProgrammingLanguageId);
            return(View(codeTemplateModel));
        }
        public async Task <IActionResult> Create([Bind("Code,ProgrammingLanguageId,ChallengeId")] CodeTemplateModel codeTemplateModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(codeTemplateModel);
                await _context.SaveChangesAsync();

                var contestId = _context.CodeTemplates.Include(s => s.Challenge).FirstOrDefault(s => s.Id == codeTemplateModel.Id).Challenge.ContestId;
                return(RedirectToAction(nameof(Index), new { codeTemplateModel.ChallengeId, contestId }));
            }
            ViewData["ChallengeId"]           = codeTemplateModel.ChallengeId;
            ViewData["ProgrammingLanguageId"] = new SelectList(_context.ProgrammingLanguages, "Id", "Name", codeTemplateModel.ProgrammingLanguageId);
            return(View(codeTemplateModel));
        }