public static void SeedCustomers() { // Read the contents of the file string s = File.ReadAllText("..\\..\\..\\AdaMovieStoreSample\\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.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); } }
public ActionResult Create(FormCollection collection) { try { Customer customer = new Customer(); customer.Name = collection.GetValue("Name").AttemptedValue.ToString(); customer.RegisteredAt = collection.GetValue("RegisteredAt").AttemptedValue.ToString(); customer.Address = collection.GetValue("Address").AttemptedValue.ToString(); customer.City= collection.GetValue("City").AttemptedValue.ToString(); customer.State = collection.GetValue("State").AttemptedValue.ToString(); customer.PostalCode = collection.GetValue("PostalCode").AttemptedValue.ToString(); customer.Phone = collection.GetValue("Phone").AttemptedValue.ToString(); customer.AccountCredit = decimal.Parse(collection.GetValue("AccountCredit").AttemptedValue.ToString()); CustomerRepository r = new CustomerRepository(); r.Add(customer); return RedirectToAction("Index"); } catch { return View(); } }