public ActionResult CheckLogin(User user) { using (FoodOrderEntities db = new FoodOrderEntities()) { var obj = db.Users.Where(a => a.username == user.username && a.password == user.password).FirstOrDefault(); if (obj != null) { if (obj.username == "admin") { Session["UserID"] = obj.userId; Session["Username"] = obj.username; return(RedirectToAction("Index", "Admin")); } else { Session["UserID"] = obj.userId; Session["Username"] = obj.username; return(RedirectToAction("Index", "Home")); } } else { TempData["Message"] = "Invalid Login Credentials"; return(RedirectToAction("Login")); } } }
// GET: Home public ActionResult Index() { using (FoodOrderEntities db = new FoodOrderEntities()) { List <Category> categories = new List <Category>(); var data = db.Categories.Join( db.FoodItems.Where(x => x.isEnabled == true && x.isDeleted == false && x.quantity != "0"), c => c.catId, i => i.catId, (c, i) => new // result selector { c.catId, c.name }).ToList().Distinct(); foreach (var item in data) { Category cat = new Category(); cat.catId = item.catId; cat.name = item.name; categories.Add(cat); } return(View(categories)); } }
IEnumerable <UserOrderViewModel> GetAllUserTransactions() { var viewModels = new List <UserOrderViewModel>(); using (FoodOrderEntities db = new FoodOrderEntities()) { var innerjoin = db.Orders.Join( db.Users.Where(x => x.username != "admin"), o => o.userId, u => u.userId, (o, u) => new { username = u.username, transId = o.transId, totalPrice = o.totalPrice, dateTime = o.dateTime }).ToList(); foreach (var item in innerjoin) { UserOrderViewModel viewModel = new UserOrderViewModel { user = new User(), order = new Order() }; viewModel.user.username = item.username; viewModel.order.transId = item.transId; viewModel.order.dateTime = item.dateTime; viewModel.order.totalPrice = item.totalPrice; viewModels.Add(viewModel); } return(viewModels); } }
IEnumerable <OrderItemViewModel> GetUserOrderDetails(int id) { var viewModels = new List <OrderItemViewModel>(); using (FoodOrderEntities db = new FoodOrderEntities()) { var innerjoin = db.OrderDetails.Where(x => x.orderId == id).Join( db.FoodItems, o => o.itemId, u => u.itemId, (o, u) => new { quantity = o.quantity, name = u.name, price = u.price, description = u.description, image = u.image }).ToList(); foreach (var item in innerjoin) { OrderItemViewModel viewModel = new OrderItemViewModel { orderDetail = new OrderDetail(), foodItem = new FoodItem() }; viewModel.orderDetail.quantity = item.quantity; viewModel.foodItem.name = item.name; viewModel.foodItem.price = item.price; viewModel.foodItem.image = item.image; viewModel.foodItem.description = item.description; viewModels.Add(viewModel); } return(viewModels); } }
public ActionResult SaveItem(FoodItem foodItem) { var fileName = ""; if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Path.GetExtension(file.FileName); foodItem.image = fileName; var path = Path.Combine(Server.MapPath("~/Images/"), fileName); file.SaveAs(path); } } using (FoodOrderEntities db = new FoodOrderEntities()) { foodItem.isEnabled = true; db.FoodItems.Add(foodItem); db.SaveChanges(); return(RedirectToAction("AddItem")); } }
public ActionResult AddCategory() { using (FoodOrderEntities db = new FoodOrderEntities()) { var data = db.Categories.ToList(); return(View(data)); } }
// GET: Admin public ActionResult ViewUsers() { using (FoodOrderEntities db = new FoodOrderEntities()) { var data = db.Users.Where(x => x.username != "admin").ToList(); return(View(data)); } }
public ActionResult SaveCategory(Category category) { using (FoodOrderEntities db = new FoodOrderEntities()) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("AddCategory")); } }
public ActionResult EnableItem(int id) { using (FoodOrderEntities db = new FoodOrderEntities()) { var obj = db.FoodItems.Where(x => x.itemId == id).FirstOrDefault(); obj.isEnabled = true; db.SaveChanges(); return(RedirectToAction("AddItem")); } }
public ActionResult ChangeStatus(int id) { using (FoodOrderEntities db = new FoodOrderEntities()) { var obj = db.Orders.Where(x => x.orderId == id).FirstOrDefault(); obj.status = "Complete"; db.SaveChanges(); return(RedirectToAction("Order")); } }
public ActionResult Index() { using (FoodOrderEntities db = new FoodOrderEntities()) { ViewBag.OrderComplete = db.Orders.Where(x => x.status == "Complete").Count(); ViewBag.OrderPending = db.Orders.Where(x => x.status == "Pending").Count(); ViewBag.FoodItems = db.FoodItems.Where(x => x.isDeleted == false).Count(); ViewBag.Users = db.Users.Where(x => x.username != "admin").Count(); return(View(GetTodayOrders())); } }
public ActionResult ShowCategoryItems(int id) { using (FoodOrderEntities db = new FoodOrderEntities()) { CatItemViewModel viewModel = new CatItemViewModel(); var itemData = db.FoodItems.Where(x => x.catId == id && x.isEnabled == true && x.isDeleted == false && x.quantity != "0").ToList(); var catData = db.Categories.Where(x => x.catId == id).ToList(); viewModel.category = catData; viewModel.foodItem = itemData; return(View(viewModel)); } }
CatItemViewModel GetAllCatItems() { using (FoodOrderEntities db = new FoodOrderEntities()) { var catData = db.Categories.ToList(); var itemData = db.FoodItems.Where(x => x.isDeleted == false).ToList(); var viewModel = new CatItemViewModel() { category = catData, foodItem = itemData }; return(viewModel); } }
public ActionResult SaveUser(User user) { using (FoodOrderEntities db = new FoodOrderEntities()) { var uname = db.Users.Where(x => x.username == user.username).FirstOrDefault(); var email = db.Users.Where(x => x.email == user.email).FirstOrDefault(); if (uname == null && email == null) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("SignUp")); } else { TempData["Message"] = "fail"; return(RedirectToAction("SignUp")); } } }
public ActionResult Checkout(List <CartItemArray> arr, int total) { using (FoodOrderEntities db = new FoodOrderEntities()) { var response = ChargeCreditCard.Run(total); if (response != null && response.check == true) { Order order = new Order(); order.transId = response.response; order.userId = Convert.ToInt32(Session["UserID"].ToString()); order.status = "Pending"; order.dateTime = DateTime.Now.ToString("HH:mm tt dd/MM/yyyy"); order.totalPrice = total.ToString(); db.Orders.Add(order); db.SaveChanges(); int id = Convert.ToInt32(order.orderId); foreach (var item in arr) { OrderDetail orderDetail = new OrderDetail(); orderDetail.orderId = id; orderDetail.itemId = item.id; orderDetail.quantity = item.qty.ToString(); db.OrderDetails.Add(orderDetail); db.SaveChanges(); var foodItem = db.FoodItems.Where(x => x.itemId == item.id).FirstOrDefault(); foodItem.quantity = (Convert.ToInt32(foodItem.quantity) - item.qty).ToString(); db.SaveChanges(); } return(Content("true")); } else { return(Content("false")); } } }
IEnumerable <UserOrderViewModel> GetTodayOrders() { var viewModels = new List <UserOrderViewModel>(); using (FoodOrderEntities db = new FoodOrderEntities()) { var today = DateTime.Now.ToString("dd/MM/yyyy"); var innerjoin = db.Orders.Where(x => x.dateTime.Contains(today)).Join( db.Users, o => o.userId, u => u.userId, (o, u) => new { username = u.username, orderId = o.orderId, status = o.status, totalPrice = o.totalPrice, dateTime = o.dateTime }).ToList(); foreach (var item in innerjoin) { UserOrderViewModel viewModel = new UserOrderViewModel { user = new User(), order = new Order() }; viewModel.user.username = item.username; viewModel.order.orderId = item.orderId; viewModel.order.status = item.status; viewModel.order.dateTime = item.dateTime; viewModel.order.totalPrice = item.totalPrice; viewModels.Add(viewModel); } return(viewModels); } }