Example #1
0
        public async Task <IActionResult> Create(CreateViewModel model)
        {
            var serverValidation = new ServerValidation(_quizRepository);

            if (ModelState.IsValid)
            {
                var quiz = new Quiz
                {
                    Title     = model.Title,
                    Questions = model.Questions
                };

                // A second validation on top of the client-side validation
                // It makes sure the inputs the client-side validation covers are correct
                // and performs other validation that is not executed in the client-side
                var isModelValidInServer = serverValidation.IsModelValidInServer(quiz, ModelState);

                if (isModelValidInServer)
                {
                    _quizRepository.Save(quiz);

                    await _context.SaveChangesAsync();

                    // Passing which page the user comes from
                    // It is to difference the message coming from the Edit page
                    TempData["create"] = "Create";

                    return(RedirectToAction("Details", new { id = quiz.QuizId }));
                }

                return(View(model));
            }

            return(View(model));
        }
Example #2
0
        protected static DocumentStore CreateStore(RavenConnectionStringOptions connectionStringOptions)
        {
            var credentials = connectionStringOptions.Credentials as NetworkCredential;

            if (credentials != null && //precaution
                (String.IsNullOrWhiteSpace(credentials.UserName) ||
                 String.IsNullOrWhiteSpace(credentials.Password)))
            {
                credentials = CredentialCache.DefaultNetworkCredentials;
            }

            var s = new DocumentStore
            {
                Url         = connectionStringOptions.Url,
                ApiKey      = connectionStringOptions.ApiKey,
                Credentials = credentials ?? CredentialCache.DefaultNetworkCredentials
            };

            s.Initialize();

            ServerValidation.ValidateThatServerIsUpAndDatabaseExists(connectionStringOptions, s);

            s.DefaultDatabase = connectionStringOptions.DefaultDatabase;

            return(s);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.outputString = "success";
        WebFormData wf = new WebFormData();

        wf.SessionID = protectHtmlXmlCodes(Request.Form["sessionID"]);
        wf.Captcha   = protectHtmlXmlCodes(Request.Form["captcha"]);
        wf.Data      = Server.UrlDecode(protectHtmlXmlCodes(Request.Form["formContent"]));
        wf.Mode      = protectHtmlXmlCodes(Request.Form["mode"]);
        var serializer = new JavaScriptSerializer();
        //serializer.RegisterConverters (new [] { new DynamicJsonConverter () });
        //Serialize Form Data
        dynamic obj     = serializer.Deserialize(wf.Data, typeof(object));
        dynamic mapping = new Object();
        dynamic data    = new Object();

        //Read Mapping Data
        try {
            mapping = serializer.Deserialize(FileContent(mappingPath), typeof(object));
            data    = serializer.Deserialize(FileContent(dataPath), typeof(object));
        } catch (FileNotFoundException exception) {
            this.outputString = "File do not exist!";
            return;
        }
        this.outputString = mapping["cloumns"][0]["name"];
        ServerValidation valid = new ServerValidation(obj, data);

        if (valid.ValidateForm())
        {
            this.outputString = "success";
        }
        //this.outputString = obj["3"];
    }
Example #4
0
        public async Task InitializeAsync(FileSystemSmugglerOptions options, CancellationToken cancellationToken)
        {
            filesStore = FileStoreHelper.CreateStore(connectionOptions);

            await ServerValidation.ValidateThatServerIsUpAndFileSystemExists(connectionOptions, filesStore).ConfigureAwait(false);

            await ServerValidation.DetectServerSupportedFeatures(connectionOptions).ConfigureAwait(false); // TODO arek - merge those 2 methods into single one
        }
        public ActionResult ServerSideValidation321(ServerValidation sv)
        {
            Debug.WriteLine("Came to post validation" + Request["username"]);
            Dictionary <string, string> errDict = new Dictionary <string, string>();

            if (Request["username"] == "")
            {
                Debug.WriteLine("Came to verify username server side validation");
                errDict.Add("username", "Username cannot be null"); // here the TryGetValue  tries to get the value
            }
            ViewBag.errDict = errDict;
            return(View("../Filter/ServerSideValidation"));
        }
Example #6
0
        public async Task InitializeAsync(DatabaseSmugglerOptions options, CancellationToken cancellationToken)
        {
            _typeIndex = 0;
            _options   = options;
            _store     = _storeFactory();

            if (_ownsStore)
            {
                _store.Initialize(ensureDatabaseExists: false);
            }

            await ServerValidation.ValidateThatServerIsUpAndDatabaseExistsAsync(_store, cancellationToken).ConfigureAwait(false);

            await InitializeBatchSizeAsync(_store, _options).ConfigureAwait(false);
        }
Example #7
0
        public async Task <IActionResult> Edit(int id, Quiz quiz)
        {
            var serverValidation = new ServerValidation(_quizRepository);

            if (id != quiz.QuizId)
            {
                return(NotFound());
            }

            if (!_quizRepository.QuizExists(quiz.QuizId))
            {
                return(NotFound($"The Quiz with id - {quiz.QuizId} does not exist in the system."));
            }

            if (ModelState.IsValid)
            {
                var isModelValidInServer = serverValidation.IsModelValidInServer(quiz, ModelState);

                if (isModelValidInServer)
                {
                    foreach (var question in quiz.Questions)
                    {
                        foreach (var answer in question.Answers)
                        {
                            _context.Entry(answer).State = EntityState.Modified;
                            _answerRepository.Edit(answer);
                        }

                        _context.Entry(question).State = EntityState.Modified;
                        _questionRepository.Edit(question);
                    }

                    _context.Entry(quiz).State = EntityState.Modified;

                    _quizRepository.Edit(quiz);

                    await _context.SaveChangesAsync();

                    TempData["edit"] = "Edit";

                    return(RedirectToAction("Details", new { id = quiz.QuizId }));
                }

                return(View(quiz));
            }

            return(View(quiz));
        }
        public async Task InitializeAsync(DatabaseSmugglerOptions options, DatabaseSmugglerNotifications notifications, CancellationToken cancellationToken)
        {
            _globalOptions = options;
            _notifications = notifications;
            _store         = _storeFactory();

            if (_ownsStore)
            {
                _store.Initialize(ensureDatabaseExists: false);
            }

            _store.JsonRequestFactory.DisableRequestCompression = _options.DisableCompression;

            await ServerValidation.ValidateThatServerIsUpAndDatabaseExistsAsync(_store, cancellationToken).ConfigureAwait(false);

            await InitializeBatchSizeAsync(_store, _globalOptions).ConfigureAwait(false);
        }