コード例 #1
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));
            }
        }
コード例 #2
0
        public ActionResult Create(SaleRecord saleRecord)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            carData.SaleRecords.Add(saleRecord);
            carData.SaveChanges();

            return(RedirectToAction("SaleList"));
        }
コード例 #3
0
 public ActionResult Create(CarRecord carRecord)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     carData.CarRecords.Add(carRecord);
     carData.SaveChanges();
     //Response.Redirect("StudentAdmission",true);
     return(RedirectToAction("CarList"));
 }
コード例 #4
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"));
            }
        }
コード例 #5
0
        // GET: Purchase/Delete/5
        public ActionResult Delete(ContactRecord IdtoDel)
        {
            var d = carData.ContactRecords.Where(x => x.ID == IdtoDel.ID).FirstOrDefault();

            carData.ContactRecords.Remove(d);
            carData.SaveChanges();
            return(RedirectToAction("QueryList"));
        }
コード例 #6
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"));
        }
コード例 #7
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());
 }
コード例 #8
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));
 }
コード例 #9
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());
 }
コード例 #10
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));
 }
コード例 #11
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());
            }
        }
コード例 #12
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());
            }
        }
コード例 #13
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"));
        }
コード例 #14
0
        public ActionResult EditCar([Bind(Include = "CarId,CarTypesId,BrandId,Name,Price,CarUrl, CarUrl2 , CarUrl3 ,Class, Type, Description,Fuel,Doors,GearBox ")] Car car, int id, HttpPostedFileBase file, HttpPostedFileBase file2, HttpPostedFileBase file3)
        {
            CarStoreEntities db = new CarStoreEntities();

            if (ModelState.IsValid)
            {
                car.CarId = id;


                if (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.CarUrl  = "/Content/Images/Upload/" + fileName;
                    car.CarUrl2 = "/Content/images/Upload/" + fileName2;
                    car.CarUrl3 = "/Content/images/Upload/" + fileName3;
                }
                db.Entry(car).State = EntityState.Modified;
                db.SaveChanges();
                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));
        }