public ActionResult Delete(int id, FormCollection collection) { if (ModelState.IsValid) { var result = dao.Delete(id); if (result) { // Session var session = Convert.ToInt32(Session["FarmerID"]); var db = new FarmHubDbContext(); var farmerID = db.FARMERs.Find(session).Id_Farmer; var farmID = db.FARMs.FirstOrDefault(x => x.Id_Farmer == farmerID).Id_Farm; return(RedirectToAction("Index", new { id = farmID })); } else { ModelState.AddModelError("", "Xóa thất bại !!!"); } } var pdModel = dao.Details(id); return(View(pdModel)); }
public ActionResult Account() { var traderID = Session["TraderId"]; var trader = new FarmHubDbContext().TRADERs.Find(traderID); return(View(trader)); }
public ActionResult Account() { var farmerID = Session["FarmerID"]; var farmer = new FarmHubDbContext().FARMERs.Find(farmerID); return(View(farmer)); }
public ActionResult Edit(int id) { var productKindID = new FarmHubDbContext().PRODUCTs.Find(id).Id_ProductKind; SetViewBagProductKind(productKindID); var model = dao.Details(id); return View(model); }
public ActionResult Edit(PRODUCT_DETAIL productDetailsModel) { string fileName = null; string fileExtension = null; try { fileName = Path.GetFileNameWithoutExtension(productDetailsModel.ImageFile.FileName); fileExtension = Path.GetExtension(productDetailsModel.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + fileExtension; productDetailsModel.Image_ProductDetail = "/Data/Image/Farmer/Customer/" + fileName; fileName = Path.Combine(Server.MapPath("/Data/Image/Farmer/Customer/"), fileName); productDetailsModel.ImageFile.SaveAs(fileName); } catch (Exception) { ModelState.AddModelError("", "Hình ảnh không được để trống"); // Set and select value from ViewBag var farmmID = new FarmHubDbContext().PRODUCT_DETAIL.Find(productDetailsModel.Id_ProductDetail).Id_Farm; SetViewBagFarm(farmmID); var producID = new FarmHubDbContext().PRODUCT_DETAIL.Find(productDetailsModel.Id_ProductDetail).Id_Product; SetViewBagProduct(producID); var seedID = new FarmHubDbContext().PRODUCT_DETAIL.Find(productDetailsModel.Id_ProductDetail).Id_Seed; SetViewBagSeed(seedID); var productDetailsModelState = dao.Details(productDetailsModel.Id_ProductDetail); return(View(productDetailsModelState)); } var result = dao.Update(productDetailsModel); if (result) { // Session var session = Convert.ToInt32(Session["FarmerID"]); var db = new FarmHubDbContext(); var farmerID = db.FARMERs.Find(session).Id_Farmer; var farmID = db.FARMs.FirstOrDefault(x => x.Id_Farmer == farmerID).Id_Farm; return(RedirectToAction("Index", new { id = farmID })); } else { ModelState.AddModelError("", "Cập nhật thất bại"); // Set and select value from ViewBag var farmmID = new FarmHubDbContext().PRODUCT_DETAIL.Find(productDetailsModel.Id_ProductDetail).Id_Farm; SetViewBagFarm(farmmID); var producID = new FarmHubDbContext().PRODUCT_DETAIL.Find(productDetailsModel.Id_ProductDetail).Id_Product; SetViewBagProduct(producID); var seedID = new FarmHubDbContext().PRODUCT_DETAIL.Find(productDetailsModel.Id_ProductDetail).Id_Seed; SetViewBagSeed(seedID); var productDetailsModelState = dao.Details(productDetailsModel.Id_ProductDetail); return(View(productDetailsModelState)); } }
// SetViewBagFarm public void SetViewBagFarm(int?farmID = null) { // Session var session = Convert.ToInt32(Session["FarmerID"]); var farmerID = new FarmHubDbContext().FARMERs.Find(session).Id_Farmer; FarmDAO dao = new FarmDAO(); ViewBag.Id_Farm = new SelectList(dao.ListFarmByFarmerID(farmerID), "Id_Farm", "Name_Farm", farmID); }
// Auto Complete public JsonResult GetSearchValue(string search) { FarmHubDbContext db = new FarmHubDbContext(); List<ProductAutoCompleteModel> allSearch = db.PRODUCTs.Where(x => x.Name_Product.Contains(search)).Select(x => new ProductAutoCompleteModel { Id_Product = x.Id_Product, Name_Product = x.Name_Product }).ToList(); return new JsonResult { Data = allSearch, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }
// SetViewBag FarmID dùng cho create tự dộng gán giá trị Id_Farm vào Product Details public void FarmIDForViewBag() { // Session var session = Convert.ToInt32(Session["FarmerID"]); var farmIDSaved = Convert.ToInt32(Session["FarmID"]); // giá trị farmID lấy từ Index var farmerID = new FarmHubDbContext().FARMERs.Find(session).Id_Farmer; FarmDAO dao = new FarmDAO(); ViewBag.FarmIDForPD = new SelectList(dao.ListFarmByFarmerID(farmerID), "Id_Farm", "Name_Farm", farmIDSaved); }
// Auto Complete public JsonResult GetSearchValue(string search) { FarmHubDbContext db = new FarmHubDbContext(); List <SeedAutoCompleteModel> allSearch = db.SEEDs.Where(x => x.Name_Seed.Contains(search)).Select(x => new SeedAutoCompleteModel { Id_Seed = x.Id_Seed, Name_Seed = x.Name_Seed }).ToList(); return(new JsonResult { Data = allSearch, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
// GET: Farmer/ProductDetails/Edit/5 public ActionResult Edit(int id) { // Set and select value from ViewBag var farmID = new FarmHubDbContext().PRODUCT_DETAIL.Find(id).Id_Farm; SetViewBagFarm(farmID); //var producID = new FarmHubDbContext().PRODUCT_DETAIL.Find(id).Id_Product; //SetViewBagProduct(producID); //var seedID = new FarmHubDbContext().PRODUCT_DETAIL.Find(id).Id_Seed; //SetViewBagSeed(seedID); ViewBag.PRODUCTS = new FarmHubDbContext().PRODUCTs.Where(x => x.Is_Deleted == false).ToList(); ViewBag.SEEDS = new FarmHubDbContext().SEEDs.Where(x => x.Is_Deleted == false).ToList(); var pdModel = dao.Details(id); return(View(pdModel)); }
// GET: Farmer/ProductDetails/Edit/5 public ActionResult Edit(int id) { // Set and select value from ViewBag var farmID = new FarmHubDbContext().PRODUCT_DETAIL.Find(id).Id_Farm; SetViewBagFarm(farmID); var producID = new FarmHubDbContext().PRODUCT_DETAIL.Find(id).Id_Product; SetViewBagProduct(producID); var seedID = new FarmHubDbContext().PRODUCT_DETAIL.Find(id).Id_Seed; SetViewBagSeed(seedID); var pdModel = dao.Details(id); return(View(pdModel)); }
public ActionResult Create(PRODUCT_DETAIL pdModel) { string fileName = null; string fileExtension = null; try { fileName = Path.GetFileNameWithoutExtension(pdModel.ImageFile.FileName); fileExtension = Path.GetExtension(pdModel.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + fileExtension; pdModel.Image_ProductDetail = "/Data/Image/Farmer/Customer/" + fileName; fileName = Path.Combine(Server.MapPath("/Data/Image/Farmer/Customer/"), fileName); pdModel.ImageFile.SaveAs(fileName); } catch (Exception) { ModelState.AddModelError("", "Hình ảnh không được để trống"); FarmIDForViewBag(); SetViewBagProduct(); SetViewBagSeed(); return(View(pdModel)); } pdModel.Id_Farm = Convert.ToInt32(Session["FarmID"]); var result = dao.Create(pdModel); if (result > 0) { // Session var session = Convert.ToInt32(Session["FarmerID"]); var db = new FarmHubDbContext(); var farmerID = db.FARMERs.Find(session).Id_Farmer; var farmID = db.FARMs.FirstOrDefault(x => x.Id_Farmer == farmerID).Id_Farm; return(RedirectToAction("Index", new { id = farmID })); } else { ModelState.AddModelError("", "Tạo mới thất bại !!!"); FarmIDForViewBag(); SetViewBagProduct(); SetViewBagSeed(); return(View(pdModel)); } }
public ActionResult Edit(PRODUCT model) { string fileName = null; string fileExtension = null; try { fileName = Path.GetFileNameWithoutExtension(model.ImageFile.FileName); fileExtension = Path.GetExtension(model.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + fileExtension; model.Image_Product = "/Data/Image/Farmer/Base/" + fileName; fileName = Path.Combine(Server.MapPath("/Data/Image/Farmer/Base/"), fileName); model.ImageFile.SaveAs(fileName); } catch (Exception) { ModelState.AddModelError("", "Hình ảnh không được để trống"); // Set and select value from ViewBag var productKindID = new FarmHubDbContext().PRODUCTs.Find(model.Id_Product).Id_ProductKind; SetViewBagProductKind(productKindID); var productModelState = dao.Details(model.Id_Product); return View(productModelState); } var result = dao.Update(model); if (result) { return RedirectToAction("ProductIndex"); } else { ModelState.AddModelError("", "Cập nhật thất bại"); // Set and select value from ViewBag var productKindID = new FarmHubDbContext().PRODUCTs.Find(model.Id_Product).Id_ProductKind; SetViewBagProductKind(productKindID); var productModelState = dao.Details(model.Id_Product); return View(productModelState); } }
// ChartJS public ActionResult Dashboard() { var list = new FarmHubDbContext().PURCHASE_OFFER.Where(x => x.Is_Deleted == false).ToList(); List <int> repartition = new List <int>(); List <int> prices = new List <int>(); var productNames = list.Select(x => x.PRODUCT.Name_Product).Distinct(); var quantityPurchaseOffer = list.GroupBy(x => x.PRODUCT.Name_Product).ToString(); foreach (var item in productNames) { repartition.Add(list.Count(x => x.PRODUCT.Name_Product == item)); } foreach (var item in quantityPurchaseOffer) { prices.Add(item); } ViewBag.PRODUCTNAMES = productNames; ViewBag.REP = repartition.ToList(); ViewBag.PRICES = prices.ToList(); return(View()); }
public PurchaseOfferDao() { db = new FarmHubDbContext(); }
public SaleOfferDetailDao() { db = new FarmHubDbContext(); }
public ProductDetailDAO() { db = new FarmHubDbContext(); }
public SeedDao() { db = new FarmHubDbContext(); }
public UserAuthenDAO() { db = new FarmHubDbContext(); }
public TraderDAO() { db = new FarmHubDbContext(); }
public TraderTransactionDao() { db = new FarmHubDbContext(); }
public FeedBackDao() { db = new FarmHubDbContext(); }
public FarmerOfferDao() { db = new FarmHubDbContext(); }
public FarmDAO() { db = new FarmHubDbContext(); }
public RegisterDao() { db = new FarmHubDbContext(); }
public OrderDao() { db = new FarmHubDbContext(); }
public TransactionOrderDAO() { db = new FarmHubDbContext(); }
public MarketTransHisDAO() { db = new FarmHubDbContext(); }
public EditPasswordDao() { db = new FarmHubDbContext(); }
public ProductKindDAO() { db = new FarmHubDbContext(); }