public ActionResult SuaSizeMonAn(FoodSize foodsize, string StoreID) { var stID = Guid.Parse(StoreID); var fs = db.FoodSizes.Where(n => n.FoodSizeID == foodsize.FoodSizeID).SingleOrDefault(); if (fs == null) { //Trả về trang báo lỗi Response.StatusCode = 404; return(null); } fs.SizeName = foodsize.SizeName; fs.PriceSize = foodsize.PriceSize; fs.FoodID = foodsize.FoodID; if (ModelState.IsValid) { //Thực hiện cập nhận trong model db.Entry(fs).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Session["Message"] = fs.SizeName + " sửa thành công"; return(RedirectToAction("QuanLySizeMonAn", new { StoreID = StoreID, page = 1, method = "Sua" })); } ViewBag.FoodID = new SelectList(db.Foods.Where(n => n.StoreID == stID) .OrderBy(n => n.FoodName).ToList(), "FoodID", "FoodName", foodsize.FoodID); ViewBag.StoreID = StoreID; return(View(foodsize)); }
public ActionResult ThemSizeMonAn(FoodSize foodsize, string StoreID) { var stID = Guid.Parse(StoreID); if (ModelState.IsValid) { db.Entry(foodsize).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); Session["Message"] = foodsize.SizeName + " thêm thành công"; return(RedirectToAction("QuanLySizeMonAn", new { StoreID = StoreID, page = 1, method = "ThemMoi" })); } ViewBag.FoodID = new SelectList(db.Foods.Where(n => n.StoreID == stID) .OrderBy(n => n.FoodName).ToList(), "FoodID", "FoodName", foodsize.FoodID); ViewBag.StoreID = StoreID; return(View(foodsize)); }
public JsonResult AddFood(FoodAddDto foodadd) { var fdID = Guid.Parse(foodadd.FoodID); Food food = db.Foods.SingleOrDefault(n => n.FoodID == fdID); if (food == null) { return(Json(null)); } //Lấy ra session giỏ hàng GioHangStore gioHangStore = getGioHangStore(food.StoreID + ""); List <GioHang> lstGioHang = new List <GioHang>(); if (gioHangStore.Orders != null) { lstGioHang = gioHangStore.Orders; } //Kiểm tra sách này đã tồn tại trong session[giohang] chưa string sizeName; string typeName; FoodSize size = db.FoodSizes.Where(n => n.FoodSizeID == foodadd.FoodSizeID).SingleOrDefault(); FoodType type = db.FoodTypes.Where(n => n.FoodTypeID == foodadd.FoodTypeID).SingleOrDefault(); GioHang sanpham = lstGioHang.Find(n => n.FoodID.Equals(foodadd.FoodID)); sizeName = (size == null) ? "" : size.SizeName; typeName = (type == null) ? "" : type.TypeName; if (sanpham == null || !sanpham.FoodSize.Equals(sizeName) || !sanpham.FoodType.Equals(typeName)) { sanpham = new GioHang(foodadd.FoodID, foodadd.FoodSizeID, foodadd.FoodTypeID, foodadd.SoLuong); //Add sản phẩm mới thêm vào list lstGioHang.Add(sanpham); gioHangStore.Orders = lstGioHang; return(Json(lstGioHang)); } else { sanpham.SoLuong += foodadd.SoLuong; return(Json(lstGioHang)); } }