コード例 #1
0
ファイル: Seeder.cs プロジェクト: vikshab/Visual-Studio
        public static void SeedRentals()
        {
            // Read the contents of the file
            string s = File.ReadAllText("..\\..\\..\\MovieRentals\\App_Data\\rentals.json");

            // Parse the contents using JSON.NET
            JArray data = (JArray)JsonConvert.DeserializeObject(s);

            RentalRepository repository = new RentalRepository();
            int indexNumber = 1;

            // Process the data
            foreach (JToken token in data)
            {
                Rental r = new Rental();
                r.Id = indexNumber;
                r.CheckoutDate = token["checkout_date"].Value<string>();
                r.ReturnedDate = token["returned_date"].Value<string>();
                r.RentalTime = token["rental_time"].Value<string>();
                r.Cost = token["cost"].Value<string>();
                r.Total = token["total"].Value<string>();
                r.CustomerId = token["customer_id"].Value<int>();
                r.MovieId = token["movie_id"].Value<int>();
                repository.Add(r);
                indexNumber++;
            }
        }
コード例 #2
0
        public void Add(Rental rental)
        {
            db.Open();
            try
            {
                SqlCommand command = new SqlCommand(
                    "insert into rentals (id, CheckoutDate, ReturnedDate, Cost, Total, CustomerId, MovieId) values (@id, @checkout_date, @returned_date, @cost, @total, @customer_id, @movie_id)",
                    this.db);
                command.Parameters.AddWithValue("@id", rental.Id);
                command.Parameters.AddWithValue("@checkout_date", rental.CheckoutDate);
                command.Parameters.AddWithValue("@returned_date", rental.ReturnedDate);
                command.Parameters.AddWithValue("@cost", rental.Cost);
                command.Parameters.AddWithValue("@total", rental.Total);
                command.Parameters.AddWithValue("@customer_id", rental.CustomerId);
                command.Parameters.AddWithValue("@movie_id", rental.MovieId);

                command.ExecuteNonQuery();
            }
            finally
            {
                db.Close();
            }
        }
コード例 #3
0
 public Rental Update(Rental rental)
 {
     throw new NotImplementedException();
 }