コード例 #1
0
        public ActionResult ChangeStatus(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            using (CarStoreEntities db = new CarStoreEntities())
            {
                Booking car = db.Bookings.Find(id);

                db.Bookings.Remove(car);

                Car cars = db.Cars.Find(id);
                cars.Type            = "Available";
                db.Entry(cars).State = EntityState.Modified;
                db.SaveChanges();


                if (car == null)
                {
                    return(HttpNotFound());
                }
                return(RedirectToAction("AvailableCar", "Admin"));
            }
        }
コード例 #2
0
        // brand operations  C.R.U.D

        public ActionResult BrandList()
        {
            using (CarStoreEntities db = new CarStoreEntities())
            {
                return(View(db.Brands.ToList()));
            }
        }
コード例 #3
0
        public ActionResult DetailsCar(int id)
        {
            CarStoreEntities db = new CarStoreEntities();
            var car             = db.Cars.Find(id);

            return(View(car));
        }
コード例 #4
0
        // CarType operation

        public ActionResult CarTypeList()
        {
            using (CarStoreEntities db = new CarStoreEntities())
            {
                return(View(db.CarTypes.ToList()));
            }
        }
コード例 #5
0
        public ActionResult AddCar([Bind(Include = "CarId,CarTypesId,BrandId,Name,Price,CarUrl, CarUrl2 , CarUrl3 ,Class, Type, Description,Fuel,Doors,GearBox ")] Car car, HttpPostedFileBase file, HttpPostedFileBase file2, HttpPostedFileBase file3)
        {
            CarStoreEntities db = new CarStoreEntities();

            if (ModelState.IsValid && file != null && file2 != null && file3 != null)
            {
                var fileName  = Path.GetFileName(file.FileName);
                var fileName2 = Path.GetFileName(file2.FileName);
                var fileName3 = Path.GetFileName(file3.FileName);
                var path      = Path.Combine(Server.MapPath("~/Content/images/Upload"), fileName);
                var path2     = Path.Combine(Server.MapPath("~/Content/images/Upload"), fileName2);
                var path3     = Path.Combine(Server.MapPath("~/Content/images/Upload"), fileName3);

                file.SaveAs(path);
                file2.SaveAs(path2);
                file3.SaveAs(path3);

                car.Type   = "Available";
                car.CarUrl = "/Content/images/Upload/" + fileName;
                db.Cars.Add(car);
                car.CarUrl2 = "/Content/images/Upload/" + fileName2;
                db.Cars.Add(car);
                car.CarUrl3 = "/Content/images/Upload/" + fileName3;
                db.Cars.Add(car);
                db.SaveChangesAsync();
                return(RedirectToAction("CarList", "Admin"));
            }

            ViewBag.ArtistId   = new SelectList(db.Brands, "BrandId", "Name", car.CarId);
            ViewBag.GenreId    = new SelectList(db.CarTypes, "CarTypesId", "Name", car.CarTypesId);
            ViewBag.uploadInfo = "Please select an Image!";


            return(View(car));
        }
コード例 #6
0
 public ActionResult RentedCar()
 {
     using (CarStoreEntities db = new CarStoreEntities())
     {
         var cars = db.Bookings.Where(U => U.Status == "Attente");
         return(View(cars.ToList()));
     }
 }
コード例 #7
0
 public ActionResult Cars()
 {
     using (CarStoreEntities db = new CarStoreEntities())
     {
         var types = db.CarTypes.ToList();
         return(View(types));
     }
 }
コード例 #8
0
 public ActionResult AvailableCar()
 {
     using (CarStoreEntities db = new CarStoreEntities())
     {
         var cars = db.Cars.Where(U => U.Type == "Available");
         return(View(cars.ToList()));
     }
 }
コード例 #9
0
 public ActionResult CarList()
 {
     using (CarStoreEntities db = new CarStoreEntities())
     {
         var cars = db.Cars.Include(a => a.Brand).Include(a => a.CarTypes);
         return(View(cars.ToList()));
     }
 }
コード例 #10
0
        public ActionResult DeleteConfirmed(int id)
        {
            CarStoreEntities db = new CarStoreEntities();
            Car car             = db.Cars.Find(id);

            db.Cars.Remove(car);
            db.SaveChanges();
            return(RedirectToAction("CarList"));
        }
