public ActionResult Create([Bind(Include = "StockImageID,StockImage,StockID")] StocksImage stocksImage, HttpPostedFileBase image1, string crop)
        {
            int ID;

            if (image1 != null)
            {
                stocksImage.StockImage = new byte[image1.ContentLength];
                image1.InputStream.Read(stocksImage.StockImage, 0, image1.ContentLength);

                var id1       = db.CropInfoes.Where(x => x.Name == crop).Select(y => y.CropID).First();
                int cid       = Convert.ToInt16(id1);
                var findStock = db.Stocks.Where(x => x.CropID == cid).Select(y => y.StockID).Count();

                if (findStock > 0)
                {
                    var id2 = db.Stocks.Where(x => x.CropID == cid).Select(y => y.StockID).First();
                    ID = Convert.ToInt16(id2);
                }
                else
                {
                    ViewBag.noStock = "Stock has not yet been created ie. Harvest pending";
                    ViewBag.crop    = new SelectList(db.CropInfoes, "Name", "Name");
                    return(View());
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Please add image");
                return(View(stocksImage));
            }
            if (ModelState.IsValid)
            {
                var imageExists = db.StocksImages.Where(x => x.ImageName == crop).Select(y => y.ImageName).Count();
                if (imageExists > 0)
                {
                    var stockid = db.StocksImages.Where(x => x.ImageName == crop).Select(y => y.StockImageID).First();
                    stocksImage.StockImageID    = Convert.ToInt16(stockid);
                    stocksImage.StockID         = ID;
                    stocksImage.ImageName       = crop;
                    db.Entry(stocksImage).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    stocksImage.StockID   = ID;
                    stocksImage.ImageName = crop;
                    db.StocksImages.Add(stocksImage);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.crop = new SelectList(db.CropInfoes, "Name", "Name");
            //ViewBag.StockID = new SelectList(db.Stocks, "StockID", "StockID", stocksImage.StockID);
            return(View(stocksImage));
        }
Example #2
0
 public ActionResult Edit([Bind(Include = "AccountID,UserName,Password,Type,Disabled")] Account account)
 {
     if (ModelState.IsValid)
     {
         db.Entry(account).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(account));
 }
 public ActionResult Edit([Bind(Include = "MTaskID,TaskName,description,Duration")] TaskMaster taskMaster)
 {
     if (ModelState.IsValid)
     {
         db.Entry(taskMaster).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(taskMaster));
 }
Example #4
0
 public ActionResult Edit([Bind(Include = "PositionID,Name,Description,BaseSalary,Disabled")] Position position)
 {
     if (ModelState.IsValid)
     {
         db.Entry(position).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(position));
 }
Example #5
0
 public ActionResult Edit([Bind(Include = "CropID,Name,Description,Season,Spacing,AverageYield,IrrigationInterval,GrowthTime,LifeExpect,Disabled")] CropInfo cropInfo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cropInfo).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cropInfo));
 }
 public ActionResult Edit([Bind(Include = "GroupID,GName,GDescription")] Group group)
 {
     if (ModelState.IsValid)
     {
         db.Entry(group).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(group));
 }
 public ActionResult Edit([Bind(Include = "FarmID,FarmName,Location,NumWorkers,Description,NumLand,LandArea,Disabled")] Farm farm)
 {
     if (ModelState.IsValid)
     {
         db.Entry(farm).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(farm));
 }
 public ActionResult Edit([Bind(Include = "FieldID,LandID,FieldName,Status,Size,Disabled")] Field field)
 {
     if (ModelState.IsValid)
     {
         db.Entry(field).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.LandID = new SelectList(db.Lands, "LandID", "LandID", field.LandID);
     return(View(field));
 }
 public ActionResult Edit([Bind(Include = "PTaskID,Description,Status,Assigned,StartOn,ExpectedCompletion,CompletedOn,flag,PlantedID")] PlantedTask plantedTask)
 {
     if (ModelState.IsValid)
     {
         db.Entry(plantedTask).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PlantedID = new SelectList(db.Planteds, "PlantedID", "Status", plantedTask.PlantedID);
     return(View(plantedTask));
 }
Example #10
0
 public ActionResult Edit([Bind(Include = "LandID,FarmID,NumFields,Size,Disabled")] Land land)
 {
     if (ModelState.IsValid)
     {
         db.Entry(land).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.FarmID = new SelectList(db.Farms, "FarmID", "FarmName", land.FarmID);
     return(View(land));
 }
        public ActionResult RemoveFromCart(int?id, StockOrder stockorder)
        {
            string name = User.Identity.Name;

            var getAcctId = (from x in db.Accounts
                             where x.UserName == name
                             select x.AccountID).First();

            int accid = Convert.ToInt16(getAcctId);

            var getCustId = (from x in db.Customers
                             where x.AccountID == accid
                             select x.CustomerID).First();

            int customerID = Convert.ToInt16(getCustId);

            //var stockCart = (from x in db.StockOrders
            //                 where x.StockID == id
            //                 select x).ToList();

            stockorder = db.StockOrders.Find(id);

            var    stockQuantity = db.StockOrders.Where(x => x.SOID == id).Select(y => y.Quantity).First();
            double qty           = Convert.ToDouble(stockQuantity);

            if (qty > 1)
            {
                double newQty = qty - 1;
                //stockorder.SOID = Convert.ToInt16(id);
                stockorder.Quantity        = newQty;
                db.Entry(stockorder).State = EntityState.Modified;
                db.SaveChanges();
            }
            else if (qty == 0 || qty == 1)
            {
                StockOrder stockRemove = db.StockOrders.Find(id);
                db.StockOrders.Remove(stockRemove);
                db.SaveChanges();
            }
            return(RedirectToAction("Cart", "Customers"));
        }
Example #12
0
 public ActionResult Edit([Bind(Include = "SaleID,Date,Total,CustomerID,OrderID")] Sale sale)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sale).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "Name", sale.CustomerID);
     ViewBag.OrderID    = new SelectList(db.Orders, "OrderID", "status", sale.OrderID);
     return(View(sale));
 }
