Пример #1
0
        public ReservationInfo GetReservationByBrand(ReservationRequestByBrand request)
        {
            if (request.LicenseKey != "SuperSecret123")
            {
                throw new WebFaultException <string>(
                          "Wrong license key",
                          HttpStatusCode.Forbidden);
            }
            else
            {
                Reservation reservation = new Reservation();

                string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

                using (SqlConnection con = new SqlConnection(cs))
                {
                    SqlCommand cmd = new SqlCommand("spGetReservationByBrand", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter parameterId = new SqlParameter();
                    parameterId.ParameterName = "@Brand";
                    parameterId.Value         = request.CarBrand;

                    cmd.Parameters.Add(parameterId);
                    con.Open();
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        reservation.Car.Model     = reader["Model"].ToString();
                        reservation.Car.Regnumber = reader["Regnumber"].ToString();
                        reservation.StartDate     = Convert.ToDateTime(reader["StartDate"]);
                        reservation.EndDate       = Convert.ToDateTime(reader["EndDate"]);
                        reservation.CustomerId    = Convert.ToInt32(reader["CustomerId"]);
                        reservation.Returned      = Convert.ToBoolean(reader["Returned"]);
                    }
                    reservation.Customer = customerMethods.GetCustomerById(reservation.CustomerId);
                }
                return(new ReservationInfo(reservation));
            }
        }
 public Customer GetCustomerById(int id)
 {
     return(castomerMethods.GetCustomerById(id));
 }