Beispiel #1
0
 public void Delete(Hotel entity)
 {
     using (SqlCommand cmd =
                new SqlCommand("DELETE FROM Hotels WHERE HotelId = @HotelId"))
     {
         cmd.Parameters.AddWithValue("HotelId", entity.HotelId);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
Beispiel #2
0
 public void Add(Hotel entity)
 {
     using (SqlCommand cmd = new SqlCommand("INSERT INTO Hotels (HotelName,FeePerNight,Stars) " +
                                            "VALUES(@HotelName,@FeePerNight,@Stars)"))
     {
         cmd.Parameters.AddWithValue("HotelName", entity.HotelName);
         cmd.Parameters.AddWithValue("FeePerNight", entity.FeePerNight);
         cmd.Parameters.AddWithValue("Stars", entity.Stars);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
Beispiel #3
0
 public void Update(Hotel entity)
 {
     using (SqlCommand cmd = new SqlCommand("UPDATE Hotels set HotelName = @HotelName, FeePerNight=@FeePerNight, Stars=@Stars WHERE HotelId = @HotelId"))
     {
         cmd.Parameters.AddWithValue("@HotelId", entity.HotelId);
         cmd.Parameters.AddWithValue("@HotelName", entity.HotelName);
         cmd.Parameters.AddWithValue("@FeePerNight", entity.FeePerNight);
         cmd.Parameters.AddWithValue("@Stars", entity.Stars);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
Beispiel #4
0
        public List <Hotel> GetAll(Expression <Func <Hotel, bool> > filter = null)
        {
            List <Hotel> hotelList = new List <Hotel>();
            SqlCommand   cmd       = new SqlCommand("Select * from Hotels");

            SqlDataReader reader = VTYS.SqlExecuteReader(cmd);

            while (reader.Read())
            {
                Hotel hotel = new Hotel
                {
                    HotelId     = Convert.ToInt32(reader[0]),
                    HotelName   = reader[1].ToString(),
                    Stars       = Convert.ToInt32(reader[2]),
                    FeePerNight = Convert.ToDecimal(reader[3].ToString())
                };

                hotelList.Add(hotel);
            }

            return(filter == null ? hotelList : hotelList.Where(filter.Compile()).ToList());
        }