public ConsoleOutput Save(ConsoleInput input) { _logRepository.Insert(new Log { InputCode = input.Code, IpAddress = GetClientIp(Request) }); string id = null; if (!string.IsNullOrEmpty(input.Id)) { var fiddle = _fiddleRepository.Get(input.Id); if (fiddle != null) { id = fiddle.Id; } } var co = Run(input); _fiddleRepository.Insert(new Fiddle { InputCode = input.Code, Id = id, Result = co.Output, Language = input.Language }); return(co); }
public ActionResult Save(CodeViewModel vm) { _logRepository.Insert(new Log { InputCode = vm.InputCode, IpAddress = Request.UserHostAddress }); string id = null; if (!string.IsNullOrEmpty(vm.Id)) { var fiddle = _fiddleRepository.Get(vm.Id); if (fiddle != null) { id = fiddle.Id; } } if (id == null) { const string hashOptions = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var random = new Random(); id = new string( Enumerable.Repeat(hashOptions, 8) .Select(s => s[random.Next(s.Length)]) .ToArray()); } var result = CompileHelper.CompileAndRun(vm.InputCode); _fiddleRepository.Insert(new Fiddle { InputCode = vm.InputCode, Id = id, Result = result }); return(new JsonResult { Data = new { id, result } }); }