コード例 #1
0
        public ActionResult Create(CroisieresViewModel cvm, HttpPostedFileBase postedFile)
        {
            if (ModelState.IsValid)
            {
                if (postedFile != null)
                {
                    var filename = Path.GetFileName(postedFile.FileName);
                    if (filename == null)
                        return RedirectToAction("Create");
                    var path = Path.Combine(Server.MapPath("~/Uploads/Bateaux/"), filename);
                    postedFile.SaveAs(path);
                    cvm.Photo = filename;
                }
                Croisieres crs = new Croisieres()
                {
                    IdTheme = cvm.IdTheme,
                    IdDuree = cvm.IdDuree,
                    IdPromo = cvm.IdPromo,
                    IdPort = cvm.IdPort,
                    Prix = cvm.Prix,
                    DateDepart = DateTime.ParseExact(cvm.DateDepart, "dd/MM/yyyy", CultureInfo.InvariantCulture,
                    DateTimeStyles.None),
                    Photo = cvm.Photo,
                    Description = cvm.Description

                };
                db.Croisieres.Add(crs);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.IdDuree = new SelectList(db.Durees, "IdDuree", "NbJours");
            ViewBag.IdPort = new SelectList(db.Ports, "IdPort", "Nom");
            ViewBag.IdPromo = new SelectList(db.Promos, "IdPromo", "Reduction");
            ViewBag.IdTheme = new SelectList(db.Themes, "IdTheme", "Libelle");
            return View();
        }
コード例 #2
0
        public ActionResult Edit(int id, CroisieresViewModel cvm, HttpPostedFileBase postedFile)
        {
            if (ModelState.IsValid)
            {
                if (postedFile != null)
                {
                    var filename = Path.GetFileName(postedFile.FileName);
                    if (filename == null)
                        return RedirectToAction("Create");
                    var path = Path.Combine(Server.MapPath("~/Uploads/Bateaux/"), filename);
                    postedFile.SaveAs(path);
                    cvm.Photo = filename;
                }
                Croisieres crs = db.Croisieres.Find(id);

                crs.IdTheme = cvm.IdTheme;
                crs.IdDuree = cvm.IdDuree;
                crs.IdPromo = cvm.IdPromo;
                crs.IdPort = cvm.IdPort;
                crs.Prix = cvm.Prix;
                crs.DateDepart = DateTime.ParseExact(cvm.DateDepart, "dd/MM/yyyy", CultureInfo.InvariantCulture,
                DateTimeStyles.None);
                crs.Photo = cvm.Photo;
                crs.Description = cvm.Description;

                db.Entry(crs).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            Croisieres croisieres = db.Croisieres.Find(id);
            ViewBag.IdDuree = new SelectList(db.Durees, "IdDuree", "NbJours", croisieres.IdDuree);
            ViewBag.IdPort = new SelectList(db.Ports, "IdPort", "Nom", croisieres.IdPort);
            ViewBag.IdPromo = new SelectList(db.Promos, "IdPromo", "Reduction", croisieres.IdPromo);
            ViewBag.IdTheme = new SelectList(db.Themes, "IdTheme", "Libelle", croisieres.IdTheme);
            return View();
        }
コード例 #3
0
        // GET: Admin/Croisieres/Edit/5
        /// <summary>
        /// recherche et affiche une croisière sélectionnée par son id passé en paramètre 
        /// </summary>
        /// <param name="id"></param>
        /// <returns>croisiereViewModel</returns>
        public ActionResult Edit(int? id)
        {
            var bc = new BreadCrumbItem("Modification", "/Croisieres/Edit/"+id);
            lbc.Add(bc);
            ViewBag.ListeBC = lbc;

            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Croisieres croisieres = db.Croisieres.Find(id);
            if (croisieres == null)
            {
                return HttpNotFound();
            }
            CroisieresViewModel cvm = new CroisieresViewModel
            {
                IdTheme = croisieres.IdTheme,
                IdDuree = croisieres.IdDuree,
                IdPromo = (int)croisieres.IdPromo,
                IdPort = croisieres.IdPort,
                Prix = croisieres.Prix,
                DateDepart = croisieres.DateDepart.ToString("dd/MM/yyyy",
                  CultureInfo.InvariantCulture),
                Photo = croisieres.Photo,
                Description = croisieres.Description
            };

            ViewBag.IdDuree = new SelectList(db.Durees, "IdDuree", "NbJours", cvm.IdDuree);
            ViewBag.IdPort = new SelectList(db.Ports, "IdPort", "Nom", cvm.IdPort);
            ViewBag.IdPromo = new SelectList(db.Promos, "IdPromo", "Reduction", cvm.IdPromo);
            ViewBag.IdTheme = new SelectList(db.Themes, "IdTheme", "Libelle", cvm.IdTheme);
            return View(cvm);
        }