Ejemplo n.º 1
0
        public ActionResult <OrderdCars> CheckOutOrder([FromBody] CheckOutOrder value)
        //public String CheckOutOrder([FromBody] CheckOutOrder value)
        {
            //return value.OrderCarID.ToString() + ',' + value.CustomerID.ToString();
            OrderdCarsRepository oc = new OrderdCarsRepository();
            OrderdCars           currentOrderCar = oc.FindById(value.OrderCarID);

            if (currentOrderCar != null)
            {
                if ((currentOrderCar.Status == 2) && (currentOrderCar.CustomerID == value.CustomerID))
                {
                    DateTime startDT = (DateTime)currentOrderCar.StarteDT;
                    TimeSpan ts      = DateTime.Now.AddSeconds(-20) - startDT;
                    double   total   = Math.Round(ts.TotalMinutes * currentOrderCar.Car.CarModel.PricePerMin, 1);

                    currentOrderCar.Status = 3;
                    currentOrderCar.EndDT  = DateTime.Now;
                    currentOrderCar.Total  = (float)total;
                    oc.Dispose();

                    CarRepository cr         = new CarRepository();
                    Car           currentCar = cr.FindById(currentOrderCar.CarID);
                    currentCar.Status = 0;
                    cr.Dispose();

                    return(currentOrderCar);
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        public int GetSecondsIntervalBetweenStartAndNow(int id)
        {
            OrderdCarsRepository oc = new OrderdCarsRepository();
            OrderdCars           currentOrderCar = oc.FindById(id);
            DateTime             startDT         = (DateTime)currentOrderCar.StarteDT;
            TimeSpan             ts = DateTime.Now - startDT;

            return(Convert.ToInt32(Math.Round(ts.TotalSeconds, 0)));
        }
Ejemplo n.º 3
0
        public ActionResult <OrderdCars> Post([FromBody] ReserverCar value)
        {
            CarRepository cr = new CarRepository();

            cr.UpdateStatusByCarID(1, value.CarID);

            Helper.Helper helper = new Helper.Helper();

            var orderCar = new OrderdCars {
                Status = 1, CreateDT = DateTime.Now, ValidityDT = DateTime.Now.AddMinutes(20), PinkCode = helper.GetPinkCode().ToString(), CustomerID = value.CustomerID, CarID = value.CarID
            };

            OrderdCarsRepository oc = new OrderdCarsRepository();

            oc.Add(orderCar);
            oc.Dispose();

            return(orderCar);
        }
Ejemplo n.º 4
0
        public ActionResult <TryPayment> TryPayment(int id)
        {
            OrderdCarsRepository oc = new OrderdCarsRepository();
            OrderdCars           currentOrderCar = oc.FindById(id);
            DateTime             startDT         = (DateTime)currentOrderCar.StarteDT;
            TimeSpan             ts = DateTime.Now - startDT;

            if (currentOrderCar.Status == 2)
            {
                TryPayment result = new TryPayment
                {
                    EndDT = DateTime.Now,
                    Total = Math.Round(ts.TotalMinutes * currentOrderCar.Car.CarModel.PricePerMin, 1)
                };
                return(result);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        public bool Unlock([FromBody] UnlockCar value)
        {
            OrderdCarsRepository oc           = new OrderdCarsRepository();
            CarRepository        cr           = new CarRepository();
            OrderdCars           currentOrder = oc.FindByCarIdAndPinkCode(value.CarID, value.PinkCode);

            //return currentOrder;
            if (!(currentOrder == null))
            {
                if (currentOrder.PinkCode == value.PinkCode)
                {
                    currentOrder.Status   = 2;
                    currentOrder.StarteDT = DateTime.Now;
                    oc.Dispose();

                    Car currentCar = cr.FindById(value.CarID);
                    currentCar.Status = 2;
                    cr.Dispose();

                    return(true);
                }
            }
            return(false);
        }