Example #13
0
 public ActionResult Edit([Bind(Include = "GTID,PTaskID,EmployeeID")] GroupTask groupTask)
 {
     if (ModelState.IsValid)
     {
         db.Entry(groupTask).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EmployeeID = new SelectList(db.Groups, "GroupID", "GName", groupTask.EmployeeID);
     ViewBag.PTaskID    = new SelectList(db.PlantedTasks, "PTaskID", "Description", groupTask.PTaskID);
     return(View(groupTask));
 }
 public ActionResult Edit([Bind(Include = "PlantedID,Status,FieldID,FieldName,CropID,CropName,QuantityPlanted,PlantedDate,ExpectedHarvestDate,ExpectedYield,LastWatered,NextWater")] Planted planted)
 {
     if (ModelState.IsValid)
     {
         db.Entry(planted).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CropID  = new SelectList(db.CropInfoes, "CropID", "Name", planted.CropID);
     ViewBag.FieldID = new SelectList(db.Fields, "FieldID", "FieldName", planted.FieldID);
     return(View(planted));
 }
Example #15
0
 public ActionResult Edit([Bind(Include = "EmpPosID,EmployeeID,PositionID,Started,Ended")] EmpPos empPos)
 {
     if (ModelState.IsValid)
     {
         db.Entry(empPos).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "Name", empPos.EmployeeID);
     ViewBag.PositionID = new SelectList(db.Positions, "PositionID", "Name", empPos.PositionID);
     return(View(empPos));
 }
Example #16
0
 public ActionResult Edit([Bind(Include = "CTID,MTaskID,CropID,Duration")] CropTask cropTask)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cropTask).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CropID  = new SelectList(db.CropInfoes, "CropID", "Name", cropTask.CropID);
     ViewBag.MTaskID = new SelectList(db.TaskMasters, "MTaskID", "TaskName", cropTask.MTaskID);
     return(View(cropTask));
 }
 public ActionResult Edit([Bind(Include = "FEID,FarmID,EmployeeID,DateStarted,DateEnded")] FarmEmployee farmEmployee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(farmEmployee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "Name", farmEmployee.EmployeeID);
     ViewBag.FarmID     = new SelectList(db.Farms, "FarmID", "FarmName", farmEmployee.FarmID);
     return(View(farmEmployee));
 }
 public ActionResult Edit([Bind(Include = "SOID,OrderID,StockID,Quantity,SubPrice")] StockOrder stockOrder)
 {
     if (ModelState.IsValid)
     {
         db.Entry(stockOrder).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "status", stockOrder.OrderID);
     ViewBag.StockID = new SelectList(db.Stocks, "StockID", "StockID", stockOrder.StockID);
     return(View(stockOrder));
 }
        public ActionResult Edit([Bind(Include = "StockID,CurQuantity,HarQuantity,Harvested,Expiery,ExpFlag,Price,Disabled,CropID,StocksImage")] Stock stock)
        {
            var sImage = db.StocksImages.Select(x => x.ImageName).ToList();

            if (ModelState.IsValid)
            {
                db.Entry(stock).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CropID     = new SelectList(db.CropInfoes, "CropID", "Name", stock.CropID);
            ViewBag.StockImage = new SelectList(db.StocksImages, "StockImageID", "ImageName", sImage);
            return(View(stock));
        }
Example #20
0
        public ActionResult Edit([Bind(Include = "EmployeeID,Name,Surname,IDNumber,DateHired,ContactNum,KinContactNum,Email,FarmID,PositionID,AccountID,GroupID")] Employee employee, int?id)
        {
            var find = (from x in db.Employees
                        where x.EmployeeID == id
                        select x.AccountID).Single();

            employee.AccountID = Convert.ToInt16(find);

            if (ModelState.IsValid)
            {
                db.Entry(employee).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.AccountID  = new SelectList(db.Accounts, "AccountID", "UserName", employee.AccountID);
            ViewBag.FarmID     = new SelectList(db.Farms, "FarmID", "FarmName", employee.FarmID);
            ViewBag.PositionID = new SelectList(db.Positions, "PositionID", "Name", employee.PositionID);
            ViewBag.GroupID    = new SelectList(db.Groups, "GroupID", "GName", employee.GroupID);
            return(View(employee));
        }
        public ActionResult AddToOrders([Bind(Include = "OrderID,status,CustomerID,Total")] Order order, StockViewModel svm)
        {
            //try
            //{
            DateTime today    = DateTime.Now.Date;
            int      stockid  = Convert.ToInt16(svm.StockID);
            int      quantity = Convert.ToInt16(svm.QuantityWanted);
            var      cropvar  = db.Stocks.Where(x => x.StockID == stockid).Select(y => y.CropID).First();
            int      cropid   = Convert.ToInt16(cropvar);
            var      cropname = db.CropInfoes.Where(x => x.CropID == cropid).Select(y => y.Name).First();
            var      price    = db.Stocks.Where(a => a.StockID == stockid).Select(b => b.Price).Single();

            bool check = svm.lowQuantitycheck(quantity);

            if (check == true)
            {
                string name = User.Identity.Name;

                var getAcctId = (from x in db.Accounts
                                 where x.UserName == name
                                 select x.AccountID).First();

                int accid = Convert.ToInt16(getAcctId);

                var getCustId = (from x in db.Customers
                                 where x.AccountID == accid
                                 select x.CustomerID).First();

                int customerID = Convert.ToInt16(getCustId);

                order.CustomerID = customerID;

                var findCust = db.Customers.Where(a => a.CustomerID == order.CustomerID).Select(b => b.CustomerID).Count();

                var checkCustOrders = db.Orders.Where(a => a.CustomerID == order.CustomerID).Select(b => b.OrderID).Count();

                var oDate = db.Orders.Where(a => a.CustomerID == order.CustomerID).OrderByDescending(x => x.OrderID).Select(b => b.DateOfOrder).Count();

                // DateTime orderDate = Convert.ToDateTime(oDate);

                order.DateOfOrder = today;

                if (checkCustOrders > 0 && oDate > 0)
                {
                    var oId = db.Orders.Where(a => a.CustomerID == order.CustomerID).OrderByDescending(x => x.OrderID).Select(b => b.OrderID).First();

                    var total = db.Orders.Where(a => a.CustomerID == order.CustomerID).OrderByDescending(x => x.OrderID).Select(b => b.Total).First();
                    order.OrderID = Convert.ToInt16(oId);

                    order.Total  = (Convert.ToDouble(price) * quantity) + Convert.ToDouble(total);
                    order.status = "Pending";

                    db.Entry(order).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    order.Total  = (Convert.ToDouble(price)) * quantity;
                    order.status = "Pending";

                    db.Orders.Add(order);
                    db.SaveChanges();
                }

                int stockID = Convert.ToInt16(stockid);

                var subPrice = db.Stocks.Where(x => x.StockID == stockID).Select(s => s.Price).Single();

                StockOrder so = new StockOrder();
                so.StockID  = stockID;
                so.OrderID  = order.OrderID;
                so.Quantity = quantity;
                so.SubPrice = Convert.ToInt16(subPrice);

                StockOrdersController soc = new StockOrdersController();
                soc.AddStockOrders(so);

                Stock st = new Stock();
                st.stockDeduct(so.Quantity, stockid);

                TempData["SuccessMessage"] = quantity + " " + cropname + " successfully added to orders";

                return(RedirectToAction("Store", "Stocks"));
            }
            else
            {
                TempData["lessQuantityMessage"] = "Selected Quantity not available";
                return(RedirectToAction("Store", "Stocks"));
            }
            //}
            //catch
            //{
            //    return Content("Failed");
            //}
        }