コード例 #1
0
 public ActionResult Edit([Bind(Include = "Id,Title,Text,File")] CaruselViewModel model)
 {
     if (ModelState.IsValid)
     {
         Carusel carusel = db.carusel.Single(s => s.Id == model.Id);
         if (carusel == null)
         {
             return(HttpNotFound());
         }
         carusel.Title = model.Title;
         carusel.Text  = model.Text;
         if (model.File != null && model.File.ContentLength > 0)
         {
             var fileExtension = Path.GetExtension(model.File.FileName);
             var fileName      = Path.GetFileNameWithoutExtension(model.File.FileName) + "-" +
                                 DateTime.Now.ToString("yyyyMMddHHmmssfff") + fileExtension;
             var path = Path.Combine(Server.MapPath("~/Img/carusel"), fileName);
             model.File.SaveAs(path);
             carusel.ImgPath = "/Img/carusel/" + fileName;
         }
         db.SaveChanges();
         ViewBag.AlertMessage = "changes has ended succesfully";
         return(RedirectToAction("List"));
     }
     ViewBag.AlertMessage = "Something gone wrong. Try again please!";
     return(RedirectToAction("List"));
 }
コード例 #2
0
        public ActionResult Create([Bind(Include = "Title,Text,File")] CaruselViewModel model)
        {
            if (ModelState.IsValid)
            {
                Carusel carusel = new Carusel();
                carusel.Title = model.Title;
                carusel.Text  = model.Text;
                if (model.File != null && model.File.ContentLength > 0)
                {
                    var fileExtension = Path.GetExtension(model.File.FileName);
                    var fileName      = Path.GetFileNameWithoutExtension(model.File.FileName) + "-" +
                                        DateTime.Now.ToString("yyyyMMddHHmmssfff") + fileExtension;
                    var path = Path.Combine(Server.MapPath("~/Img/carusel"), fileName);
                    model.File.SaveAs(path);
                    carusel.ImgPath = "/Img/carusel/" + fileName;
                }

                db.carusel.Add(carusel);
                db.SaveChanges();
                TempData["AlertMessage"] = "The Carusel has created succesfully";
                return(RedirectToAction("List"));
            }
            TempData["AlertMessage"] = "Something gone wrong. Try again please!";
            return(RedirectToAction("List"));
        }
コード例 #3
0
        //GET: Carusels/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Carusel carusel = db.carusel.Find(id);

            if (carusel == null)
            {
                return(HttpNotFound());
            }
            return(Json(new { Text = carusel.Text, Id = carusel.Id, Title = carusel.Title, Image = carusel.ImgPath }, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public ActionResult DeleteConfirmed(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Carusel carusel = db.carusel.Find(id);

            if (carusel == null)
            {
                return(HttpNotFound());
            }
            db.carusel.Remove(carusel);
            db.SaveChanges();
            return(RedirectToAction("List"));
        }
コード例 #5
0
ファイル: CarsGenerator.cs プロジェクト: renat784/Cars
        public IEnumerable <Car> Generate(
            List <string> styles,
            List <string> bodystyle,
            List <string> colorlist,
            List <string> transmissiaonlist,
            List <string> makelist,
            List <string> toyota,
            List <string> honda,
            List <string> lexus,
            List <string> ford,
            List <string> kia,
            int TotalCountToGenerate = 20)
        {
            var list             = new List <Car>();
            var caruselForMake   = new Carusel(0, makelist.Count - 1, true);
            var caruselForToyota = new Carusel(0, toyota.Count - 1, true);
            var caruselForHonda  = new Carusel(0, honda.Count - 1, true);
            var caruselForLexus  = new Carusel(0, lexus.Count - 1, true);
            var caruselForFord   = new Carusel(0, ford.Count - 1, true);
            var caruselForKia    = new Carusel(0, kia.Count - 1, true);

            var caruselForYear           = new Carusel(2000, 2020, true);
            var caruselForStyleId        = new Carusel(0, styles.Count - 1, true);
            var caruselForBodystyleId    = new Carusel(0, bodystyle.Count - 1, true);
            var caruselForTransmissionId = new Carusel(0, transmissiaonlist.Count - 1, true);
            var caruselForMillieage      = new Carusel(50000, 100000, true);
            var caruselForColorId        = new Carusel(0, colorlist.Count - 1, true);
            var caruselForPrice          = new Carusel(5000, 25000, true);


            for (int i = 1; i <= TotalCountToGenerate; i++)
            {
                var make = makelist[caruselForMake.Next()];

                var name = "";

                switch (make)
                {
                case "Toyota":
                    name = toyota[caruselForToyota.Next()];
                    break;

                case "Honda":
                    name = honda[caruselForHonda.Next()];
                    break;

                case "Lexus":
                    name = lexus[caruselForLexus.Next()];
                    break;

                case "Ford":
                    name = ford[caruselForFord.Next()];
                    break;

                case "Kia":
                    name = kia[caruselForKia.Next()];
                    break;
                }

                list.Add(new Car
                {
                    CarId         = i,
                    Make          = make,
                    Model         = name,
                    Year          = caruselForYear.Next(),
                    Style         = styles[caruselForStyleId.Next()],
                    Bodystyle     = bodystyle[caruselForBodystyleId.Next()],
                    Transmission  = transmissiaonlist[caruselForTransmissionId.Next()],
                    Mileage       = caruselForMillieage.Next(),
                    ExteriorColor = colorlist[caruselForColorId.Next()],
                    InteriorColor = colorlist[caruselForColorId.Next()],
                    Price         = caruselForPrice.Next()
                });
            }

            return(list);
        }