public Annonce Post(Annonce annonce)
        {

            MyService.Add(annonce);
            MyService.Commit();

            return annonce;
        }
Esempio n. 2
0
        public ActionResult Create(AnnonceVM annonceVM, HttpPostedFileBase file)
        {
            Annonce A = new Annonce();

            A.Titre           = annonceVM.Titre;
            A.DateAnnonce     = DateTime.UtcNow;
            A.statut          = Solution.Domain.Entities.Statut.disponible;
            A.type            = Solution.Domain.Entities.Type_ano.Location;
            A.Localisation    = annonceVM.Localisation;
            A.LoyerMensuel    = annonceVM.LoyerMensuel;
            A.Description     = annonceVM.Description;
            A.ImageBi         = file.FileName;
            A.NombreDeChambre = annonceVM.NombreDeChambre;
            A.jardin          = annonceVM.jardin;
            A.Type_Dannonce   = "Maison";

            var fileName = "";

            if (file.ContentLength > 0)
            {
                var path = Path.Combine(Server.MapPath("~/Content/"), file.FileName);
                file.SaveAs(path);
            }
            //try
            //{
            //    if (file.ContentLength > 0)
            //    {

            //        var fileName = Path.GetFileName(file.FileName);
            //        var path = Path.Combine(Server.MapPath("~/Content/Documents/"), fileName);
            //        file.SaveAs(path);
            //        annonceVM.SizeImage = file.ContentLength / 1024;

            //        A.ImageBi = "~/Content/Documents/" + fileName;
            //        ViewBag.Message = "File Uploaded Successfully!!";
            //    }
            //}
            //catch
            //{
            //    ViewBag.Message = "File upload failed!!";
            //    return View();
            //}
            //A.SizeImage = annonceVM.SizeImage;

            //if (annonceVM.type == 0)
            //{
            //    A.UserID = User.Identity.GetUserId<string>();
            //    AnnonceService.Add(A);
            //    AnnonceService.Commit();


            //    return RedirectToAction("CreateM");
            //}
            //else
            A.UserID = User.Identity.GetUserId();
            AnnonceService.Add(A);
            AnnonceService.Commit();
            //var path = Path.Combine(Server.MapPath("~/Content/Upload/"), Image.FileName);
            //Image.SaveAs(path);
            return(RedirectToAction("Index"));
        }