Exemplo n.º 1
0
 public Rental(Customer customer, RentalLocation location, Car car, int daysRented)
 {
     Customer   = customer;
     Car        = car;
     DaysRented = daysRented;
     Location   = location;
 }
        public RentalLocation GetRentalLocation(int id)
        {
            using (var con = GetConnection())
            {
                var cmd = con.CreateCommand();

                cmd.CommandText = "RentalLocations_SelectById";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Id", id);

                using (var reader = cmd.ExecuteReader())
                {
                    if (!reader.Read())
                    {
                        return(null);
                    }

                    RentalLocation location = new RentalLocation();

                    location.Id           = (int)reader["Id"];
                    location.LocationName = (string)reader["LocationName"];
                    location.City         = (string)reader["City"];
                    location.DateCreated  = (DateTime)reader["DateCreated"];

                    object streetValue = reader["Street"];
                    if (streetValue != DBNull.Value)
                    {
                        location.Street = (string)streetValue;
                    }

                    object stateValue = reader["State"];
                    if (stateValue != DBNull.Value)
                    {
                        location.State = (string)stateValue;
                    }

                    object zipValue = reader["Zip"];
                    if (zipValue != DBNull.Value)
                    {
                        location.Zip = (string)zipValue;
                    }

                    object phoneValue = reader["Phone"];
                    if (phoneValue != DBNull.Value)
                    {
                        location.Phone = (string)phoneValue;
                    }

                    object countryValue = reader["Country"];
                    if (countryValue != DBNull.Value)
                    {
                        location.Country = (string)countryValue;
                    }

                    object latValue = reader["Lat"];
                    if (latValue != DBNull.Value)
                    {
                        location.Lat = (double)latValue;
                    }

                    object longValue = reader["Long"];
                    if (longValue != DBNull.Value)
                    {
                        location.Long = (double)longValue;
                    }

                    object dateModifiedValue = reader["DateModified"];
                    if (dateModifiedValue != DBNull.Value)
                    {
                        location.DateModified = (DateTime)dateModifiedValue;
                    }

                    return(location);
                }
            }
        }
        public List <RentalLocation> GetRentalLocations()
        {
            using (var con = GetConnection())
            {
                var cmd = con.CreateCommand();

                cmd.CommandText = "RentalLocations_SelectAll";
                cmd.CommandType = CommandType.StoredProcedure;

                using (var reader = cmd.ExecuteReader())
                {
                    List <RentalLocation> rentalLocations = new List <RentalLocation>();

                    while (reader.Read())
                    {
                        RentalLocation location = new RentalLocation();

                        location.Id           = (int)reader["Id"];
                        location.LocationName = (string)reader["LocationName"];
                        location.City         = (string)reader["City"];
                        location.DateCreated  = (DateTime)reader["DateCreated"];

                        object streetValue = reader["Street"];
                        if (streetValue != DBNull.Value)
                        {
                            location.Street = (string)streetValue;
                        }

                        object stateValue = reader["State"];
                        if (stateValue != DBNull.Value)
                        {
                            location.State = (string)stateValue;
                        }

                        object zipValue = reader["Zip"];
                        if (zipValue != DBNull.Value)
                        {
                            location.Zip = (string)zipValue;
                        }

                        object phoneValue = reader["Phone"];
                        if (phoneValue != DBNull.Value)
                        {
                            location.Phone = (string)phoneValue;
                        }

                        object countryValue = reader["Country"];
                        if (countryValue != DBNull.Value)
                        {
                            location.Country = (string)countryValue;
                        }

                        object latValue = reader["Lat"];
                        if (latValue != DBNull.Value)
                        {
                            location.Lat = (double)latValue;
                        }

                        object longValue = reader["Long"];
                        if (longValue != DBNull.Value)
                        {
                            location.Long = (double)longValue;
                        }

                        object dateModifiedValue = reader["DateModified"];
                        if (dateModifiedValue != DBNull.Value)
                        {
                            location.DateModified = (DateTime)dateModifiedValue;
                        }

                        rentalLocations.Add(location);
                    }

                    return(rentalLocations);
                }
            }
        }
Exemplo n.º 4
0
        public HttpResponseMessage GetRentalLocation(int id)
        {
            RentalLocation location = rentalLocationService.GetRentalLocation(id);

            return(Request.CreateResponse(HttpStatusCode.OK, location));
        }