public ActionResult CustomerAccount(Customer customer) { HttpCookie aCookie = Request.Cookies["UserSettings"]; if (aCookie == default(HttpCookie)) { return RedirectToAction("Index"); } else { if (aCookie["Role"] == "Customer") { RestaurantDatabaseEntities db = new RestaurantDatabaseEntities(); string currentEmail = aCookie["Email"]; Customer myCustomer = db.Customers.FirstOrDefault(x => x.customerEmail == currentEmail); if (myCustomer == default(Customer)) { return RedirectToAction("CustomerAccount"); } else { Customer checkEmail = db.Customers.FirstOrDefault(x => x.customerEmail == customer.customerEmail); if (checkEmail == default(Customer) || checkEmail.customerID == myCustomer.customerID) { myCustomer.customerEmail = customer.customerEmail; myCustomer.customerAddress = customer.customerAddress; myCustomer.customerPhone = customer.customerPhone; aCookie["Email"] = myCustomer.customerEmail; Response.SetCookie(aCookie); db.Entry(myCustomer).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("CustomerAccount/4"); } else { return RedirectToAction("CustomerAccount/1"); } } } else { return RedirectToAction("Index"); } } }
public ActionResult CreateCustomerAccount(Customer customer) { HttpCookie aCookie = Request.Cookies["UserSettings"]; if (aCookie == default(HttpCookie)) { RestaurantDatabaseEntities db = new RestaurantDatabaseEntities(); if (customer.customerEmail == null || customer.customerAddress == null || customer.customerPass == null || customer.customerPhone == null) { return RedirectToAction("CreateCustomerAccount/2"); } else { if (ModelState.IsValid) { Customer prevCustomer = db.Customers.FirstOrDefault(x => x.customerEmail == customer.customerEmail); if (prevCustomer == default(Customer)) { using (MD5 hash = MD5.Create()) { customer.customerPass = GetMd5Hash(hash, customer.customerPass); } db.Customers.Add(customer); db.SaveChanges(); customer.customerID = db.Customers.First(x => x.customerEmail == customer.customerEmail).customerID; HttpCookie myCookie = new HttpCookie("UserSettings"); myCookie.Values["Email"] = customer.customerEmail; myCookie.Values["Role"] = "Customer"; myCookie.Values["ID"] = customer.customerID.ToString(); Response.SetCookie(myCookie); return RedirectToAction("CustomerAccount"); } else { return RedirectToAction("CreateCustomerAccount/1"); } } else { return RedirectToAction("CreateCustomerAccount/2"); } } } else { return RedirectToAction("Index"); } }