Esempio n. 1
0
        // Update
        public bool Update(PRODUCT_DETAIL productDetailModel)
        {
            var targetUpdate = db.PRODUCT_DETAIL.Find(productDetailModel.Id_ProductDetail);

            try
            {
                targetUpdate.Id_Product          = productDetailModel.Id_Product;
                targetUpdate.Id_Farm             = productDetailModel.Id_Farm;
                targetUpdate.Id_Seed             = productDetailModel.Id_Seed;
                targetUpdate.Name_Crop           = productDetailModel.Name_Crop;
                targetUpdate.Start_Time          = productDetailModel.Start_Time;
                targetUpdate.End_Time            = productDetailModel.End_Time;
                targetUpdate.Harvest_StartTime   = productDetailModel.Harvest_StartTime;
                targetUpdate.Harvest_EndTime     = productDetailModel.Harvest_EndTime;
                targetUpdate.Geography_Location  = productDetailModel.Geography_Location;
                targetUpdate.Quantity_Expected   = productDetailModel.Quantity_Expected;
                targetUpdate.Image_ProductDetail = productDetailModel.Image_ProductDetail;
                db.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                return(false);

                throw new Exception(e.Message);
            }
        }
        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));
            }
        }
Esempio n. 3
0
 public virtual int Delete(int id)
 {
     try
     {
         PRODUCT_DETAIL cus = this.GetById(id);
         return(this.Delete(cus));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Esempio n. 4
0
 public virtual void Remove(PRODUCT_DETAIL cus)
 {
     try
     {
         db.PRODUCT_DETAILs.DeleteOnSubmit(cus);
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Esempio n. 5
0
 public virtual void Remove(int id)
 {
     try
     {
         PRODUCT_DETAIL cus = this.GetById(id);
         this.Remove(cus);
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
Esempio n. 6
0
 public virtual void Create(PRODUCT_DETAIL cus)
 {
     try
     {
         this.db.PRODUCT_DETAILs.InsertOnSubmit(cus);
         db.SubmitChanges();
     }
     catch// (Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
Esempio n. 7
0
 public virtual void Update(PRODUCT_DETAIL cus)
 {
     try
     {
         PRODUCT_DETAIL cusOld = this.GetById(cus.ID);
         cusOld = cus;
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
Esempio n. 8
0
 public virtual int Delete(PRODUCT_DETAIL cus)
 {
     try
     {
         //user.IsDelete = true;
         db.SubmitChanges();
         return(0);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 // Create
 public int Create(PRODUCT_DETAIL productDetailModel)
 {
     try
     {
         productDetailModel.Is_Deleted = false;
         db.PRODUCT_DETAIL.Add(productDetailModel);
         db.SaveChanges();
     }
     catch (Exception)
     {
         return(0);
     }
     return(productDetailModel.Id_ProductDetail);
 }
        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));
            }
        }
        private void Save(string strLink = "")
        {
            try
            {
                var ProductDetail = _ProductDetailRepo.GetById(id);
                if (id > 0 && ProductDetail != null)
                {
                    ProductDetail.CODE       = txtCode.Text;
                    ProductDetail.NAME       = txtName.Text;
                    ProductDetail.M2         = Utils.CDecDef(txtM2.Text);
                    ProductDetail.WEIGHT     = Utils.CDecDef(txtWeight.Text);;
                    ProductDetail.TYPE_ID    = Utils.CIntDef(ddlType.SelectedValue);
                    ProductDetail.PRODUCT_ID = Utils.CIntDef(ddlProduct.SelectedValue);

                    _ProductDetailRepo.Update(ProductDetail);

                    strLink = string.IsNullOrEmpty(strLink) ? "chi-tiet-san-pham-chi-tiet.aspx?id=" + id : strLink;
                }
                else
                {
                    ProductDetail            = new PRODUCT_DETAIL();
                    ProductDetail.CODE       = txtCode.Text;
                    ProductDetail.NAME       = txtName.Text;
                    ProductDetail.M2         = Utils.CDecDef(txtM2.Text);
                    ProductDetail.WEIGHT     = Utils.CDecDef(txtWeight.Text);;
                    ProductDetail.TYPE_ID    = Utils.CIntDef(ddlType.SelectedValue);
                    ProductDetail.PRODUCT_ID = Utils.CIntDef(ddlProduct.SelectedValue);

                    _ProductDetailRepo.Create(ProductDetail);

                    strLink = string.IsNullOrEmpty(strLink) ? "chi-tiet-san-pham-chi-tiet.aspx?id=" + ProductDetail.ID : strLink;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (!string.IsNullOrEmpty(strLink))
                {
                    Response.Redirect(strLink);
                }
            }
        }
Esempio n. 12
0
 public ProductDetailService(PRODUCT_DETAIL item)
 {
     _item = item;
 }