Beispiel #1
0
        public string AddVehicle(Vehicle vehicle)
        {
            string query = "insert into Vehicle(Id,UserId,Model,Number,VehicleTypeId,IsActive) values(@Id,@UserId,@Model,@Number,@vehicleTypeId,@IsActive)";

            vehicle.Id       = Guid.NewGuid().ToString();
            vehicle.IsActive = true;

            string          vehicleTypeQuery           = "select * from VehicleType where Name='Four-Wheeler'";
            ExtensionObject vehicleTypeExtensionObject = new ExtensionObject()
            {
                Query            = vehicleTypeQuery,
                ConnectionString = connectionString
            };

            string            VehicleTypeId = vehicleTypeExtensionObject.GetItem <VehicleType>().Id;
            DynamicParameters parameters    = new DynamicParameters();

            parameters.Add("Id", vehicle.Id);
            parameters.Add("UserId", vehicle.UserId);
            parameters.Add("Model", vehicle.Model);
            parameters.Add("Number", vehicle.Number);
            parameters.Add("VehicleTypeId", VehicleTypeId);
            parameters.Add("IsActive", vehicle.IsActive);
            ExtensionObject extensionObject = new ExtensionObject()
            {
                Query            = query,
                ConnectionString = connectionString
            };

            extensionObject.AddOrUpdateItem <Vehicle>(parameters);

            return(vehicle.Id);
        }
Beispiel #2
0
        public Status GetStatus(string type, string value)
        {
            string          query           = "select * from Status where Type='" + type + "' and Value='" + value + "'";
            ExtensionObject extensionObject = new ExtensionObject()
            {
                Query            = query,
                ConnectionString = connectionString
            };

            return(extensionObject.GetItem <Status>());
        }
        public User GetUserByMail(string email)
        {
            string          query           = "select * from [User] where Email='" + email + "'";
            ExtensionObject extensionObject = new ExtensionObject()
            {
                Query            = query,
                ConnectionString = connectionString
            };

            return(extensionObject.GetItem <User>());
        }
        public User GetUser(string id)
        {
            string          query           = "select * from [User] where Id='" + id + "'";
            ExtensionObject extensionObject = new ExtensionObject()
            {
                Query            = query,
                ConnectionString = connectionString
            };

            return(extensionObject.GetItem <User>());
        }
