public IHttpActionResult Put(AnnonceVM annonceVM)
        {
            if (!ModelState.IsValid)
                return BadRequest("Not a valid model");

            using (var ctx = new MyContext())
            {
                var existingFormation = ctx.Annonces.Where(s => s.IdAnnonce == annonceVM.Id)
                                                        .FirstOrDefault<Annonce>();

                if (existingFormation != null)
                {
                    existingFormation.IdAnnonce = annonceVM.Id;
                    existingFormation.Titre = annonceVM.Titre;
                    existingFormation.DateAnnonce = DateTime.UtcNow;
                    existingFormation.Description = annonceVM.Description;
                    existingFormation.UserID = annonceVM.UserID;
                    existingFormation.Type_Dannonce = annonceVM.Type_Dannonce;
                    existingFormation.ImageBi = annonceVM.ImageBi;
                    existingFormation.LoyerMensuel = annonceVM.LoyerMensuel;
                    existingFormation.PrixAchat = annonceVM.PrixAchat;
                    existingFormation.jardin = annonceVM.jardin;
                    existingFormation.NombreDeChambre = annonceVM.NombreDeChambre;
                    ctx.SaveChanges();
                }
                else
                {
                    return NotFound();
                }
            }
            return Ok();
        }
예제 #2
0
        public ActionResult CreateAppartementV(AnnonceVM annonceVM, HttpPostedFileBase file)
        {
            try
            {
                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.Vente;
                A.Localisation    = annonceVM.Localisation;
                A.PrixAchat       = annonceVM.PrixAchat;
                A.Description     = annonceVM.Description;
                A.NombreDeChambre = annonceVM.NombreDeChambre;
                A.Superficie      = annonceVM.Superficie;
                A.ImageBi         = file.FileName;
                A.Type_Dannonce   = "Appartement";
                A.Etage           = annonceVM.Etage;
                A.Ascensseur      = annonceVM.Ascensseur;
                var fileName = "";
                if (file.ContentLength > 0)
                {
                    var path = Path.Combine(Server.MapPath("~/Content/"), file.FileName);
                    file.SaveAs(path);
                }



                //    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"));
            }
            catch
            {
                return(View());
            }
        }
예제 #3
0
        // GET: Annonce/Details
        public ActionResult Details(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Annonce f;

            f = AnnonceService.getAnnonceById((int)id);
            if (f == null)
            {
                return(HttpNotFound());
            }

            AnnonceVM AVM = new AnnonceVM()
            {
                Id              = f.IdAnnonce,
                UserID          = f.UserID,
                DateAnnonce     = f.DateAnnonce,
                Titre           = f.Titre,
                ImageBi         = f.ImageBi,
                Ascensseur      = f.Ascensseur,
                ChargeMensuel   = f.ChargeMensuel,
                CuisineEquipe   = f.CuisineEquipe,
                Description     = f.Description,
                Etage           = f.Etage,
                jardin          = f.jardin,
                Localisation    = f.Localisation,
                LoyerMensuel    = f.LoyerMensuel,
                PrixAchat       = f.PrixAchat,
                NombreDeChambre = f.NombreDeChambre,
                statut          = f.statut,
                type            = f.type,
                Superficie      = f.Superficie,
                Type_Dannonce   = f.Type_Dannonce,
                typeStudio      = f.typeStudio,
            };

            return(View(AVM));
        }
예제 #4
0
        public ActionResult CreateStudio(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.typeStudio    = Domain.Entities.TypeStudio.meublée;
            A.Type_Dannonce = "Studio";
            A.CuisineEquipe = annonceVM.CuisineEquipe;

            var fileName = "";

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



            //    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"));
        }
예제 #5
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"));
        }