public ActionResult Edit(AdresseTable adressetable)
 {
     if (ModelState.IsValid)
     {
         db.Entry(adressetable).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(adressetable);
 }
        public ActionResult Create(AdresseTable adressetable)
        {
            if (ModelState.IsValid)
            {
                db.AdresseTables.Add(adressetable);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(adressetable);
        }
 public virtual void SaveAddress(AdresseTable address)
 {
     using (var ctx = new notetalocEntities())
     {
         var add = ctx.AdresseTables.Where(a => a.GeoCodeResponse == address.GeoCodeResponse).FirstOrDefault();
         if (add == null)
         {
             address.AdresseId = GetAddresseId(DateTime.Now);
             ctx.AdresseTables.Add(address);
             ctx.SaveChanges();
         }
     }
 }
        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);
        }
        //
        // 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 virtual int GetAddressId(AdresseTable address)
 {
     using (var ctx = new notetalocEntities())
     {
         return ctx.AdresseTables.SingleOrDefault(a => a.GeoCodeResponse == address.GeoCodeResponse).AdresseId;
     }
 }
 public void SaveAddresNoteSaisi(AdresseTable address)
 {
     _SaisiNoteContext.SaveAddress(address);
 }