Example #1
0
        public ActionResult Update(int cid, string crop_name, int quantity, int unit_price)
        {
            if (Session["UserData"] != null)
            {
                int id = int.Parse(Session["UserData"].ToString());

                CropFarmer c = new CropFarmer
                {
                    fid      = id,
                    cid      = cid,
                    added_on = DateTime.Now,
                    qty_left = quantity
                };
                crops c1            = BusinessManager.getcrop(cid);
                int   totalquantity = c1.quantity + c.qty_left;
                c.qty_left = totalquantity;
                BusinessManager.updateCrop(c);
                bool status = BusinessManager.updateCropquantity(cid, totalquantity);
                if (status)
                {
                    return(RedirectToAction("displayAllCrops", "crops"));
                }
                else
                {
                    return(View());
                }
            }
            return(RedirectToAction("loginfarmerdis", "farmers"));
        }
        public static bool AddCrop(crops c)
        {
            bool status = false;

            try
            {
                using (MySqlConnection con = new MySqlConnection(connString)) //DI via Constructor
                {
                    if (con.State == ConnectionState.Closed)                  //if connection is closed?
                    {
                        con.Open();
                    }
                    string query = "INSERT INTO crops (crop_name,added_on,category,description,quantity,unit_price,image) " +
                                   "VALUES (@crop_name, @added_on, @category, @description, @quantity,@unit_price,@ImageUrl)";
                    MySqlCommand cmd = new MySqlCommand(query, con);
                    cmd.Parameters.Add(new MySqlParameter("@crop_name", c.crop_name));
                    cmd.Parameters.Add(new MySqlParameter("@added_on", c.added_on));
                    cmd.Parameters.Add(new MySqlParameter("@category", c.category));
                    cmd.Parameters.Add(new MySqlParameter("@description", c.description));
                    cmd.Parameters.Add(new MySqlParameter("@quantity", c.quantity));
                    cmd.Parameters.Add(new MySqlParameter("@unit_price", c.unit_price));
                    cmd.Parameters.Add(new MySqlParameter("@ImageUrl", c.image));
                    cmd.ExecuteNonQuery();
                    con.Close();


                    status = true;
                }
            }
            catch (MySqlException exp)
            {
                string message = exp.Message;
            }
            return(status);
        }
Example #3
0
        public ActionResult RegisterCrops(int cid, int quantity, int unit_price)
        {
            if (Session["UserData"] != null)
            {
                int id = int.Parse(Session["UserData"].ToString());

                //            bool status = BusinessManager.AddCrop(c);
                DateTime          date          = DateTime.Now;
                int               totalquantity = 0;
                crops             c             = new crops();
                List <CropFarmer> cf            = BusinessManager.getcropfarmerByID(id);
                foreach (CropFarmer i in cf)
                {
                    if (i.cid == cid)
                    {
                        c             = BusinessManager.getcrop(cid);
                        totalquantity = c.quantity + i.qty_left;
                        i.qty_left    = totalquantity;
                        i.added_on    = DateTime.Now;
                        BusinessManager.updateCrop(i);
                        BusinessManager.updateCropquantity(cid, totalquantity);
                    }
                }
                BusinessManager.AddCrop_xref(id, cid, date, quantity);
                c = BusinessManager.getcrop(cid);
                CropFarmer cf1 = BusinessManager.getcropFarmer(cid);
                totalquantity = c.quantity + cf1.qty_left;
                BusinessManager.updateCropquantity(cid, totalquantity);//main crop table
                return(RedirectToAction("displayAllCrops", "crops"));
            }
            return(RedirectToAction("loginfarmer", "farmers"));
        }
        public ActionResult Order()
        {                                       //orderid, customerID, cropID, quantity, total_amount, address, fid, crop_name
            if (Session["customrdata"] != null) //fid session
            {
                int      id          = 0;
                Customer thecustomer = null;
                if (Session["thecustomer"] != null)
                {
                    thecustomer = (Customer)Session["thecustomer"];
                }

                if (Session["FARMERID"] != null)
                {
                    id = int.Parse(Session["FARMERID"].ToString());
                }
                int userData = int.Parse(Session["customrdata"].ToString());

                Cart        existingCart = this.HttpContext.Session["shoppingcart"] as Cart;
                List <Item> ilist        = new List <Item>();
                foreach (Item i in existingCart.items)
                {
                    BusinessManager.AddToOrder(i, userData, thecustomer.address, id);
                    ilist.Add(i);
                    crops c         = BusinessManager.getcrop(i.cropID);
                    int   totalLeft = c.quantity - i.quantity;
                    BusinessManager.updateCropquantity(i.cropID, totalLeft);
                }
                existingCart.items.Clear();
                ViewData["ilist"] = ilist;

                return(View());//add view
            }
            return(RedirectToAction("login", "Accounts"));
        }
        public ActionResult AddToCart(int cropID, string crop_name, string image, int quantity, int unit_price)
        {
            int fid = 0;

            if (Session["FARMERID"] != null)
            {
                fid = int.Parse(this.Session["FARMERID"].ToString());
            }

            Cart existingCart = this.HttpContext.Session["shoppingcart"] as Cart;
            Item newItem      = new Item {
                cropID = cropID, crop_name = crop_name, image = image, quantity = quantity, unit_price = unit_price, total = quantity * unit_price, fid = fid
            };
            crops c = BusinessManager.getcrop(cropID);

            if (c.quantity >= quantity)
            {
                existingCart.items.Add(newItem);
            }
            else
            {
                this.ViewBag.Message = "your requested quantity is not available plese check the available quantity on details page";
                return(RedirectToAction("AddToCarterror/" + cropID, "shoppingCart"));
            }

            return(RedirectToAction("index", "shoppingCart"));
        }
        /* public ActionResult Remove1(int id)
         * {
         *
         *   Cart existingCart = this.HttpContext.Session["shoppingcart"] as Cart;
         *   Item i = new Item();
         *//* List<Item> itemlist = new List<Item>();*//*
         *   foreach (Item item in existingCart.items)
         *   {
         *       if(item.cropID==id)
         *       {
         *           i.cropID = item.cropID;
         *           i.crop_name = item.crop_name;
         *           i.fid = item.fid;
         *           i.unit_price = item.unit_price;
         *           i.total = item.total;
         *           i.quantity = item.quantity;
         *           i.image = item.image;
         *       }
         *
         *   }
         *   existingCart.items.Remove(i);
         *   return RedirectToAction("index", "shoppingCart");
         * }*/

        public ActionResult AddToCart(int id)
        {
            Cart existingCart = this.HttpContext.Session["shoppingcart"] as Cart;

            crops c = BusinessManager.getcrop(id);

            return(View(c));
        }
