Пример #1
0
        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 Delete(int id, FormCollection collection)
        {
            try
            {
                Customer movie = new Customer();
                CustomerRepository r = new CustomerRepository();
                r.Remove(id);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        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();
            }
        }
 // GET: Customer/Edit/5
 public ActionResult Edit(int id)
 {
     CustomerRepository r = new CustomerRepository();
     Customer customers = r.Find(id);
     return View(customers);
 }
 // GET: Customer/CustDetail/5
 public ActionResult CustDetail(int id = 1)
 {
     CustomerRepository r = new CustomerRepository();
     Customer customers = r.Find(id);
     return View(customers);
 }
 // GET: Customer
 public ActionResult Index()
 {
     CustomerRepository r = new CustomerRepository();
     List<Customer> customers = r.GetAll();
     return View(customers);
 }
 // 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();
 }