public async Task <ActionResult> EditCode(CodeItem codeItem, string returnurl)
        {
            if (ModelState.IsValid)
            {
                if (codeItem.Id == 0)
                {
                    CodeRunResultViewModel viewModel = new CodeRunResultViewModel();
                    var codetext     = codeItem.CodeText.Replace("\r", "").Replace("\n", "");
                    var codecompiler = await _codeProcessor.GetCodeCompilerFromText(codetext);

                    codecompiler.CompileCode();

                    if (!codecompiler.IsCodeCompiled)
                    {
                        viewModel.IsSucceeded = false;
                        viewModel.ErrorsText  = codecompiler.CompilationErrors;
                        return(View("CodeRunResult", viewModel));
                    }

                    var result = await _codeProcessor.SaveCompiledCode(codecompiler);
                }
                else
                {
                    await _repository.SaveCodeItemAsync(codeItem);
                }


                return(returnurl != null?Redirect(returnurl) : Redirect(Url.Action("Index", "CodeItem")));
            }

            return(View(codeItem));
        }
        public async Task <CodeItem> SaveCompiledCode(IAcidCodeCompiler codeCompiler)
        {
            codeCompiler = codeCompiler ?? throw new ArgumentNullException(nameof(codeCompiler));

            if (!codeCompiler.IsCodeCompiled)
            {
                throw new ApplicationException("Compile code before saving");
            }

            CodeItem codeItem = new CodeItem();

            codeItem.CodeText   = codeCompiler.CodeText;
            codeItem.EntryPoint = codeCompiler.EntryPoint;

            await _codeRepository.SaveCodeItemAsync(codeItem);

            return(codeItem);
        }