コード例 #11
0
        public ActionResult AddCar()
        {
            CarStoreEntities db = new CarStoreEntities();

            ViewBag.BrandId    = new SelectList(db.Brands, "BrandId", "Name");
            ViewBag.CarTypesId = new SelectList(db.CarTypes, "CarTypesId", "Name");

            return(View());
        }
コード例 #12
0
        public ActionResult AddressAndPayement(FormCollection values)
        {
            CarStoreEntities db        = new CarStoreEntities();
            const string     PromoCode = "FD1FBN2FMNJT";
            var order = new Booking {
            };
            var car   = new Car {
            };

            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == true)
                {
                    order.Username    = User.Identity.Name;
                    order.BookingDate = DateTime.Now;

                    //Save Order
                    db.Bookings.Add(order);
                    db.SaveChanges();
                    //Process the order
                    var cart = ShoppingCart.GetCart(this.HttpContext);
                    cart.CreateOrder(order, 0.8m);


                    return(RedirectToAction("OrderDetails",
                                            new { id = order.BookingId }));

                    //return RedirectToAction("OrderDetail", order);

                    //return View(order);
                }
                else
                {
                    order.Username    = User.Identity.Name;
                    order.BookingDate = DateTime.Now;
                    order.Status      = "Attente";


                    //Save Order
                    db.Bookings.Add(order);
                    db.SaveChanges();
                    //Process the order
                    var cart = ShoppingCart.GetCart(this.HttpContext);
                    cart.CreateOrder(order, 1);

                    return(RedirectToAction("OrderDetails", new { id = order.BookingId }));
                }
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(order));
            }
        }
コード例 #13
0
        public ActionResult Browse(int?page, string genre = "Hot")
        {
            CarStoreEntities db = new CarStoreEntities();

            // Retrieve Types and its Associated car from database
            var genreModel = db.CarTypes.Include("Cars")
                             .Single(g => g.Name == genre).Cars;

            return(View(genreModel.ToList().ToPagedList(page ?? 1, 4)));
        }
コード例 #14
0
 public ActionResult DeleteBrand(int?id)
 {
     using (CarStoreEntities db = new CarStoreEntities())
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         Brand brand = db.Brands.Find(id);
         return(View(brand));
     }
 }
コード例 #15
0
 public ActionResult DeleteCarType(int?id)
 {
     using (CarStoreEntities db = new CarStoreEntities())
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         CarTypes cartype = db.CarTypes.Find(id);
         return(View(cartype));
     }
 }
コード例 #16
0
 public ActionResult AddCarType(CarTypes cartype)
 {
     if (ModelState.IsValid)
     {
         using (CarStoreEntities db = new CarStoreEntities())
         {
             db.CarTypes.Add(cartype);
             db.SaveChanges();
             return(RedirectToAction("CarTypeList", "Admin"));
         }
     }
     return(View());
 }
コード例 #17
0
 public ActionResult EditBrand([Bind(Include = "Name,BrandId")] Brand brand)
 {
     if (ModelState.IsValid)
     {
         using (CarStoreEntities db = new CarStoreEntities())
         {
             db.Entry(brand).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("BrandList", "Admin"));
         }
     }
     return(View(brand));
 }
コード例 #18
0
 public ActionResult EditCarType([Bind(Include = "Name,CarTypesId,Description,Type")] CarTypes cartype)
 {
     if (ModelState.IsValid)
     {
         using (CarStoreEntities db = new CarStoreEntities())
         {
             db.Entry(cartype).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("CarTypeList", "Admin"));
         }
     }
     return(View(cartype));
 }
コード例 #19
0
 public ActionResult AddBrand(Brand brand)
 {
     if (ModelState.IsValid)
     {
         using (CarStoreEntities db = new CarStoreEntities())
         {
             db.Brands.Add(brand);
             db.SaveChanges();
             return(RedirectToAction("BrandList", "Admin"));
         }
     }
     return(View());
 }
コード例 #20
0
        public ActionResult CarTypeMenu()
        {
            //var genres = from p in storeDB.Genres
            //             orderby p.Name ascending
            //             select new GenreViewModel
            //             {  AlbumsCount = p.Albums.Count, GenreName =p.Name };

            using (CarStoreEntities db = new CarStoreEntities())
            {
                var cartype = db.CarTypes.Include("Cars").OrderBy(g => g.Name);
                var model   = cartype.ToList();
                return(PartialView("_CarTypeMenu", model));
            }
        }