Beispiel #5
0
        public Vehicle GetVehicleById(string vehicleId)
        {
            string          query           = "select * from Vehicle where Id='" + vehicleId + "'";
            ExtensionObject extensionObject = new ExtensionObject()
            {
                Query            = query,
                ConnectionString = connectionString
            };

            return(extensionObject.GetItem <Vehicle>());
        }
        public bool UpdateRide(Ride ride)
        {
            if (ride.Status.Value == "Cancelled")
            {
                string          statusQuery           = "select * from Status where Type='Ride' and Value='Cancelled'";
                ExtensionObject statusExtensionObject = new ExtensionObject()
                {
                    Query            = statusQuery,
                    ConnectionString = connectionString
                };

                string          rideStatusId    = statusExtensionObject.GetItem <Status>().Id;
                string          query           = "update Ride set StatusId=@StatusId where Id=@Id";
                ExtensionObject extensionObject = new ExtensionObject()
                {
                    Query            = query,
                    ConnectionString = connectionString
                };
                DynamicParameters parameters = new DynamicParameters();
                parameters.Add("Id", ride.Id);
                parameters.Add("StatusId", rideStatusId);
                if (extensionObject.AddOrUpdateItem <Ride>(parameters))
                {
                    IBookingService bookingService = new BookingService(configuration);
                    return(bookingService.CancelAllBookingsByRideId(ride.Id));
                }
                return(false);
            }
            else
            {
                string          query                 = "update Ride set AutoApproveRide=@AutoApproveRide, VehicleId=@VehicleId, StatusId=@statusId where Id=@Id";
                string          statusQuery           = "select * from Status where Type='Ride' and Value='" + ride.Status.Value + "'";
                ExtensionObject statusExtensionObject = new ExtensionObject()
                {
                    Query            = statusQuery,
                    ConnectionString = connectionString
                };
                string statusId = statusExtensionObject.GetItem <Status>().Id;

                DynamicParameters parameters = new DynamicParameters();
                parameters.Add("Id", ride.Id);
                parameters.Add("AutoApproveRide", ride.AutoApproveRide);
                parameters.Add("VehicleId", ride.Vehicle.Id);
                parameters.Add("StatusId", statusId);
                ExtensionObject extensionObject = new ExtensionObject()
                {
                    Query            = query,
                    ConnectionString = connectionString
                };
                return(extensionObject.AddOrUpdateItem <Booking>(parameters));
            }
        }
        public int AddBooking(Booking booking)
        {
            IRideService rideService = new RideService(configuration);
            Ride         ride        = rideService.GetRideById(booking.Ride.Id);

            ride.Id = booking.Ride.Id;
            int availableSeats = AvailableSeats(ride, booking.PickUp, booking.Drop);

            if (availableSeats >= booking.NumberOfSeatsBooked)
            {
                string query = "insert into Booking(Id,RideId,PickUp,[Drop],BookedBy,Price,StatusId,BookingTime,NumberOfSeatsBooked)" +
                               " values(@Id,@RideId,@PickUp,@Drop,@BookedBy,@Price,@StatusId,@BookingTime,@NumberOfSeatsBooked)";
                booking.Id = Guid.NewGuid().ToString();
                string          statusQuery           = "select * from Status where Type='Booking' and Value='Pending'";
                ExtensionObject statusExtensionObject = new ExtensionObject()
                {
                    Query            = statusQuery,
                    ConnectionString = connectionString
                };

                string            statusId   = statusExtensionObject.GetItem <Status>().Id;
                DynamicParameters parameters = new DynamicParameters();
                parameters.Add("Id", booking.Id);
                parameters.Add("RideId", booking.Ride.Id);
                parameters.Add("PickUp", booking.PickUp);
                parameters.Add("Drop", booking.Drop);
                parameters.Add("BookedBy", booking.BookedBy.Id);
                parameters.Add("Price", booking.Price);
                parameters.Add("StatusId", statusId);
                parameters.Add("BookingTime", booking.BookingTime);
                parameters.Add("NumberOfSeatsBooked", booking.NumberOfSeatsBooked);
                ExtensionObject extensionObject = new ExtensionObject()
                {
                    Query            = query,
                    ConnectionString = connectionString
                };
                if (extensionObject.AddOrUpdateItem <Booking>(parameters))
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                return(-1);
            }
        }
        public bool IsValidUser(string email, string password)
        {
            string          query           = "select * from [User] where Email='" + email + "' and Password='******'";
            ExtensionObject extensionObject = new ExtensionObject()
            {
                Query            = query,
                ConnectionString = connectionString
            };
            User user = extensionObject.GetItem <User>();

            if (user == null)
            {
                return(false);
            }
            return(true);
        }
        public string AddRide(Ride ride)
        {
            string query = "insert into Ride(Id,PublisherId,PickUp,[Drop],StartDate,NumberOfSeats,Price,VehicleId,AutoApproveRide,StatusId) " +
                           "values(@Id,@PublisherId,@PickUp,@Drop,@StartDate,@NumberOfSeats,@Price,@VehicleId,@AutoApproveRide,@Status)";
            DynamicParameters parameters = new DynamicParameters();

            ride.Id = Guid.NewGuid().ToString();

            string          statusQuery           = "select * from Status where Type='Ride' and Value='Not Started'";
            ExtensionObject statusExtensionObject = new ExtensionObject()
            {
                Query            = statusQuery,
                ConnectionString = connectionString
            };

            string rideStatusId = statusExtensionObject.GetItem <Status>().Id;

            ride.AutoApproveRide = false;

            parameters.Add("Id", ride.Id);
            parameters.Add("PublisherId", ride.Publisher.Id);
            parameters.Add("PickUp", ride.PickUp.ToLower());
            parameters.Add("Drop", ride.Drop.ToLower());
            parameters.Add("StartDate", ride.StartDate);
            parameters.Add("NumberOfSeats", ride.NumberOfSeats);
            //parameters.Add("AvailableSeats", ride.AvailableSeats);
            parameters.Add("Price", ride.Price);
            parameters.Add("VehicleId", ride.Vehicle.Id);
            parameters.Add("AutoApproveRide", ride.AutoApproveRide);
            parameters.Add("Status", rideStatusId);
            ExtensionObject extensionObject = new ExtensionObject()
            {
                Query            = query,
                ConnectionString = connectionString
            };

            if (extensionObject.AddOrUpdateItem <Ride>(parameters))
            {
                return(ride.Id);
            }
            else
            {
                return(null);
            }
        }
        public List <Ride> FindRide(string from, string to)
        {
            from = from.ToLower();
            to   = to.ToLower();
            List <Ride> requiredRides  = new List <Ride>();
            int         availableSeats = 0;

            IBookingService  bookingService  = new BookingService(configuration);
            IViaPointService viaPointService = new ViaPointService(configuration);

            string          query           = "select * from Ride";
            ExtensionObject extensionObject = new ExtensionObject()
            {
                Query            = query,
                ConnectionString = connectionString
            };

            List <Ride> rides = extensionObject.GetAllItems <Ride>();

            foreach (Ride ride in rides)
            {
                availableSeats = bookingService.AvailableSeats(ride, from, to);
                if (availableSeats > 0)
                {
                    ride.AvailableSeats = availableSeats;
                    query = "select id,name,phoneNumber from [User] where Id= (select publisherId from Ride where Id='" + ride.Id + "')";
                    ExtensionObject publisherExtensionObject = new ExtensionObject()
                    {
                        Query            = query,
                        ConnectionString = connectionString
                    };

                    ride.Publisher = publisherExtensionObject.GetItem <User>();
                    query          = "select value from Status where Id=(select statusId from Ride where Id='" + ride.Id + "')";
                    ExtensionObject statusExtensionObject = new ExtensionObject()
                    {
                        Query            = query,
                        ConnectionString = connectionString
                    };
                    ride.Status = statusExtensionObject.GetItem <Status>();
                    requiredRides.Add(ride);
                }
            }
            return(requiredRides);
        }
        public bool IsExistingUser(string email)
        {
            string          query           = "select * from [User] where Email='" + email + "'";
            ExtensionObject extensionObject = new ExtensionObject()
            {
                Query            = query,
                ConnectionString = connectionString
            };
            User user = extensionObject.GetItem <User>();

            if (user == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        public bool CancelAllBookingsByRideId(string rideId)
        {
            string          statusQuery           = "select * from Status where Type='Booking' and Value='Cancelled'";
            ExtensionObject statusExtensionObject = new ExtensionObject()
            {
                Query            = statusQuery,
                ConnectionString = connectionString
            };
            string statusId = statusExtensionObject.GetItem <Status>().Id;

            string            query      = "update Booking set StatusId=@statusId where RideId=@RideId";
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("RideId", rideId);
            parameters.Add("StatusId", statusId);
            ExtensionObject extensionObject = new ExtensionObject()
            {
                Query            = query,
                ConnectionString = connectionString
            };

            return(extensionObject.AddOrUpdateItem <Booking>(parameters));
        }
        public int UpdateBooking(Booking booking)
        {
            IRideService rideService = new RideService(configuration);
            Ride         ride        = rideService.GetRideById(booking.Ride.Id);

            ride.Id = booking.Ride.Id;
            int availableSeats = AvailableSeats(ride, booking.PickUp, booking.Drop);

            if (booking.Status.Value == "Rejected")
            {
                string query = "update Booking set PickUp=@PickUp,[Drop]=@Drop" +
                               ",StatusId=@Status,NumberOfSeatsBooked=@NumberOfSeatsBooked where Id=@Id";
                DynamicParameters parameters            = new DynamicParameters();
                string            statusQuery           = "select * from Status where Type='Booking' and Value='" + booking.Status.Value + "'";
                ExtensionObject   statusExtensionObject = new ExtensionObject()
                {
                    Query            = statusQuery,
                    ConnectionString = connectionString
                };
                string statusId = statusExtensionObject.GetItem <Status>().Id;

                parameters.Add("Id", booking.Id);
                parameters.Add("PickUp", booking.PickUp);
                parameters.Add("Drop", booking.Drop);
                parameters.Add("Status", statusId);
                parameters.Add("NumberOfSeatsBooked", booking.NumberOfSeatsBooked);
                ExtensionObject extensionObject = new ExtensionObject()
                {
                    Query            = query,
                    ConnectionString = connectionString
                };
                //new { booking.Id, booking.PickUp, booking.Drop, booking.Status, booking.NumberOfSeatsBooked });
                if (extensionObject.AddOrUpdateItem <Booking>(parameters))
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            else if (booking.Status.Value == "Approved" && availableSeats >= booking.NumberOfSeatsBooked)
            {
                string query = "update Booking set PickUp=@PickUp,[Drop]=@Drop" +
                               ",StatusId=@Status,NumberOfSeatsBooked=@NumberOfSeatsBooked where Id=@Id";
                DynamicParameters parameters            = new DynamicParameters();
                string            statusQuery           = "select * from Status where Type='Booking' and Value='" + booking.Status.Value + "'";
                ExtensionObject   statusExtensionObject = new ExtensionObject()
                {
                    Query            = statusQuery,
                    ConnectionString = connectionString
                };
                string statusId = statusExtensionObject.GetItem <Status>().Id;

                parameters.Add("Id", booking.Id);
                parameters.Add("PickUp", booking.PickUp);
                parameters.Add("Drop", booking.Drop);
                parameters.Add("Status", statusId);
                parameters.Add("NumberOfSeatsBooked", booking.NumberOfSeatsBooked);
                ExtensionObject extensionObject = new ExtensionObject()
                {
                    Query            = query,
                    ConnectionString = connectionString
                };
                //new { booking.Id, booking.PickUp, booking.Drop, booking.Status, booking.NumberOfSeatsBooked });
                if (extensionObject.AddOrUpdateItem <Booking>(parameters))
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            return(-1);
        }