public void AddSale([Bind(Include = "SaleID,Date,Total,CustomerID,OrderID")] Sale sale) { if (ModelState.IsValid) { db.Sales.Add(sale); db.SaveChanges(); } }
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)); }
public ActionResult Create([Bind(Include = "PositionID,Name,Description,BaseSalary,Disabled")] Position position) { if (ModelState.IsValid) { db.Positions.Add(position); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(position)); }
public ActionResult Create([Bind(Include = "GroupID,GName,GDescription")] Group group) { if (ModelState.IsValid) { db.Groups.Add(group); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(group)); }
public ActionResult Create([Bind(Include = "CropID,Name,Description,Season,Spacing,AverageYield,IrrigationInterval,GrowthTime,LifeExpect,Disabled")] CropInfo cropInfo) { if (ModelState.IsValid) { db.CropInfoes.Add(cropInfo); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cropInfo)); }
public ActionResult Create([Bind(Include = "FarmID,FarmName,Location,NumWorkers,Description,NumLand,LandArea,Disabled")] Farm farm) { if (ModelState.IsValid) { db.Farms.Add(farm); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(farm)); }
public ActionResult Create([Bind(Include = "MTaskID,TaskName,description,Duration")] TaskMaster taskMaster) { if (ModelState.IsValid) { db.TaskMasters.Add(taskMaster); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(taskMaster)); }
public ActionResult Create([Bind(Include = "FieldID,LandID,FieldName,Status,Size,Disabled")] Field field) { if (ModelState.IsValid) { db.Fields.Add(field); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LandID = new SelectList(db.Lands, "LandID", "LandID", field.LandID); return(View(field)); }
public ActionResult Create([Bind(Include = "StockID,CurQuantity,HarQuantity,Harvested,Expiery,ExpFlag,Price,Disabled,CropID")] Stock stock) { if (ModelState.IsValid) { db.Stocks.Add(stock); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CropID = new SelectList(db.CropInfoes, "CropID", "Name", stock.CropID); return(View(stock)); }
public ActionResult Create([Bind(Include = "PTaskID,Description,Status,Assigned,StartOn,ExpectedCompletion,CompletedOn,flag,PlantedID")] PlantedTask plantedTask) { if (ModelState.IsValid) { db.PlantedTasks.Add(plantedTask); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PlantedID = new SelectList(db.Planteds, "PlantedID", "Status", plantedTask.PlantedID); return(View(plantedTask)); }
public ActionResult Create([Bind(Include = "LandID,FarmID,NumFields,Size,Disabled")] Land land) { if (ModelState.IsValid) { db.Lands.Add(land); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FarmID = new SelectList(db.Farms, "FarmID", "FarmName", land.FarmID); return(View(land)); }
public ActionResult Create([Bind(Include = "GTID,PTaskID,EmployeeID")] GroupTask groupTask) { if (ModelState.IsValid) { db.GroupTasks.Add(groupTask); 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 Create([Bind(Include = "EmpPosID,EmployeeID,PositionID,Started,Ended")] EmpPos empPos) { if (ModelState.IsValid) { db.EmpPos.Add(empPos); 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)); }
public ActionResult Create([Bind(Include = "PlantedID,Status,FieldID,FieldName,CropID,CropName,QuantityPlanted,PlantedDate,ExpectedHarvestDate,ExpectedYield,LastWatered,NextWater")] Planted planted) { if (ModelState.IsValid) { db.Planteds.Add(planted); 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)); }
public ActionResult Create([Bind(Include = "FEID,FarmID,EmployeeID,DateStarted,DateEnded")] FarmEmployee farmEmployee) { if (ModelState.IsValid) { db.FarmEmployees.Add(farmEmployee); 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 Create([Bind(Include = "CTID,MTaskID,CropID,Duration")] CropTask cropTask) { if (ModelState.IsValid) { db.CropTasks.Add(cropTask); 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 ClearCart() { 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 join y in db.Orders on x.OrderID equals y.OrderID where y.CustomerID == customerID select x.SOID).ToList(); foreach (var item in stockCart) { int id = Convert.ToInt16(item); StockOrder stockRemove = db.StockOrders.Find(id); db.StockOrders.Remove(stockRemove); db.SaveChanges(); } return(RedirectToAction("Cart", "Customers")); }
public ActionResult AddStockOrders([Bind(Include = "SOID,OrderID,StockID,Quantity,SubPrice")] StockOrder stockOrder) { try { db.StockOrders.Add(stockOrder); db.SaveChanges(); ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "status", stockOrder.OrderID); ViewBag.StockID = new SelectList(db.Stocks, "StockID", "StockID", stockOrder.StockID); return(RedirectToAction("Index")); } catch { ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "status", stockOrder.OrderID); ViewBag.StockID = new SelectList(db.Stocks, "StockID", "StockID", stockOrder.StockID); return(View(stockOrder)); } //ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "status", stockOrder.OrderID); // ViewBag.StockID = new SelectList(db.Stocks, "StockID", "StockID", stockOrder.StockID); }
public ActionResult Create([Bind(Include = "AccountID,UserName,Password,Type,Disabled")] Account account) { if (ModelState.IsValid) { db.Accounts.Add(account); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(account)); }
public ActionResult AddEmployee([Bind(Include = "EmployeeID,Name,Surname,IDNumber,DateHired,ContactNum,KinContactNum,Email,FarmID,PositionID,GroupID,UserName,Password,ConfirmPassword,Type")] EmployeeAccountsViewModel employeeAccounts) { // employeeAccounts.Type = "Employee"; if (ModelState.IsValid) { try { // add employee account to account table var varBefore = db.Accounts.Select(x => x.AccountID).Count(); int before = Convert.ToInt16(varBefore); Account account = new Account(); account.UserName = employeeAccounts.UserName; account.Password = employeeAccounts.Password; account.ConfirmPassword = employeeAccounts.ConfirmPassword; db.Accounts.Add(account); db.SaveChanges(); //Acc ID var accFind = db.Accounts.Where(x => x.UserName == account.UserName).Select(y => y.AccountID).Single(); int accId = Convert.ToInt16(accFind); // add employee details to employee table var varAfter = db.Accounts.Select(x => x.AccountID).Count(); int after = Convert.ToInt16(varAfter); var beforeEmployeeIsAdded = db.Employees.Select(x => x.EmployeeID).Count(); if (before < after) { int positionId = employeeAccounts.PositionID; int farmId = employeeAccounts.FarmID; int groupId = employeeAccounts.GroupID; Employee employees = new Employee(); //employees.Account = new Account(); //employees.Position = new Position(); employees.EmployeeID = employeeAccounts.EmployeeID; employees.Email = employeeAccounts.Email; employees.Name = employeeAccounts.Name; employees.Surname = employeeAccounts.Surname; employees.AccountID = accId; employees.KinContactNum = employeeAccounts.KinContactNum; employees.IDNumber = employeeAccounts.IDNumber; employees.ContactNum = employeeAccounts.ContactNum; employees.DateHired = employeeAccounts.DateHired; DateTime hired = employeeAccounts.DateHired; employees.PositionID = positionId; employees.FarmID = farmId; employees.GroupID = groupId; // employees.Account.UserName = employeeAccounts.UserName; db.Employees.Add(employees); db.SaveChanges(); var checkEmp = db.Employees.Select(x => x.EmployeeID).Count(); if (beforeEmployeeIsAdded < checkEmp) { EmpPos employeePosition = new EmpPos(); employeePosition.EmployeeID = employees.EmployeeID; employeePosition.Started = hired; employeePosition.PositionID = positionId; employeePosition.Ended = null; db.EmpPos.Add(employeePosition); db.SaveChanges(); return(RedirectToAction("Index")); } } } catch (Exception ex) { // undo account commit if employee transaction fails var acc = db.Accounts.Where(x => x.UserName == employeeAccounts.UserName).Select(y => y.AccountID).Single(); int ac = Convert.ToInt16(acc); AccountsController emp = new AccountsController(); emp.DeleteConfirmed(ac); ViewBag.FarmID = new SelectList(db.Farms, "FarmID", "FarmName", employeeAccounts.FarmID); ViewBag.PositionID = new SelectList(db.Positions, "PositionID", "Name", employeeAccounts.PositionID); ViewBag.GroupID = new SelectList(db.Groups, "GroupID", "GName", employeeAccounts.GroupID); ViewBag.fatalError = ex.ToString(); return(View(employeeAccounts)); } } ViewBag.FarmID = new SelectList(db.Farms, "FarmID", "FarmName", employeeAccounts.FarmID); ViewBag.PositionID = new SelectList(db.Positions, "PositionID", "Name", employeeAccounts.PositionID); ViewBag.GroupID = new SelectList(db.Groups, "GroupID", "GName", employeeAccounts.GroupID); return(View(employeeAccounts)); }
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"); //} }