Example #1
0
        public ActionResult CreateProtectedDb()
        {
            ProtectedDbVm vm = new ProtectedDbVm
            {
                AvailableServers = GetAvailableDbmsAsListString()
            };

            return(View(vm));
        }
Example #2
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"));
        }