public ActionResult add(get_info_product_Result data, HttpPostedFileBase file) { if (db.categories.Find(data.idcategory) != null) { if (file != null) { var x = db.categories.Where(s => s.id == data.idcategory).FirstOrDefault(); string physicaPath = Server.MapPath("/assets/image/icon/" + x.name + "/" + file.FileName); file.SaveAs(physicaPath); db.add_product(data.name, data.price, data.idcategory, file.FileName); } else { db.add_product(data.name, data.price, data.idcategory, "No picture"); } } else { TempData["alert"] = "Thêm mới sản phẩm không thành công do hạng mục món ăn không tồn tại !!"; TempData["AlertType"] = "alert-danger"; return(RedirectToAction("product", "home")); } using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { var x = db.foods.OrderByDescending(s => s.id).Take(1).FirstOrDefault(); get_info_product_Result product = db.get_info_product(x.id).FirstOrDefault(); List <category> listcategory = db.categories.ToList(); ViewBag.list = listcategory; return(View("index", product)); } }
public ActionResult cartt(int id) { using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { //tìm món ăn và hoá đơn đã có trong billinfo chưa var x = dbb.billinfoes.ToList().Where(s => s.idfood == id && s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault(); if (x == null) { //nếu không tìm thấy thì ta tạo mới billinfo chứa món ăn và idbill của bàn ăn đó dbb.add_billinfo(int.Parse(Session["idbill"].ToString()), id, 1); } else { //nếu tìm thấy ta tăng số lượng món ăn lên 1 x.count++; dbb.SaveChanges(); } } //thêm xong ta sẽ show lên giỏ hàng using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { //lấy tất cả billinfo cartfood.allbillinfos = dbb.billinfoes.ToList(); cartfood.allfoods = new List <food>(); foreach (billinfo item in cartfood.allbillinfos) { //lấy ra món ăn tương ứng với sô lượng của chúng var x = dbb.foods.ToList().Where(s => s.id == item.idfood).FirstOrDefault(); cartfood.allfoods.Add(x); } } return(PartialView("/Views/Shared/_cartproduct.cshtml", cartfood)); }
public ActionResult addstaff(Models.staff astaff) { using (QuanLyCafeEntities db = new QuanLyCafeEntities()) { data.allstaffs = db.staffs.ToList(); int idaccount = data.allstaffs[data.allstaffs.Count() - 1].idaccount + 1; string username; if (string.Compare(astaff.position, "Ban quản lý", true) == 0) { username = "******" + idaccount.ToString(); } else { username = "******" + idaccount.ToString(); } string password = "******"; string type; if (string.Compare(astaff.position, "Ban quản lý", true) == 0) { type = "admin"; } else { type = "staff"; } db.Addstaffaccountlatest(astaff.name, astaff.status, astaff.position, astaff.email, idaccount, username, password, type); } return(RedirectToAction("setting", "Home", new { area = "admin" })); }
public ActionResult delproduct(int id) { using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { db.delete_billinfo_idfood(id, int.Parse(Session["idbill"].ToString())); } return(cart()); }
public ActionResult Index(int id, int?status) { ViewBag.temp = status; //nhận được id bàn ViewBag.idtable = id; Session.Timeout = 360; //tìm trong bill xem bàn đã có hoá đơn chưa theo id bàn và status của bill var x = db.bills.ToList().Where(s => s.idtable == id && string.Compare(s.status, "0", true) == 0).FirstOrDefault(); if (x == null) { //nếu bàn chưa có bill thì tạo tạm thời 1 bill để lưu thông tin món ăn DateTime Timecheckin = DateTime.Now; DateTime?Timecheckout = null; db.add_bill(Timecheckin, Timecheckout, "0", int.Parse(Session["idaccount"].ToString()), id); var y = db.bills.ToList().Where(s => s.idtable == id & string.Compare(s.status, "0", true) == 0).FirstOrDefault(); Session["idbill"] = y.id; //lấy giá trị idbill để dùng cho việc xem billinfo của 1 bàn nào đó } else { /*ngược lại nếu bàn đó trống mà trước đó ta có chọn món mà ko xác nhận thì ở bước này sẽ xoá billinfo của bàn đó. * cái này cũng dùng cho trường hợp sau khi xác nhận thanh toán sẽ xoá hết thông tin billinfo của bàn đó */ Session["idbill"] = x.id; var y = db.tablefoods.ToList().Where(s => s.id == id && string.Compare(s.status, "Trống", true) == 0).FirstOrDefault(); if (y != null) { db.delete_billinfo(x.id); x.datecheckin = DateTime.Now; db.SaveChanges(); } else { using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { List <listIncart> listproduct = new List <listIncart>(); cartfood.allbillinfos = dbb.billinfoes.ToList(); foreach (billinfo item in cartfood.allbillinfos) { if (item.idbill == int.Parse(Session["idbill"].ToString())) { listproduct.Add(new listIncart(item.idfood, item.idbill, item.count)); } } Session["listproduct"] = listproduct; } } } data.allfoods = db.foods.ToList(); return(View(db.categories.ToList())); }
//không được gọi thông qua URL public ActionResult cart() { using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { cartfood.allbillinfos = dbb.billinfoes.ToList(); cartfood.allfoods = new List <food>(); foreach (billinfo item in cartfood.allbillinfos) { var x = dbb.foods.ToList().Where(s => s.id == item.idfood).FirstOrDefault(); cartfood.allfoods.Add(x); } } return(PartialView("/views/Shared/_cartproduct.cshtml", cartfood)); }
public ActionResult deletestaff(int id) { using (QuanLyCafeEntities db = new QuanLyCafeEntities()) { try { data.allstaffs = db.staffs.ToList(); db.deletestaffaccount(id); } catch { return(RedirectToAction("setting", "Home", new { area = "admin" })); } } return(RedirectToAction("setting", "Home", new { area = "admin" })); }
public ActionResult cartt(int id) { using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { //tìm món ăn và hoá đơn đã có trong billinfo chưa var x = dbb.billinfoes.ToList().Where(s => s.idfood == id && s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault(); if (x == null) { //nếu không tìm thấy thì ta tạo mới billinfo chứa món ăn và idbill của bàn ăn đó dbb.add_billinfo(int.Parse(Session["idbill"].ToString()), id, 1); } else { //nếu tìm thấy ta tăng số lượng món ăn lên 1 x.count++; dbb.SaveChanges(); } } return(cart()); }
public ActionResult reduction(int id) { //nếu count =1 thì không làm gì, ngược lại thì giảm đi 1 var y = db.billinfoes.ToList().Where(s => s.idfood == id && s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault(); if (y.count == 1) { return(RedirectToAction("index", "order")); } else { using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { var x = dbb.billinfoes.ToList().Where(s => s.idfood == id && s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault(); x.count = x.count - 1; dbb.SaveChanges(); } } return(cart()); }
public ActionResult Result(account user) { using (QuanLyCafeEntities db = new QuanLyCafeEntities()) { var search = db.accounts.ToList().Where(x => x.username == user.username && x.password == user.password).FirstOrDefault(); if (search != null) { Session["type"] = search.type; Session["idaccount"] = search.id; if (Session["type"].ToString() == "admin") { return(RedirectToAction("home", "admin")); } else { return(RedirectToAction("home", "staff")); } } else { if (string.IsNullOrEmpty(user.password)) { ModelState.AddModelError("password", "Chưa nhập mật khẩu !"); } if (string.IsNullOrEmpty(user.username)) { ModelState.AddModelError("username", "Chưa nhập tài khoản !"); } if (string.IsNullOrEmpty(user.username) == false && string.IsNullOrEmpty(user.password) == false) { //user.LoginErrorMessage = "Wrong username or password."; TempData["LoginMessage"] = "Tài khoản hoặc mật khẩu không đúng"; return(View("index", user)); } return(View("index", user)); } } }
public ActionResult bill(int?id, int?temp) { if (id != null && db.tablefoods.ToList().Where(s => s.id == id && string.Compare(s.status, "trống", true) == 0).FirstOrDefault() == null) { ViewBag.temp = temp; db.empty_table(id); var x = db.bills.ToList().Where(s => s.idtable == id && string.Compare(s.status, "0", true) == 0).FirstOrDefault(); x.status = "1"; x.idaccount = int.Parse(Session["idaccount"].ToString()); x.datecheckout = DateTime.Now; //tính tổng tiền của bàn double tongtien = 0; using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { cartfood.allbillinfos = dbb.billinfoes.ToList(); foreach (billinfo item in cartfood.allbillinfos) { if (item.idbill == int.Parse(Session["idbill"].ToString())) { var y = dbb.foods.ToList().Where(s => s.id == item.idfood).FirstOrDefault(); tongtien += (item.count * y.price); } } } x.Tongtien = tongtien; db.SaveChanges(); } else if (id != null && db.tablefoods.ToList().Where(s => s.id == id && string.Compare(s.status, "trống", true) == 0).FirstOrDefault() != null) { ViewBag.temp = temp; db.empty_table(id); var x = db.bills.ToList().Where(s => s.idtable == id && string.Compare(s.status, "0", true) == 0).FirstOrDefault(); x.status = "1"; x.idaccount = int.Parse(Session["idaccount"].ToString()); x.datecheckout = DateTime.Now; //tính tổng tiền của bàn double tongtien = 0; using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { cartfood.allbillinfos = dbb.billinfoes.ToList(); foreach (billinfo item in cartfood.allbillinfos) { if (item.idbill == int.Parse(Session["idbill"].ToString())) { var y = dbb.foods.ToList().Where(s => s.id == item.idfood).FirstOrDefault(); tongtien += (item.count * y.price); } } } if (tongtien == 0) { return(RedirectToAction("index", "order", new { id = id, status = 4 })); } else { x.Tongtien = tongtien; db.SaveChanges(); } } //nếu thanh toán khi chưa chọn xác nhận using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { //List<bill> x = dbb.bills.SqlQuery("select * from bill where "); //dbb.delete_billinfo(x.id); data.alltablefoods = dbb.tablefoods.SqlQuery("select * from tablefood").ToList(); } return(View("index", data)); }
public ActionResult Index(int?id, int?temp) { //taọ 1 toastr thông báo khi chưa chọn món mà bấm xác nhận using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { if (Session["idbill"] != null) { var x = dbb.billinfoes.ToList().Where(s => s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault(); if (id != null && x == null) { //nếu không tìm thấy billinfo của bill thì thông báo chưa chọn món. //3 là trạng thái gửi sang page order return(RedirectToAction("index", "order", new { id = id, status = 3 })); } } } //trường hợp chọn thêm món mà chưa xác nhận sẽ không được tính if (id == null && temp == null && Session["idbill"] != null) { ViewBag.temp = 3; //toastr thông báo món ăn ko thay đổi List <listIncart> listproduct = new List <listIncart>(); listproduct = (List <listIncart>)Session["listproduct"]; //listproduct là danh sách trước khi chịn thêm món //listproduct1 là danh sách sau khi chịn thêm món using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { List <listIncart> listproductbefore = new List <listIncart>(); classdata cardfood1 = new classdata(); cardfood1.allbillinfos = dbb.billinfoes.ToList(); foreach (billinfo item in cardfood1.allbillinfos) { if (item.idbill == int.Parse(Session["idbill"].ToString())) { listproductbefore.Add(new listIncart(item.idfood, item.idbill, item.count)); } } foreach (var item in listproductbefore) { foreach (var item1 in listproduct) { if (item1.ID == item.ID && item1.COUNT != item.COUNT) { var z = dbb.billinfoes.ToList().Where(s => s.idfood == item.ID && s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault(); z.count = item1.COUNT; dbb.SaveChanges(); } } } } } else if (id != null && temp != null) { //xác nhận đổi món của bàn thành công ViewBag.temp = 0; } //nếu id != null và bàn trống tức là có bàn yêu cầu xác nhận đặt món if (id != null && db.tablefoods.ToList().Where(s => s.id == id && string.Compare(s.status, "trống", true) == 0).FirstOrDefault() != null) { ViewBag.temp = temp; db.customer_table(id); } using (QuanLyCafeEntities dbb = new QuanLyCafeEntities()) { data.alltablefoods = dbb.tablefoods.SqlQuery("select * from tablefood").ToList(); } return(View(data)); }