Example #1
0
        public ActionResult Delete(int id)
        {
            AppUser      user    = _userManager.FindById(User.Identity.GetUserId());
            DataBaseInfo foundDb = DataBasesManager.GetDbInfos(user.Id).Single(db => db.Id == id);

            return(PartialView(foundDb));
        }
Example #2
0
        public ActionResult ShowConnectionString(int id)
        {
            //Find user
            AppUser user = _userManager.FindById(User.Identity.GetUserId());
            //Find DB
            DataBaseInfo foundDb = DataBasesManager.GetDbInfos(user.Id).Single(db => db.Id == id);

            return(PartialView("WatchConnectionString", foundDb.ConnectionString));
        }
Example #3
0
        public ActionResult GoToEditingProtected()
        {
            var id =
                DataBasesManager.GetDbInfos(User.Identity.GetUserId())
                .OrderByDescending(db => db.DateOfCreating)
                .First()
                .Id;

            return(RedirectToAction("Index", "DisplayTable", new { dbId = id }));
        }
Example #4
0
        public ActionResult ShowConnectionString()
        {
            string cs =
                DataBasesManager.GetDbInfos(User.Identity.GetUserId())
                .OrderByDescending(db => db.DateOfCreating)
                .First()
                .ConnectionString;

            return(PartialView("ShowConnectionString", cs));
        }
Example #5
0
        /// <summary>
        /// Removes Database after confiramtion
        /// </summary>
        /// <returns></returns>
        public ActionResult DeleteConfirmed(int id)
        {
            //Find user
            AppUser user = _userManager.FindById(User.Identity.GetUserId());
            //Find DB
            DataBaseInfo foundDb = DataBasesManager.GetDbInfos(user.Id).Single(db => db.Id == id);

            //Remove db info from DbInfos
            DataBasesManager.RemoveDbInfo(foundDb);
            //Delete database
            DataService.DropDataBase(foundDb.DbmsType, foundDb.Name);

            return(RedirectToAction("Index"));
        }
Example #6
0
        public ActionResult QueryExecutor(QueryExecutorVm vm)
        {
            //Find user
            AppUser      user    = _userManager.FindById(User.Identity.GetUserId());
            DataBaseInfo foundDb = DataBasesManager.GetDbInfos(user.Id).Single(m => m.Id == vm.DbId);

            //TODO: Think, if i need different executors for each DBMS or not

            using (IQueryExecutor executor = new SqlServerExecutor(foundDb.ConnectionString))
            {
                vm.DataTable = executor.ExecuteQueryAsDataTable(vm.Query);
            }
            return(PartialView("QueryResults", vm.DataTable));
        }
Example #7
0
        public ActionResult ExecuteQuery(int id)
        {
            //Find user
            AppUser user = _userManager.FindById(User.Identity.GetUserId());
            //Find DB
            DataBaseInfo foundDb = DataBasesManager.GetDbInfos(user.Id).Single(db => db.Id == id);

            QueryExecutorVm vm = new QueryExecutorVm
            {
                DbId   = id,
                DbName = foundDb.Name
            };

            return(PartialView("~/Views/Query/QueryExecutor.cshtml", vm));
        }
Example #8
0
        public void Configuration(IAppBuilder app)
        {
            DataService.ExecuteQuery("USE MASTER CREATE DATABASE HANGFIRE",
                                     ConfigurationManager.ConnectionStrings["SqlServerMaster"].ConnectionString, DbmsType.SqlServer);

            GlobalConfiguration.Configuration.UseSqlServerStorage("Hangfire");

            app.UseHangfireDashboard();
            app.UseHangfireServer();

            RecurringJob.AddOrUpdate(() => DataBasesManager.DropOutdatedDbs(), Cron.Hourly);//TODO: Hourly

            // настраиваем контекст и менеджер
            app.CreatePerOwinContext <AppIdentityContext>(AppIdentityContext.Create);
            app.CreatePerOwinContext <AppUserManager>(AppUserManager.Create);
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login")
            });
        }
Example #9
0
        public ActionResult CreateProtectedDb(ProtectedDbVm vm)
        {
            vm.AvailableServers = GetAvailableDbmsAsListString();

            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            //Receives info
            AppUser user       = _userManager.FindById(User.Identity.GetUserId());
            var     tempDbInfo = vm.ToCreateDatabaseObject(user);

            //Check Db Exists
            DbmsType selectedDbmsType = (DbmsType)Enum.Parse(typeof(DbmsType), vm.SelectedServer);

            if (DataService.CheckDataBaseExists(selectedDbmsType, tempDbInfo.Name))
            {
                string errorMessage = "База данных с таким именем уже существует в этой СУБД.";
                ModelState.AddModelError("err", errorMessage);
                return(View(vm));
            }

            //Try to create database
            try
            {
                tempDbInfo.ConnectionString = DataService.CreateDatabase(tempDbInfo, GetSqlServerAddress(), user.UserNickName, vm.DataBasePassword);
            }
            catch (Exception e)
            {
                return(View("CustomError", (object)e.ToString()));
            }
            //Save action to database
            //AddRecord new info to user. No ID and foreighn Key (!)
            DataBasesManager.AddDbInfo(tempDbInfo);
            _userManager.Update(user);

            return(View("RequestConnectionString"));
        }
Example #10
0
        public ActionResult CreateAnonymousDb(AnonymousDbVm vm)
        {
            vm.AvailableServers = GetAvailableDbmsAsListString();

            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            var tempObj = vm.ToCreateDatabaseObject();
            //Check Db Exists
            DbmsType selectedDbmsType = (DbmsType)Enum.Parse(typeof(DbmsType), vm.SelectedServer);

            if (DataService.CheckDataBaseExists(selectedDbmsType, tempObj.Name))
            {
                string errorMessage = "База данных с таким именем уже существует в этой СУБД.";
                ModelState.AddModelError("err", errorMessage);
                return(View(vm));
            }

            //Try to create database
            String connectionString;

            try
            {
                connectionString = DataService.CreateDatabase(tempObj, GetSqlServerAddress());
            }
            catch (Exception e)
            {
                return(View("CustomError", (object)e.ToString()));
            }
            tempObj.ConnectionString = connectionString;
            DataBasesManager.AddAnonymousDbInfo(tempObj);

            ViewBag.IsAnon = true;
            return(View("RequestConnectionString", (object)connectionString));
        }
Example #11
0
        public ActionResult Index()
        {
            AppUser user = _userManager.FindById(User.Identity.GetUserId());

            return(View(DataBasesManager.GetDbInfos(user.Id)));
        }
Example #12
0
 public AppIdentityContext() : base("IdentityDb")
 {
     Database.CreateIfNotExists();
     //Create table DbInfos
     DataBasesManager.CreateTablesIfNotExists();
 }