public ActionResult AdminHome(List <Food> FoodList, FormCollection forms) { try { bool menuAvailable = bool.Parse(forms["MenuAvailable"].ToString()); long menuId = long.Parse(Session["AdminMenuId"].ToString()); List <Menu> MenuList = (from menu in foodContext.Menus where menu.MenuAvailable == menuAvailable where menu.MenuId == menuId select menu).ToList(); foreach (Menu m in MenuList) { m.MenuAvailable = !menuAvailable; } foodContext.SaveChanges(); Menu menuFound = foodContext.Menus.Find(Session["AdminMenuId"]); FoodList = (from food in foodContext.Foods where menuFound.MenuId == food.FoodMenuId && food.FoodQty < 50 orderby 1 select food).ToList(); return(View(FoodList)); } catch (Exception e) { string exceptionMessage = DateTime.Now + " ActionResult : " + Request.RequestContext.RouteData.Values["action"].ToString() + "Exception : " + e.Message.ToString(); AdminAuthController.WriteExceptionToFile(exceptionMessage, out string fileExceptionMessage); return(Content(exceptionMessage + "\n" + fileExceptionMessage)); } }
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 AddToCart(FormCollection forms) { try { Cart cart = new Cart { CartCustId = long.Parse(Session["CustId"].ToString()) }; foodContext.Carts.Add(cart); foodContext.SaveChanges(); List <Cart> CartList = (from cartList in foodContext.Carts select cartList).ToList(); CartItem cartItem = new CartItem { CartItemCartId = CartList.Last().CartId, CartAddDate = DateTime.Now, CartItemQty = long.Parse(forms["FoodQty"].ToString()), CartItemFoodId = long.Parse(forms["FoodId"].ToString()) }; foodContext.CartItems.Add(cartItem); foodContext.SaveChanges(); Customer customer = new Customer { CustId = long.Parse(Session["CustId"].ToString()), CustFName = Session["CustFName"].ToString(), CustPassword = "******" }; ViewBag.Status = "ItemAdded"; ViewBag.Quantity = long.Parse(forms["FoodQty"].ToString()); return(View(foodContext.Foods.Find(long.Parse(forms["FoodId"].ToString())))); } 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)); } }