public ActionResult Create(Customer_Info customer_info) { if (ModelState.IsValid) { System.Collections.Specialized.NameValueCollection postedValues = Request.Form; customer_info.Address.City = postedValues["Address.City"]; customer_info.Address.Country = postedValues["Address.Country"]; customer_info.Address.House_number = postedValues["Address.House_number"]; customer_info.Address.Postcode = postedValues["Address.Postcode"]; customer_info.Address.Province = postedValues["Address.Province"]; customer_info.Address.Street_name = postedValues["Address.Street_name"]; customer_info.Address.Street_number = postedValues["Address.Street_number"]; repo.InsertCustomerInfo(customer_info); repo.Save(); return RedirectToAction("Index"); } return View(customer_info); }
public void UpdateCustomerInfo(Customer_Info customerInfo) { context.Entry(customerInfo).State = EntityState.Modified; }
public void InsertCustomerInfo(Customer_Info customerInfo) { int id = context.Database.SqlQuery<int>("GetCustomerInfoMaxID").Single() + 1; context.Customer_Info.Add(customerInfo); }
public ActionResult Edit(Customer_Info customer_info) { if (ModelState.IsValid) { try { System.Collections.Specialized.NameValueCollection postedValues = Request.Form; Address addre = new Address(); Customer_Info oldCustomer = (Customer_Info)Session["customer"]; customer_info.Address_id = oldCustomer.Address_id; customer_info.Customer_id = oldCustomer.Customer_id; customer_info.Address = oldCustomer.Address; customer_info.Address.City = postedValues["Address.City"]; customer_info.Address.Country = postedValues["Address.Country"]; customer_info.Address.House_number = postedValues["Address.House_number"]; customer_info.Address.Postcode = postedValues["Address.Postcode"]; customer_info.Address.Province = postedValues["Address.Province"]; customer_info.Address.Street_name = postedValues["Address.Street_name"]; customer_info.Address.Street_number = postedValues["Address.Street_number"]; repo.UpdateAddress(customer_info.Address); repo.UpdateCustomerInfo(customer_info); repo.Save(); return RedirectToAction("Index"); } catch (Exception ex) { //get the innermost exception while (ex.InnerException != null) { ex = ex.InnerException; } ModelState.AddModelError("", "error on create: " + ex.GetBaseException().Message); } } return View(customer_info); }