//version foreach /*List<PaysEntity> ListePaysFromDB = _paysRepo.Get(); * List<PaysModel> ListePaysForCtrl = new List<PaysModel>(); * * foreach (PaysEntity pe in ListePaysFromDB) * { * PaysModel pm = new PaysModel(); * pm.IdPays = pe.IdPays; * pm.NomPays = pe.Libelle; * ListePaysForCtrl.Add(pm); * } * return ListePaysForCtrl;*/ // ajouter un bien public bool AddBien(AjoutBienModel abm) { MembreModel owner = (MembreModel)HttpContext.Current.Session["ConnectedUser"]; AjoutBienEntity abe = new AjoutBienEntity(); //mapping partie Bien abe.Titre = abm.Titre; abe.DescCourte = abm.DescCourte; abe.DescLong = abm.DescLong; abe.Numero = abm.Numero; abe.Rue = abm.Rue; abe.CodePostal = abm.CodePostal; abe.Ville = abm.Ville; abe.Pays = abm.Pays; abe.NombrePerson = abm.NombrePerson; abe.NbrSBD = abm.NbrSBD; abe.NbrWC = abm.NbrWC; abe.IdMembre = owner.IdMembre; if (abm.Latitude is null) { abe.Latitude = "000000000"; } else { abe.Latitude = abm.Latitude; } if (abm.Longitude is null) { abe.Longitude = "000000000"; } else { abe.Longitude = abm.Longitude; } if (abm.Photo is null) { abe.Photo = "pas de photo disponible"; } else { abe.Photo = abm.Photo; } //je traiterai les options plus tard /*//mapping partie OptionBien * abe.ListeOption = new List<OptionEntity>(); * foreach (OptionModel item in abm.ListeIdOption) * { * OptionEntity option = new OptionEntity(); * option.IdOption = item.IdOption; * option.Libelle = item.Libelle; * abe.ListeOption.Add(option); * }*/ return(_ajoutBienRepo.Insert(abe)); }
public ActionResult AjouterBien(FormCollection form, AjouterBienViewModel abvm) { AjoutBienModel abm = new AjoutBienModel(); abm.Titre = form["NewBien.Titre"].ToString(); abm.DescCourte = form["NewBien.DescCourte"].ToString(); abm.DescLong = form["NewBien.DescLong"].ToString(); abm.Pays = int.Parse(form["Pays"].ToString()); abm.Ville = form["NewBien.Ville"].ToString(); abm.Rue = form["NewBien.Rue"].ToString(); abm.Numero = form["NewBien.Numero"].ToString(); abm.CodePostal = form["NewBien.CodePostal"].ToString(); abm.Photo = form["NewBien.Photo"].ToString(); abm.NombrePerson = int.Parse(form["NewBien.NombrePerson"].ToString()); abm.NbrSBD = int.Parse(form["NewBien.NbrSBD"].ToString()); abm.NbrWC = int.Parse(form["NewBien.NbrWC"].ToString()); string assuranceObligatoire = form["NewBien.AssuranceObligatoire"]; if (assuranceObligatoire == "true,false") { abm.AssuranceObligatoire = true; } else { abm.AssuranceObligatoire = false; } abm.ListeIdOption = new List <OptionModel>(); foreach (OptionModel item in abvm.ListeOption) { if (form.AllKeys.Contains(item.Libelle)) { OptionModel option = new OptionModel(); option.IdOption = item.IdOption; option.Libelle = item.Libelle; abm.ListeIdOption.Add(option); } } UnitOfWork uow = new UnitOfWork(ConfigurationManager.ConnectionStrings["Cnstr"].ConnectionString); if (uow.AddBien(abm)) { return(RedirectToAction("Index", "Home", new { area = "Membre" })); } else { return(RedirectToAction("AjouterBien", "Sharing", new { area = "Membre" })); } }