Ejemplo n.º 1
0
 public void CanValidateAutocompleteAddress()
 {
     // Create the instance of the ValidateServerHelper and compare the expected result with real
     ValidateServerHelper validateServer = new ValidateServerHelper();
     ValidationResult vr = validateServer.AddressValidation( "Кирова 59" );
     Assert.IsTrue(vr == ValidationResult.Success);
 }
Ejemplo n.º 2
0
        public ContentResult FeedbackForm(FeedbackViewModel fvm)
        {
            var vsh = new ValidateServerHelper();
            ValidationResult validationResult = vsh.FeedBackDataIsValid(fvm);

            if (validationResult == ValidationResult.Success)
            {
                var feedback = new Feedback
                {
                    Email = fvm.Email,
                    Name = fvm.Name ?? "Anonymous",
                    Text = fvm.Text,
                    Type = int.Parse(fvm.SelectedValue)
                };

                this.feedbackRepository.Add(feedback);
                this.feedbackRepository.Save();
                switch (feedback.Type)
                {
                    case 0:
                        this.RedirectToAction("Index", "MakeRoute");
                        return
                            this.Content(
                                "<div class=\"greetings\" oncreate style=\"text-align:center; padding:20px;\">Спасибо, ваше мнение очень важно для нас. <a class='close' data-dismiss='modal'>×</a></div>",
                            "text/html");

                    case 1:
                        return
                            this.Content(
                                "<div class=\"greetings\" oncreate style=\"text-align:center; padding:20px;\">Спасибо, ваше предложение будет расмотрено. <a class='close' data-dismiss='modal'>×</a></div>",
                            "text/html");
                    case 2:
                        return
                            this.Content(
                                "<div class=\"greetings\" oncreate style=\"text-align:center; padding:20px;\">Спасибо, ошибка будет вскоре исправлена.<a class='close' data-dismiss='modal'>×</a></div>",
                            "text/html");
                    case 3:
                        return
                            this.Content(
                                "<div class=\"greetings\" oncreate style=\"text-align:center; padding:20px;\">Спасибо за проявленый интерес к нашему сайту. Мы вскоре свяжемся с вами. <a class='close' data-dismiss='modal'>×</a></div>",
                            "text/html");
                    default:
                        return
                            this.Content(
                                "<div class=\"greetings\" oncreate style=\"text-align:center; padding:20px;\" >Спасибо за ваш отзыв, он для нас очень важен. <a class='close' data-dismiss='modal'>×</a></div> ",
                            "text/html");
                }
            }
            else
                return
                    this.Content(
                        "<div class=\"greetings\" oncreate style=\"text-align:center\">" + validationResult.ErrorMessage
                        + "</div>",
                        "text/html");
        }
Ejemplo n.º 3
0
        public void CanValidateDataToFeedmackForm()
        {
            FeedbackViewModel feedbackViewModel = new FeedbackViewModel();

            feedbackViewModel.Email = "*****@*****.**";
            feedbackViewModel.Name = "Вася Пупкин";
            feedbackViewModel.Text = "Какой то текст";
            feedbackViewModel.SelectedValue = "1";

            // Create the instance of the ValidateServerHelper and compare the expected result with real one
            ValidateServerHelper validateServer = new ValidateServerHelper();
            // Verify that the entered data is valid
            ValidationResult vr = validateServer.FeedBackDataIsValid(feedbackViewModel);
            Assert.IsTrue(vr == ValidationResult.Success);
        }
Ejemplo n.º 4
0
        public void CanValidateCityCoords()
        {
            // Pointer to MakeRouteViewModel
            MakeRouteViewModel makeRoute = new MakeRouteViewModel();

            makeRoute.EndPointLatitude = "35,0394344329834";
            makeRoute.EndPointLongitude = "48,46062862564409";
            makeRoute.StartPointLatitude = "35,03368377685547";
            makeRoute.StartPointLongitude = "48,45146411408362";

            // Create the instance of the ValidateServerHelper and compare the expected result with real
            ValidateServerHelper validateServer = new ValidateServerHelper();
            ValidationResult vr = validateServer.IsValidCoords(makeRoute);
            Assert.IsTrue( vr == ValidationResult.Success );
        }
        public JsonResult GetPredictions(string address)
        {
            var retVal = string.Empty;

            // Verify that address has no digits and not empty string
            ValidateServerHelper vsh = new ValidateServerHelper();
            if( vsh.AddressValidation(address) == ValidationResult.Success )
            {

                // used to build entire input
                var sb = new StringBuilder();
                var fromDatabase = this.autocomplete.GetAdressFromDatabase(address);

                // used on each read operation
                if (fromDatabase == null)
                {
                    var valueBeforeParsing = GoogleMapHelper.GetGoogleAnswerForAutocomplete(address);

                    var resp = JObject.Parse(valueBeforeParsing);
                    var status = (string)resp["status"];
                    if (status == "OK")
                    {
                        var descriptions = resp["predictions"];
                        var suggestions = descriptions.Select(item => ((string)item["description"]).Replace(",", string.Empty).Replace("\n", string.Empty)).ToList();

                        this.autocomplete.AddSuggestionsToDatabase(suggestions);
                    }

                    retVal = valueBeforeParsing;
                }
                else
                {
                    var jsonAnswer = JsonConvert.SerializeObject(fromDatabase);
                    return this.Json(fromDatabase, JsonRequestBehavior.AllowGet);
                }

                return this.Json(retVal, JsonRequestBehavior.AllowGet);
            }
            else
                return null;
        }
Ejemplo n.º 6
0
        public JsonResult Index(MakeRouteViewModel makeRouteViewModel, ValidateServerHelper validateCoords)
        {
            if (validateCoords.IsValidCoords(makeRouteViewModel) == ValidationResult.Success)
            {
                var startPoint = new MapPoint(
                    Convert.ToDouble(makeRouteViewModel.StartPointLatitude),
                    Convert.ToDouble(makeRouteViewModel.StartPointLongitude));
                var endPoint = new MapPoint(
                    Convert.ToDouble(makeRouteViewModel.EndPointLatitude),
                    Convert.ToDouble(makeRouteViewModel.EndPointLongitude));
                var args = new List<Transport> { Transport.All };
                var invalidDirections =
                    this.directionProvider.All().ToList().Select(direction => direction.Direction).ToList();
                var invalidWords =
                    this.invalidCharacterProvider.All().ToList().Select(invalidWord => invalidWord.InvalidWord).ToList();
                var validWords =
                    this.invalidCharacterProvider.All().ToList().Select(validWord => validWord.ValidWord).ToList();
                var allRoutes = this.routeSeach.GetAppropriateRoutes(
                    this.routeProvider.All(),
                    invalidDirections,
                    validWords,
                    invalidWords,
                    endPoint.ToSqlGeography(),
                    startPoint.ToSqlGeography(),
                    args);
                var routes = ModelConverter.Convert(allRoutes);

                return this.Json(routes);
            }
            else
            {
                return Json(makeRouteViewModel);
            }
        }