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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 9
0
        // 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
            });
        }
Exemplo n.º 10
0
        // 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);
            }
        }
Exemplo n.º 14
0
        // 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());
        }
Exemplo n.º 15
0
 public PurchaseOfferDao()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 16
0
 public SaleOfferDetailDao()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 17
0
 public ProductDetailDAO()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 18
0
 public SeedDao()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 19
0
 public UserAuthenDAO()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 20
0
 public TraderDAO()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 21
0
 public TraderTransactionDao()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 22
0
 public FeedBackDao()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 23
0
 public FarmerOfferDao()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 24
0
 public FarmDAO()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 25
0
 public RegisterDao()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 26
0
 public OrderDao()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 27
0
 public TransactionOrderDAO()
 {
     db = new FarmHubDbContext();
 }
 public MarketTransHisDAO()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 29
0
 public EditPasswordDao()
 {
     db = new FarmHubDbContext();
 }
Exemplo n.º 30
0
 public ProductKindDAO()
 {
     db = new FarmHubDbContext();
 }