//
        // POST: /SaisiNote/NoterAppartement

        public ActionResult NoterAppartement(string address, string country, string zip, string provincia, string citta, string appart, string lng, string lat, string nota)
        {
            //SaisiNoteForm form = new SaisiNoteForm();

            var data = new
            {
                indirizzo = address,
                Pays = country,
                zip = zip,
                province = provincia,
                ville = citta,
                appartement = appart,
                longitude = lng,
                latitude = lat,
                note = nota
            };
            string resultMessage = "";
            var result = new { returnValue = "" };
            try
            {
                var valLng = Double.Parse(lng, CultureInfo.InvariantCulture);
                var valLat = Double.Parse(lat, CultureInfo.InvariantCulture);

                var addressToSave = new AdresseTable();
                addressToSave.RueNo = int.Parse(GetRueAndNumero(address)[0]);
                addressToSave.Rue = GetRueAndNumero(address)[1];
                addressToSave.AptNo = appart;
                addressToSave.CodePostal = zip;
                addressToSave.Ville = citta;
                addressToSave.Pays = country;
                addressToSave.Province = provincia;
                addressToSave.GeoCodeResponse = address;
                addressToSave.Lattitude = (decimal)valLat;
                addressToSave.Longitude = (decimal)valLng;

                var saisiNoteWriter = new SaisiNoteWriter(new MailSender(), new SaisiNoteContext());
                saisiNoteWriter.SaveAddresNoteSaisi(addressToSave);
                var id = saisiNoteWriter.GetAddressId(addressToSave);
                var noteToSave = new NoteTable();
                noteToSave.Note = int.Parse(nota);
                noteToSave.AdresseId = id;

                UserTable userVariable = (UserTable)HttpContext.Session["UserSessionObject"];

                noteToSave.UserId = userVariable.UserId;
                noteToSave.StatutNote = 0;
                saisiNoteWriter.SaveNoteSaisi(noteToSave, out resultMessage);
                result = new { returnValue = resultMessage };
            }
            catch (Exception ex)
            {
                result = new { returnValue = " Error" };
            }

            return Json(result);
            //return RedirectToAction("SearchNoted", "AdresseTable", "searchPhrase=7060 Rue Hutchison, Montréal, QC H3N 1Y6, Canada");
        }
        public ActionResult Index(SaisiNoteForm form)
        {
            if (ModelState.IsValid)
            {
                var address = ConcatenationAddress(form);
                try
                {
                    var geocoder = new Geocoder();
                    var response = geocoder.Locate(address);
                    if (response != null)
                    {
                        var longititude = response.Longitude;
                        var lat = response.Latitude;
                        var formatted_address = response.Formatted_address;
                        var addressToSave = new AdresseTable();
                        addressToSave.AptNo = form.Appartement;
                        addressToSave.CodePostal = form.CodePostal;
                        addressToSave.Ville = form.Localite;
                        addressToSave.Pays = form.Pays;
                        addressToSave.Province = form.Region;
                        addressToSave.GeoCodeResponse = formatted_address;
                        addressToSave.Lattitude = (decimal)lat;
                        addressToSave.Longitude = (decimal)longititude;

                        var saisiNoteWriter = new SaisiNoteWriter(new MailSender(), new SaisiNoteContext());
                        saisiNoteWriter.SaveAddresNoteSaisi(addressToSave);
                        var id = saisiNoteWriter.GetAddressId(addressToSave);
                        var noteToSave = new NoteTable();
                        noteToSave.Note = form.Note;
                        noteToSave.AdresseId = id;
                        noteToSave.UserId = 1;
                        noteToSave.StatutNote = 0;
                        //saisiNoteWriter.SaveNoteSaisi(noteToSave);
                        ViewBag.Message = "Enregistrement reussie!";
                        ViewBag.NumTimes = 1;
                        ViewData["color"] = "green";
                    }
                    else
                    {
                        ViewBag.Message = "vous devez inserez une adresse valide!";
                        ViewBag.NumTimes = 1;
                        ViewData["color"] = "red";
                    }

                }
                catch (Exception ex)
                {
                    ViewBag.Message = "La note n'a pas été enregistrée. Réessayer plus tard!";
                    ViewBag.NumTimes = 1;
                    ViewData["color"] = "red";
                }
            }
            return View(form);
        }
 public SaisiNoteController()
 {
     _SaisiNoteWriter = new SaisiNoteWriter(new MailSender(), new SaisiNoteContext());
 }