1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
//Création Offre
Offre ofr = new Offre();
ofr.DateCreation = DateTime.Now;
ofr.NomContact = txtNom.Text;
//Nature de l'offre (depuis combo)
ofr.NatureReference.EntityKey = new EntityKey("ImmoContainer.Nature", "IdNat", Int32.Parse(cbNature.SelectedValue));
//Encore plein de champs...
// on pousse le luxe jusqu'à enregistrer des photos
if (Session["CurrentPhotos"] != null)
{
classeurPhoto cl = (classeurPhoto)Session["CurrentPhotos"];
foreach (var p in cl.liste())
{
ImmoAnnonce.Photo pEntity = new ImmoAnnonce.Photo();
string name;
FileInfo fi = new FileInfo(p.PhotoPath);
name = Server.MapPath("~/photos/") + fi.Name;
System.IO.File.Copy(p.PhotoPath , name);
pEntity.PhotoURL = name;
ofr.Photo.Add(pEntity);
}
}
//Enregistrement
try
{
ImmoContainer bdd = new ImmoContainer();
bdd.AddToOffre(ofr);
bdd.SaveChanges();
}
catch (Exception Ex)
{
lblErreur.Visible = true;
lblErreur.Text = "Une erreur s'est produite : " + Ex.Message ;
return;
} |
Partager