protected void btnDatabindRepository_Click(object sender, EventArgs e)
 {
     using (var repository = new CustomerRepository())
     {
         customersView.DataSource = repository.GetAll();
         customersView.DataBind();
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            using (var repository = new CustomerRepository())
            {
                //Load it
                var customers = repository.GetAll();

                //Map it to view model
                var customerViewModels = customers.Select(c => new CustomerViewModel
                {
                    CustomerId = c.CustomerId,
                    Address = c.Address,
                    City = c.City,
                    State = c.State,
                    FirstName = c.FirstName,
                    LastName = c.LastName
                }).ToArray();

                //Bind it. BAM
                GridView1.DataSource = customerViewModels;
                GridView1.DataBind();
            }
        }
 private IEnumerable<SelectListItem> GetAllCustomers()
 {
     using (CustomerRepository repository = new CustomerRepository())
     {
         return repository.GetAll().Select(x => new SelectListItem
         {
             Text = string.Format("{0} {1}", x.FirstName, x.LastName),
             Value = x.CustomerId.ToString()
         }).ToList();
     }
 }
        public void TestCustomerLoading()
        {
            var customer = _dbContext.Customers.Where(o => o.CustomerId == 1);

            ICustomerRepository repository = new CustomerRepository(_dbContext);
            Debug.WriteLine(customer.Single().FirstName);

            var customers = repository.GetAll();
            //Debug.Assert(customers.Count == 0);
            Customer customer2 = new Customer(_validator) { FirstName = "Test", City = "bethlehem" };
            repository.Create(customer2);
            repository.Save();
        }
        public void ShowSmartFieldUpating()
        {
            ICustomerRepository repository = new CustomerRepository(_dbContext);
            var customers = repository.GetAll();
            Debug.Assert(customers.Count() == 0);

            Customer customer = new Customer(_validator) { FirstName = "Test", City = "bethlehem" };
            repository.Create(customer);
            repository.Save();
            customer.Address = "1 main st" + DateTime.Now.ToString();
            customer.City = customer.City;
            repository.Update(customer);
            repository.Save();
        }