Example #1
0
        public static void RegisterNewCarRent(ReservationsDTO reservationsDTO)
        {
            var db          = new RentCDataBaseEntities();
            var reservation = ConvertToEntity(reservationsDTO);

            db.Reservations.Add(reservation);
            db.SaveChanges();
        }
        public static void RegisterNewCustomer(DTO.CustomersDTO newCustomer)
        {
            var db       = new RentCDataBaseEntities();
            var customer = ConvertToEntities(newCustomer);

            db.Customers.Add(customer);
            db.SaveChanges();
        }
Example #3
0
        public static void CreateNewStatus(DTO.ReservationStatusesDTO status)
        {
            var db        = new RentCDataBaseEntities();
            var newStatus = ConvertToEntity(status);

            db.ReservationStatuses.Add(newStatus);
            db.SaveChanges();
        }
Example #4
0
        public static List <DTO.CarsDTO> ListCars()
        {
            var db   = new RentCDataBaseEntities();
            var cars = db.Cars.ToList();

            var carsDTO = ConvertToDTO(cars);

            return(carsDTO);
        }
Example #5
0
        public static List <DTO.ReservationStatusesDTO> ListStatuses()
        {
            var db      = new RentCDataBaseEntities();
            var statues = db.ReservationStatuses.ToList();

            var statutesDTO = ConvertToDTO(statues);


            return(statutesDTO);
        }
Example #6
0
        public static DTO.ReservationStatusesDTO RetrieveStatus()
        {
            var db = new RentCDataBaseEntities();

            var status = db.ReservationStatuses.Max(p => p.ReservStatsID);

            var statusDto = new DTO.ReservationStatusesDTO();

            statusDto.ReservStatsID = status;

            return(statusDto);
        }
        public static void UpdateCustomer(DTO.CustomersDTO updateCustomersDto)
        {
            var db             = new RentCDataBaseEntities();
            var updateCustomer = ConvertToEntities(updateCustomersDto);

            var customer = db.Customers.Where(p => p.CostumerID == updateCustomer.CostumerID).FirstOrDefault <Customers>();

            customer.Name      = updateCustomer.Name;
            customer.BirthDate = updateCustomer.BirthDate;
            customer.Location  = updateCustomer.Location;

            db.SaveChanges();
        }
Example #8
0
        public static void UpdateStatus(DTO.ReservationStatusesDTO status)
        {
            var db     = new RentCDataBaseEntities();
            var update = ConvertToEntity(status);

            var newStatus = db.ReservationStatuses.Where(p => p.ReservStatsID == update.ReservStatsID).FirstOrDefault();

            //newStatus.ReservStatsID = update.ReservStatsID;
            newStatus.Name        = update.Name;
            newStatus.Description = update.Description;

            db.SaveChanges();
        }
Example #9
0
        //public static void UpdateCarRent(DTO.ReservationsDTO update)
        //{
        //    var db = new RentCDataBaseEntities();
        //    var updateReservation = ConvertToEntity(update);

        //    var reservation = db.Reservations.Where(p => p.CarID == updateReservation.CarID
        //    && p.CostumerID == updateReservation.CostumerID).FirstOrDefault<Reservations>();

        //    //reservation.ReservationID = updateReservation.ReservationID;
        //    reservation.CarID = updateReservation.CarID;
        //    reservation.CostumerID = updateReservation.CostumerID;
        //    reservation.ReservStatsID = updateReservation.ReservStatsID;
        //    reservation.StartDate = updateReservation.StartDate;
        //    reservation.EndDate = updateReservation.EndDate;
        //    reservation.Location = updateReservation.Location;

        //    db.SaveChanges();

        //}

        public static List <DTO.ReservationsDTO> ListReservations()
        {
            var db           = new RentCDataBaseEntities();
            var reservations = db.Reservations.ToList();

            var cars                 = Persistence.CarsRepository.ListCars();
            var statuses             = RentC.Persistence.ReservationStatutesRepository.ListStatuses();
            var canceledReservations = statuses.FindAll(x => x.Name == "CANCELED").ToList();
            var result               = reservations.Where(p => !canceledReservations.Any(x => x.ReservStatsID == p.ReservStatsID)).ToList();

            var reservationDTO = ConvertToDTO(result);

            return(reservationDTO);
        }
Example #10
0
        public static DTO.CarsDTO FindCarIdByPlate(string plate)
        {
            var db  = new RentCDataBaseEntities();
            var car = db.Cars.Where(p => p.Plate == plate).FirstOrDefault();

            if (car == null)
            {
                return(null);
            }
            else
            {
                var carDTO = new DTO.CarsDTO();
                carDTO.Plate = car.Plate;
                carDTO.CarID = car.CarID;
                return(carDTO);
            }
        }