Ejemplo n.º 1
0
        public void CanAddReservation()
        {
            // arrange
            IRepo <Customer>     customerRepo     = new MockContext <Customer>();
            IRepo <Car>          carRepo          = new MockContext <Car>();
            IRepo <Reservation>  reservationRepo  = new MockContext <Reservation>();
            IRepo <Location>     locationRepo     = new MockContext <Location>();
            IRepo <Model>        modelRepo        = new MockContext <Model>();
            IRepo <Manufacturer> manufacturerRepo = new MockContext <Manufacturer>();

            var controller = new ReservationController(carRepo, customerRepo, reservationRepo,
                                                       locationRepo, modelRepo, manufacturerRepo);

            var reservation = new QueryReservation
            {
                CarId      = 1,
                CustomerId = 1,
                StartDate  = new DateTime(2020, 9, 1),
                EndDate    = new DateTime(2020, 9, 2),
                Location   = "Brasov"
            };

            // act
            controller.Create(reservation);
            Reservation r = reservationRepo.Collection().FirstOrDefault();

            // assert
            Assert.IsNotNull(r);
            Assert.AreEqual(1, reservationRepo.Collection().Count());
            Assert.AreEqual(new DateTime(2020, 9, 1), r.StartDate);
        }
Ejemplo n.º 2
0
        internal void ManageReservations(bool isCreating)
        {
            inAppBehavior.MenuItemEntry("Register new Car Rent", "Update Car Rent", isCreating);

            int id = 1;

            if (!isCreating)
            {
                id = reader.ReadInt("Reservation ID: ");
            }
            DateTime startDate = reader.ReadDate("Start Date: ");
            DateTime endDate   = reader.ReadDate("End Date: ");

            QueryReservation queryReservation = new QueryReservation
            {
                Id         = id,
                StartDate  = startDate,
                EndDate    = endDate,
                IsCreating = isCreating
            };

            if (isCreating)
            {
                string plate      = reader.ReadString("Car Plate: ");
                int    customerId = reader.ReadInt("Client ID: ");
                string location   = reader.ReadString("City: ");
                queryReservation.Plate      = plate;
                queryReservation.CustomerId = customerId;
                queryReservation.Location   = location;
            }

            PushModel(queryReservation, isCreating, contextManager.ManageReservations, ManageReservations);
        }
Ejemplo n.º 3
0
        public ActionResult Update(QueryReservation reservation)
        {
            if (!ModelState.IsValid)
            {
                OverrideErrorMessage("Date should be in format dd-MM-yyyy");
                return(View(reservation));
            }

            contextManager.ManageReservations(false, reservation);

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 4
0
        public override bool IsValid(object value)
        {
            QueryReservation r = value as QueryReservation;

            if (r.EndDate < r.StartDate)
            {
                this.ErrorMessage = "End Date should be equal or bigger than Start Date";
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        public override bool IsValid(object value)
        {
            QueryReservation r = value as QueryReservation;
            int id             = r.Id;

            if (!r.IsCreating && (id < 1 || id > int.MaxValue))
            {
                this.ErrorMessage = String.Format("Id should be between 1 and {0}", int.MaxValue);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
0
        public void ManageReservations(bool creating, QueryReservation queryReservation)
        {
            Reservation r = creating ? new Reservation() : queryReservation.Reservation;

            if (queryReservation.IsCreating)
            {
                r.CarId      = queryReservation.CarId;
                r.CustomerId = (int)queryReservation.CustomerId;
                r.LocationId = queryReservation.LocationId;
            }
            r.StartDate = (DateTime)queryReservation.StartDate;
            r.EndDate   = (DateTime)queryReservation.EndDate;


            InsertUpdateCommit(creating, r, reservationRepo);
        }