public static void SeedCustomers() { // Read the contents of the file string s = File.ReadAllText("..\\..\\..\\MovieRentals\\App_Data\\customers.json"); // Parse the contents using JSON.NET JArray data = (JArray)JsonConvert.DeserializeObject(s); CustomerRepository repository = new CustomerRepository(); // Process the data foreach (JToken token in data) { Customer c = new Customer(); c.Id = token["id"].Value<int>(); c.Name = token["name"].Value<string>(); c.RegisteredAt = token["registered_at"].Value<string>(); c.Address = token["address"].Value<string>(); c.City = token["city"].Value<string>(); c.State = token["state"].Value<string>(); c.PostalCode = token["postal_code"].Value<string>(); c.Phone = token["phone"].Value<string>(); c.AccountCredit = token["account_credit"].Value<decimal>(); repository.Add(c); } }
// GET api/customers/5 public Customer Get(int id) { CustomerRepository r = new CustomerRepository(); return r.Find(id); }
// GET api/customers public IEnumerable<Customer> Get() { CustomerRepository r = new CustomerRepository(); return r.GetAll(); }