コード例 #21
0
        public ActionResult DeleteBrand(int id)
        {
            using (CarStoreEntities db = new CarStoreEntities())
            {
                Brand brand = db.Brands.Find(id);
                if (ModelState.IsValid)
                {
                    db.Brands.Remove(brand);
                    db.SaveChanges();
                    return(RedirectToAction("BrandList", "Admin"));
                }

                return(View());
            }
        }
コード例 #22
0
        public ActionResult DeleteCarType(int id)
        {
            using (CarStoreEntities db = new CarStoreEntities())
            {
                CarTypes cartype = db.CarTypes.Find(id);
                if (ModelState.IsValid)
                {
                    db.CarTypes.Remove(cartype);
                    db.SaveChanges();
                    return(RedirectToAction("CarTypeList", "Admin"));
                }

                return(View());
            }
        }
コード例 #23
0
 public ActionResult DetailsAvailableCAr(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     using (CarStoreEntities db = new CarStoreEntities())
     {
         Car car = db.Cars.Find(id);
         if (car == null)
         {
             return(HttpNotFound());
         }
         return(View(car));
     }
 }
コード例 #24
0
 public ActionResult DetailsBrand(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     using (CarStoreEntities db = new CarStoreEntities())
     {
         Brand brand = db.Brands.Find(id);
         if (brand == null)
         {
             return(HttpNotFound());
         }
         return(View(brand));
     }
 }
コード例 #25
0
        public ActionResult DeleteCar(int?id)
        {
            CarStoreEntities db = new CarStoreEntities();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Car car = db.Cars.Find(id);

            if (car == null)
            {
                return(HttpNotFound());
            }
            return(View(car));
        }
コード例 #26
0
 public ActionResult DetailsCarType(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     using (CarStoreEntities db = new CarStoreEntities())
     {
         CarTypes cartype = db.CarTypes.Find(id);
         if (cartype == null)
         {
             return(HttpNotFound());
         }
         return(View(cartype));
     }
 }
コード例 #27
0
        public ActionResult Complete(int id)
        {
            CarStoreEntities db = new CarStoreEntities();

            bool isValid = db.Bookings.Any(
                o => o.BookingId == id &&
                o.Username == User.Identity.Name);

            if (isValid)
            {
                return(View(id));
            }
            else
            {
                return(View("Error"));
            }
        }
コード例 #28
0
        public ActionResult BookCar(int id)
        {
            CarStoreEntities db = new CarStoreEntities();

            Car Car = db.Cars.Find(id);

            Car.Type            = "Rented";
            db.Entry(Car).State = EntityState.Modified;


            var addedCar = db.Cars
                           .Single(car => car.CarId == id);


            var cart = ShoppingCart.GetCart(this.HttpContext);

            cart.AddToCart(addedCar);
            db.SaveChanges();
            return(RedirectToAction("AddressAndPayement", "Home"));
        }
コード例 #29
0
        public ActionResult EditCar(int?id)
        {
            CarStoreEntities db = new CarStoreEntities();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Car car = db.Cars.Find(id);

            if (car == null)
            {
                return(HttpNotFound());
            }

            ViewBag.BrandId    = new SelectList(db.Brands, "BrandId", "Name", car.CarId);
            ViewBag.CarTypesId = new SelectList(db.CarTypes, "CarTypesId", "Name", car.CarTypesId);
            ViewBag.uploadInfo = "Please select an Image!";
            return(View(car));
        }
コード例 #30
0
        public ActionResult OrderDetails(int id)
        {
            CarStoreEntities db = new CarStoreEntities();

            ViewBag.total = db.Bookings.Single(o => o.BookingId == id).Total;

            bool isValid = db.Bookings.Any(
                o => o.BookingId == id &&
                o.Username == User.Identity.Name);

            if (isValid)
            {
                var oderWithDetails = db.Bookings.Include("BookingDetails").Single(o => o.BookingId == id).BookingDetails.ToList();

                return(View(oderWithDetails));
            }
            else
            {
                return(View("Error"));
            }
        }