public ActionResult UpdateProfile(AccountDetailsModel m) { AccountDetailsModel model = m; if (m.UserType == "employee") { using (NorthwindConnection db = new NorthwindConnection()) { Employee e = db.Employees.SingleOrDefault(x => x.EmployeeID == m.Employee.EmployeeID); db.Employees.SingleOrDefault(x => x.EmployeeID == m.Employee.EmployeeID).FirstName = m.Employee.FirstName; db.Employees.SingleOrDefault(x => x.EmployeeID == m.Employee.EmployeeID).LastName = m.Employee.LastName; db.SaveChanges(); } } else { using (NorthwindConnection db = new NorthwindConnection()) { db.Customers.SingleOrDefault(x => x.CustomerID == m.Customer.CustomerID).ContactName = m.Customer.ContactName; db.Customers.SingleOrDefault(x => x.CustomerID == m.Customer.CustomerID).ContactTitle = m.Customer.ContactTitle; db.SaveChanges(); } } return View(); }
public ActionResult AccountDetails() { Employee employee; Customer customer; AccountDetailsModel model = new AccountDetailsModel(); string type; if (Session["EmployeeId"] != null) { int id = (int) Session["EmployeeId"]; using (NorthwindConnection db = new NorthwindConnection()) { employee = db.Employees.SingleOrDefault(p => p.EmployeeID == id); } type = "employee"; model.Employee = employee; } else { string id = (string) Session["CustomerId"]; using (NorthwindConnection db = new NorthwindConnection()) { customer = db.Customers.SingleOrDefault(c => c.CustomerID == id); } model.Customer = customer; type = "customer"; } model.UserType = type; return View(model); }