Example #7
0
        public ActionResult DisplayAllCropsForCustomers(int id)
        {
            List <CropFarmer> croplist = BusinessManager.getcropfarmerByID(id);

            //add farmerID to session
            this.Session.Add("FARMERID", id);
            List <crops> cList = new List <crops>();

            foreach (CropFarmer i in croplist)
            {
                crops c = new crops();
                c = BusinessManager.getcrop(i.cid);
                cList.Add(c);
            }
            ViewBag.farmerId        = id;
            ViewData["allProducts"] = cList;
            return(View());
        }
Example #8
0
        public ActionResult displayAllCrops()//display crops to farmer which are only added by that particular farmer
        {
            //CropFarmer cf=new
            if (Session["UserData"] != null)

            {
                int id = int.Parse(Session["UserData"].ToString());

                List <CropFarmer> croplist = BusinessManager.getcropfarmerByID(id);
                List <crops>      cList    = new List <crops>();
                foreach (CropFarmer i in croplist)
                {
                    crops c = new crops();
                    c = BusinessManager.getcrop(i.cid);
                    cList.Add(c);
                }
                ViewData["allProducts"] = cList;
                return(View());
            }
            return(RedirectToAction("loginfarmer", "farmers"));
        }
        public static crops GetByID(int id)
        {
            crops thecrops = new crops();

            IDbConnection conn = new MySqlConnection();

            conn.ConnectionString = connString;
            string     query = "Select * from crops WHERE cropID=" + id;
            IDbCommand cmd   = new MySqlCommand();

            cmd.CommandText = query;
            cmd.Connection  = conn;
            MySqlDataAdapter da = new MySqlDataAdapter(cmd as MySqlCommand);
            DataSet          ds = new DataSet();

            try
            {
                //cropID, crop_name, added_on, category, description, quantity, unit_price, image

                da.Fill(ds);
                DataRowCollection rows = ds.Tables[0].Rows;
                foreach (DataRow row in rows)
                {
                    thecrops.cropID      = int.Parse(row["cropID"].ToString());
                    thecrops.crop_name   = row["crop_name"].ToString();
                    thecrops.added_on    = DateTime.Parse(row["added_on"].ToString());
                    thecrops.category    = row["category"].ToString();
                    thecrops.description = row["description"].ToString();
                    thecrops.quantity    = int.Parse(row["quantity"].ToString());
                    thecrops.unit_price  = int.Parse(row["unit_price"].ToString());
                    thecrops.image       = row["image"].ToString();
                }
            }
            catch (MySqlException e)
            {
                string message = e.Message;
            }
            // implementation
            return(thecrops);
        }
        public static List <crops> GetAllProducts()
        {
            List <crops>  allCrops = new List <crops>();
            IDbConnection conn     = new MySqlConnection();

            conn.ConnectionString = connString;
            string     query = "Select * from crops";
            IDbCommand cmd   = new MySqlCommand();

            cmd.CommandText = query;
            cmd.Connection  = conn;
            MySqlDataAdapter da = new MySqlDataAdapter(cmd as MySqlCommand);
            DataSet          ds = new DataSet();

            try
            {
                //cropID, crop_name, added_on, category, description, quantity, unit_price, image
                da.Fill(ds);
                DataRowCollection rows = ds.Tables[0].Rows;
                foreach (DataRow row in rows)
                {
                    crops crop = new crops();
                    crop.cropID      = int.Parse(row["cropID"].ToString());
                    crop.crop_name   = row["crop_name"].ToString();
                    crop.added_on    = DateTime.Parse(row["added_on"].ToString());
                    crop.category    = row["category"].ToString();
                    crop.description = row["description"].ToString();
                    crop.quantity    = int.Parse(row["quantity"].ToString());
                    crop.unit_price  = int.Parse(row["unit_price"].ToString());
                    crop.image       = row["image"].ToString();
                    allCrops.Add(crop);
                }
            }
            catch (MySqlException e)
            {
                string message = e.Message;
            }
            return(allCrops);
        }
 public static bool AddCrop(crops c)
 {
     return(DBManager.AddCrop(c));
 }
Example #12
0
        public ActionResult Update(int id)
        {
            crops crop = BusinessManager.getcrop(id);

            return(View(crop));
        }
Example #13
0
        public ActionResult details(int id)
        {
            crops c = BusinessManager.getcrop(id);

            return(View(c));
        }