예제 #1
0
        public ActionResult Index(UserQueryViewModel model)
        {
            var dbContext = new OctopusDbContext();
            var script = PreparedScriptHelper.Get(model.PreparedScriptId);

            ModelState.Remove("Sql");
            if (script != null)
            {
                model.Sql = script.Sql;
                model.Params = PreparedScriptHelper.PrepareParams(script.Sql);
            }
            else
                model.Sql = string.Empty;

            return View(model);
        }
예제 #2
0
        public ActionResult Execute(UserQueryViewModel userQuery)
        {
            SqlQuery query = new SqlQuery();
            var preparedScript = PreparedScriptHelper.Get(userQuery.PreparedScriptId);
            if (preparedScript != null)
                query.PreparedScriptName = preparedScript.Name;
            query.Databases = userQuery.Databases;
            query.Sql = PreparedScriptHelper.SetParams(userQuery.Sql, userQuery.Params);

            query.UserId = UserHelper.GetUserId(User.Identity);
            query.DateStart = DateTime.Now;
            query.SingleTable = userQuery.SingleTable;
            _dbContext.Queries.Add(query);
            _dbContext.SaveChanges();

            Worker.ExecuteQuery(query);

            return Redirect(string.Format("~/Query/Execute/{0}", query.Id));
        }