private bool ValidateUniquePhoneEmail(FoodkartModelContainer foodkartModelContainer, Customer customer, long custId) { List <Customer> custList = (from cust in foodkartModelContainer.Customers where cust.CustId != custId select cust).ToList(); foreach (Customer c in custList) { if (c.CustPhone == customer.CustPhone || c.CustEmail == customer.CustEmail) { return(false); } } return(true); }
public ActionResult CustomerProfile(Customer customer, FormCollection form) { try { FoodkartModelContainer foodkartModelContainer = new FoodkartModelContainer(); long custId = long.Parse(form["CustId"].ToString()); Customer currCust = foodkartModelContainer.Customers.Find(custId); bool validate = ValidateUniquePhoneEmail(foodkartModelContainer, customer, custId); if (!validate) { ViewBag.Status = "KeyViolation"; } else { List <Customer> custList = (from cust in foodkartModelContainer.Customers where cust.CustId == custId select cust).ToList(); foreach (Customer c in custList) { c.CustFName = customer.CustFName; c.CustLName = customer.CustLName; c.CustPhone = customer.CustPhone; c.CustEmail = customer.CustEmail; } if (ModelState.IsValid) { foodkartModelContainer.SaveChanges(); } } Session["CustModel"] = currCust; Session["CustFName"] = currCust.CustFName; return(View(currCust)); } catch (Exception e) { string exceptionMessage = DateTime.Now + " ActionResult : " + Request.RequestContext.RouteData.Values["action"].ToString() + "Exception : " + e.Message.ToString(); AuthController.WriteExceptionToFile(exceptionMessage, out string fileExceptionMessage); return(Content(exceptionMessage + "\n" + fileExceptionMessage)); } }
public ActionResult Index(Customer customer, FormCollection forms) { try { FoodkartModelContainer foodContext = new FoodkartModelContainer(); IList <Customer> CustList = (from cust in foodContext.Customers where cust.CustEmail == customer.CustEmail || cust.CustPhone == customer.CustPhone select cust).ToList(); long custId = 0; foreach (Customer cust in CustList) { custId = cust.CustId; } Customer custFound = foodContext.Customers.Find(custId); bool auth = forms["userReg"].ToString() != "reg"; if (auth) //login { if (custFound != null && custFound.CustPassword != customer.CustPassword) { customer.CustEmail = "BadCredentials"; return(View(customer)); } else if (custFound != null) { return(RedirectToAction("CustomerHome", "Customer", custFound)); } else { customer.CustEmail = "NotRegistered"; return(View(customer)); } } else // register { if (customer.CustEmail == null || customer.CustFName == null || customer.CustLName == null || customer.CustPhone == null || customer.CustPassword != forms["ConfirmPassword"].ToString()) { customer.CustEmail = "CustInvalid"; return(View("Index", customer)); } else if (custFound == null) { foodContext.Customers.Add(customer); if (foodContext.SaveChanges() > 0) { customer.CustEmail = "CustRegistered"; return(View("Index", customer)); } else { return(View(customer)); } } else { customer.CustEmail = "CustExists"; return(View("Index", customer)); } } } catch (Exception e) { string exceptionMessage = DateTime.Now + " ActionResult : " + Request.RequestContext.RouteData.Values["action"].ToString() + "Exception : " + e.Message.ToString(); WriteExceptionToFile(exceptionMessage, out string fileExceptionMessage); return(Content(exceptionMessage + "\n" + fileExceptionMessage)); } }
public ActionResult AdminIndex(Admin admin, FormCollection forms) { try { FoodkartModelContainer foodContext = new FoodkartModelContainer(); IList <Admin> AdminList = (from adm in foodContext.Admins where adm.AdminUsername == admin.AdminUsername select adm).ToList(); long adminId = 0; foreach (Admin adm in AdminList) { adminId = adm.AdminId; } Admin adminFound = foodContext.Admins.Find(adminId); bool auth = forms["userReg"].ToString() != "reg"; if (auth) // login { if (adminFound != null && adminFound.AdminPassword != admin.AdminPassword) { admin.AdminUsername = "******"; return(View(admin)); } else if (adminFound != null) { return(RedirectToAction("AdminHome", "Admin", adminFound)); } else { admin.AdminUsername = "******"; return(View(admin)); } } else //register { if (admin.AdminUsername == null || admin.AdminFName == null || admin.AdminLName == null || admin.AdminPhone == null || admin.AdminPassword != forms["ConfirmPassword"].ToString()) { admin.AdminUsername = "******"; return(View("AdminIndex", admin)); } else if (adminFound == null) { foodContext.Admins.Add(admin); if (foodContext.SaveChanges() > 0) { admin.AdminUsername = "******"; return(View("AdminIndex", admin)); } else { return(View(admin)); } } else { admin.AdminUsername = "******"; return(View("AdminIndex", admin)); } } } catch (Exception e) { string exceptionMessage = DateTime.Now + " ActionResult : " + Request.RequestContext.RouteData.Values["action"].ToString() + "Exception : " + e.Message.ToString(); WriteExceptionToFile(exceptionMessage, out string fileExceptionMessage); return(Content(exceptionMessage + "\n" + fileExceptionMessage)); } }