コード例 #1
0
 public ActionResult Create([Bind(Include = "Id,Count,Price,BikeId,CompanyLocationId")] CompanyBike companyBike)
 {
     if (ModelState.IsValid)
     {
         db.CompanyBikes.Add(companyBike);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BikeId = new SelectList(db.Bikes, "Id", "BikeModel", companyBike.BikeId);
     return(View(companyBike));
 }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "Id,Count,BikeId,CompanyLocationId")] CompanyBike companyBike)
 {
     if (ModelState.IsValid)
     {
         db.Entry(companyBike).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BikeId            = new SelectList(db.Bikes, "Id", "Model", companyBike.BikeId);
     ViewBag.CompanyLocationId = new SelectList(db.CompanyLocations, "Id", "Street", companyBike.CompanyLocationId);
     return(View(companyBike));
 }
コード例 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            CompanyBike companyBike = db.CompanyBikes.Find(id);

            if (db.Bookings.Where(b => b.CompanyBikeId == id).ToList().Count > 0)
            {
                ViewBag.Result = "The bike is used in bookings and cannot be deleted.";
                return(View(companyBike));
            }
            db.CompanyBikes.Remove(companyBike);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        // GET: CompanyBikes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CompanyBike companyBike = db.CompanyBikes.Find(id);

            if (companyBike == null)
            {
                return(HttpNotFound());
            }
            return(View(companyBike));
        }
コード例 #5
0
        public ActionResult Create(int companyLocationId)
        {
            CompanyLocation companyLocation = db.CompanyLocations.Find(companyLocationId);

            if (companyLocation == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BikeId = new SelectList(db.Bikes, "Id", "BikeModel");
            var bike = new CompanyBike();

            bike.CompanyLocationId = companyLocationId;
            return(View(bike));
        }
コード例 #6
0
        // GET: Bookings/Details/5
        //public ActionResult Details(int? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    Booking booking = db.Bookings.Find(id);
        //    if (booking == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(booking);
        //}

        // GET: Bookings/Create
        public ActionResult Create(int?companyBikeId, string sDate, string eDate)
        {
            if (companyBikeId == null || sDate == null || eDate == null)
            {
                return(HttpNotFound());
            }

            try
            {
                DateTime startDate = DateTime.ParseExact(sDate, "d/M/yyyy", CultureInfo.InvariantCulture);
                DateTime endDate   = DateTime.ParseExact(eDate, "d/M/yyyy", CultureInfo.InvariantCulture);

                if (startDate >= endDate)
                {
                    return(HttpNotFound());
                }

                if (startDate <= DateTime.Today)
                {
                    return(HttpNotFound());
                }

                // check the num of days of booking, max: 7
                if ((endDate - startDate).TotalDays > 7)
                {
                    return(HttpNotFound());
                }

                CompanyBike companyBike = db.CompanyBikes.Find(companyBikeId);
                if (companyBike == null)
                {
                    return(HttpNotFound());
                }

                Booking booking = new Booking();
                booking.CompanyBike = companyBike;
                booking.StartDate   = startDate;
                booking.EndDate     = endDate;
                booking.UserId      = User.Identity.GetUserId();

                ViewBag.TotalPrice = companyBike.Price * (endDate - startDate).TotalDays;

                return(View(booking));
            }
            catch (System.FormatException e)
            {
                return(HttpNotFound());
            }
        }
コード例 #7
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CompanyBike companyBike = db.CompanyBikes.Find(id);

            if (companyBike == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BikeId = new SelectList(db.Bikes, "Id", "Model", companyBike.BikeId);
            return(View(companyBike));
        }