public void SaveCustomer(Customer customer) { // If its a new Customer, just attach it to the DataContext if (customer.CustomerID == 0) customersTable.InsertOnSubmit(customer); else if (customersTable.GetOriginalEntityState(customer) == null) { // Were updating an existing Customer, but its not attached to the // this data context, so attach it and detect the changes customersTable.Attach(customer); customersTable.Context.Refresh(RefreshMode.KeepCurrentValues, customer); } customersTable.Context.SubmitChanges(); }
public ActionResult Edit(Customer customer) { TryUpdateModel(customer); if (ModelState.IsValid) { customerRepository.SaveCustomer(customer); TempData["message"] = customer.Firstname + " " + customer.Surname + " has been saved!"; Response.Redirect("/Customer/Display?id=" + customer.CustomerID); emailCustomer.SendCustEmail(customer.Firstname,customer.Email, customer.CustomerID); Session["CustID"] = customer.CustomerID; Session["EmailAddr"] = customer.Email; return RedirectToAction("Index"); } else // validation error - redisplay same view return View(customer); }
public ActionResult Login(Customer customer) { string email = customer.Email; string password = customer.LoginPassword; //var customer_find = customerRepository.Customers.First(x => x.Email == email); //Customer c_find = customerRepository.Customers.First(x => x.Email == customer.Email); int test = customerRepository.FindCustomer(email, password); string emailAddr = customerRepository.GetCustomerEmail(test); if (test > 0) { Session["CustID"] = test; Session["EmailAddr"] = emailAddr; Response.Redirect("/Cart/Index"); } return View(); }
public void DeleteCustomer(Customer customer) { customersTable.DeleteOnSubmit(customer); customersTable.Context.SubmitChanges(); }