public ActionResult Create(Order order)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Car car = CarRepository.Find(order.CarId);
                    car.Status = "Booked";
                    car.StatusRu = "Забронировано";

                    order.DateOfChange = DateTime.Now;
                    order.TotalPrice = ((TimeSpan)(order.ReturnDateTime - order.PickupDateTime)).Days * car.Price;
                    order.CarId = car.Id;

                    //SendMail(Convert.ToString(order.ApplicationNumber), order.Email, order.FirstName+" "+order.LastName);

                    OrderRepository.Create(order);
                    OrderRepository.Save();
                    CarRepository.Update(car);

                    return RedirectToAction("Index");
                }
            }
            catch(RetryLimitExceededException)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return View(order);
        }
Example #2
0
 public ActionResult DeleteOrder(Order order)
 {
     if (ModelState.IsValid)                     // check server-side validation
     {
         return RedirectToAction("Confirm", order);
     }
     else
     {
         return View();
     }
 }
        // GET: Cars/Order
        public ActionResult Order(FormCollection collection)
        {
            Car car=null;
            Guid newGuid = Guid.Empty;
            try {
                newGuid = Guid.Parse(collection["item.Id"]);
                car = CarRepository.Find(newGuid);
            }
            catch
            {

            }

            DateTime dtPickup = DateTime.Now; // НУЖНО ЗАМЕНИТЬ БД УСТАНОВИТЬ ЧТОБЫ ДАТА МОГЛА БЫТЬ NULL!!!!!!!!!!!!
            DateTime dtReturn = DateTime.Now;

            if (!String.IsNullOrEmpty(Session["PickupDateOriginal"] as string))
            {
                string pickupDate = ConvertDateForOrder((Session["PickupDateOriginal"] as string).Replace("/", "."));
                dtPickup = Convert.ToDateTime(pickupDate);
            }

            if (!String.IsNullOrEmpty(Session["ReturnDateOriginal"] as string))
            {
                string returnDate = ConvertDateForOrder((Session["ReturnDateOriginal"] as string).Replace("/", "."));
                dtReturn = Convert.ToDateTime(returnDate);
            }

            Order order = new Order()
            {
                Car = car,
                CarId = newGuid,
                PickupDateTime = dtPickup,
                PickupLocation = Session["PickupLocation"] as string,
                ReturnLocation = Session["DifferentLocation"] as bool?==true? Session["ReturnLocation"] as string : Session["PickupLocation"] as string,
                ReturnDateTime = dtReturn
            };

            if (!String.IsNullOrEmpty((Session["PickupDateOriginal"] as string)) & !String.IsNullOrEmpty((Session["ReturnDateOriginal"] as string)))
            {
                TimeSpan days = (TimeSpan)(order.ReturnDateTime - order.PickupDateTime);
                int day = Convert.ToInt32(days.Days);
                ViewBag.TotalPrice = day * order.Car.Price;
                ViewBag.Currency = "USD";
            }

            return View(order);
        }
Example #4
0
 public ActionResult ConfirmOrder(Order order)
 {
     return View(order);
 }