public ActionResult ModelBinding()
 {
     var customer = new Customer()
         {
             Addresses = new List<Address>
                 {
                     new Address {AddressId = 1, Number = "1", Street = "one"},
                     new Address {AddressId = 2, Number = "2", Street = "two"}
                 }
         };
     return View(customer);
 }
 public CustomerRepresentation Get(int customerId)
 {
     //customerRepository.GetById(customerId)
     var customer = new Customer
         {
             CustomerId = customerId,
             Title = "title",
             FirstName = "first Name",
             Surname = "surname"
         };
     return CustomerRepresentation.FromResource(customer);
 }
Example #3
0
 public static void SaveCustomer(Customer customer)
 {
     using (var dbContext = new CrmEntities()){
         if(customer.ID > 0){
             if(dbContext.Customer.Any(c => c.Tel == customer.Tel && c.ID != customer.ID))
                 throw new Exception("已存在此电话的客户!");
             if(dbContext.Customer.Any(c => c.Number == customer.Number && c.ID != customer.ID))
                 throw new Exception("已存在此编号的客户!");
         }
         else{
             if(dbContext.Customer.Any(c => c.Tel == customer.Tel))
                 throw new Exception("已存在此电话的客户!");
             if(dbContext.Customer.Any(c => c.Number == customer.Number))
                 throw new Exception("已存在此编号的客户!");
             dbContext.Customer.Add(customer);
         }
         dbContext.SaveChanges();
     }
 }
        public ActionResult ModelBinding(Customer customer)
        {
            var test = customer.FirstName;

            return View(customer);
        }
 public ActionResult Index(Customer customer)
 {
     return View(customer);
 }