// GET: LiveStocTrack public ActionResult Index(int id) { LivesStock livesStock = db.LivesStocks.Find(id); LiveStockWeight liveStockWeight = new LiveStockWeight(); List <LiveStockWeight> list = liveStockWeight.ValidWeights(db.LiveStockWeights.ToList(), id); List <DataPoint> dataPoints1 = new List <DataPoint>(); List <DataPoint> dataPoints2 = new List <DataPoint>(); List <DataPoint> dataPoints3 = new List <DataPoint>(); for (int i = 0; i < list.Count; i++) { dataPoints1.Add(new DataPoint(list[i].Date.ToString(), Convert.ToDouble(list[i].Weight))); } //dataPoints1.Add(new DataPoint("Jan", 72)); //dataPoints1.Add(new DataPoint("Feb", 67)); //dataPoints1.Add(new DataPoint("Mar", 55)); //dataPoints1.Add(new DataPoint("Apr", 42)); //dataPoints1.Add(new DataPoint("May", 40)); //dataPoints1.Add(new DataPoint("Jun", 35)); //dataPoints1.Add(new DataPoint("July", 80)); //dataPoints1.Add(new DataPoint("Aug", 32)); //dataPoints1.Add(new DataPoint("Sept", 45)); //dataPoints1.Add(new DataPoint("Oct", 33)); //dataPoints1.Add(new DataPoint("Nov", 63)); //dataPoints1.Add(new DataPoint("Dec", 49)); //dataPoints2.Add(new DataPoint("Jan", 48)); //dataPoints2.Add(new DataPoint("Feb", 56)); //dataPoints2.Add(new DataPoint("Mar", 50)); //dataPoints2.Add(new DataPoint("Apr", 47)); //dataPoints2.Add(new DataPoint("May", 65)); //dataPoints2.Add(new DataPoint("Jun", 69)); //dataPoints2.Add(new DataPoint("July", 72)); //dataPoints2.Add(new DataPoint("Aug", 76)); //dataPoints2.Add(new DataPoint("Sept", 56)); //dataPoints2.Add(new DataPoint("Oct", 83)); //dataPoints2.Add(new DataPoint("Nov", 58)); //dataPoints2.Add(new DataPoint("Dec", 44)); //dataPoints3.Add(new DataPoint("Jan", 38)); //dataPoints3.Add(new DataPoint("Feb", 46)); //dataPoints3.Add(new DataPoint("Mar", 55)); //dataPoints3.Add(new DataPoint("Apr", 70)); //dataPoints3.Add(new DataPoint("May", 77)); //dataPoints3.Add(new DataPoint("Jun", 91)); //dataPoints3.Add(new DataPoint("July", 76)); //dataPoints3.Add(new DataPoint("Aug", 63)); //dataPoints3.Add(new DataPoint("Sept", 46)); //dataPoints3.Add(new DataPoint("Oct", 43)); //dataPoints3.Add(new DataPoint("Nov", 66)); //dataPoints3.Add(new DataPoint("Dec", 87)); ViewBag.DataPoints1 = JsonConvert.SerializeObject(dataPoints1); ViewBag.DataPoints2 = JsonConvert.SerializeObject(dataPoints2); ViewBag.DataPoints3 = JsonConvert.SerializeObject(dataPoints3); ViewBag.Code = livesStock.Code; return(View()); }
public ActionResult DeleteConfirmed(int id) { LivesStock livesStock = db.LivesStocks.Find(id); db.LivesStocks.Remove(livesStock); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(LivesStock livestock) { LivestockImage livestockImage = new LivestockImage(); //links the image to be uploaded, with the selected livestock livestockImage.LivestockID = livestock.LivestockID; //takes the livestockImage with the livestockID to the image upload screen return(View(livestockImage)); }
public ActionResult Create([Bind(Include = "LivestockID,CategoryId,Weight,BatchID,DateOfBirth,Sex,CostPrice")] LivesStock livesStock, HttpPostedFileBase img_upload) { livesStock.sold = false; livesStock.addedtocart = false; byte[] data = null; data = new byte[img_upload.ContentLength]; img_upload.InputStream.Read(data, 0, img_upload.ContentLength); livesStock.Picture = data; if (ModelState.IsValid) { Category category = db.Categories.Find(livesStock.CategoryId); db.LivesStocks.Add(livesStock); if (livesStock.BatchID != null) { //Decrement the number of uncreated livestock for that batch db.Batches.Find(livesStock.BatchID).UncreatedQuantity--; } db.SaveChanges(); livesStock.Code = livesStock.GenerateCode(category); db.Entry(livesStock).State = EntityState.Modified; LiveStockWeight liveStockWeight = new LiveStockWeight(); liveStockWeight.LivestockID = livesStock.LivestockID; liveStockWeight.Date = liveStockWeight.EntryDate(); liveStockWeight.Weight = livesStock.Weight; db.LiveStockWeights.Add(liveStockWeight); db.SaveChanges(); // livesStock.Weight = liveStockWeight.Weight; CategoryCost categoryCost = new CategoryCost(); livesStock.SellingPrice = livesStock.calcSellingPrice(categoryCost.ValidategoryCost(db.CategoryCosts.ToList(), livesStock.CategoryId)); db.Entry(livesStock).State = EntityState.Modified; db.SaveChanges(); if (livesStock.BatchID != null) { //check whether there are still any ucreated livestock for that batch if (db.Batches.Find(livesStock.BatchID).UncreatedQuantity > 0) { //if there are, return to the livestock create screen return(RedirectToAction("Create", db.Batches.Find(livesStock.BatchID))); } } TempData["Message"] = "<script>alert('Livestock added!');</script>"; return(RedirectToAction("Index")); } Batch batch = new Batch(); List <Batch> batches = db.Batches.ToList <Batch>(); ViewBag.BatchID = new SelectList(batch.ValidBatch(batches), "BatchID", "BatchCode"); ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryType", livesStock.CategoryId); return(View(livesStock)); }
public bool add(LivesStock model) { try { db.LivesStocks.Add(model); db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool delete(LivesStock model) { try { db.LivesStocks.Remove(model); db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool edit(LivesStock model) { try { db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
// GET: LivesStocks/Create public ActionResult Create(Batch batch) { ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryType"); LivesStock livestock = new LivesStock(); livestock.BatchID = batch.ID; if (batch == null) { livestock.BatchID = null; } return(View(livestock)); }
public ActionResult Edit([Bind(Include = "ID,CategoryId,BatchID,Weight,Age,Gender,Image,CostPrice")] LivesStock livesStock) { if (ModelState.IsValid) { db.Entry(livesStock).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BatchID = new SelectList(db.Batches, "ID", "ID", livesStock.BatchID); ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryType", livesStock.CategoryId); return(View(livesStock)); }
// GET: LivesStocks/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LivesStock livesStock = db.LivesStocks.Find(id); if (livesStock == null) { return(HttpNotFound()); } return(View(livesStock)); }
//[Authorize(Roles = "Stock Controller")] public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LivesStock livesStock = db.LivesStocks.Find(id); if (livesStock == null) { return(HttpNotFound()); } // ViewBag.BatchID = new SelectList(db.Batches, "BatchID", "BatchCode", livesStock.BatchID); //ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryType", livesStock.CategoryId); return(View(livesStock)); }
public ActionResult Edit([Bind(Include = "LivestockID,CategoryId,Weight,BatchID,DateOfBirth,Sex,CostPrice,SellingPrice,Code")] LivesStock livesStock, HttpPostedFileBase img_upload) { byte[] data = null; data = new byte[img_upload.ContentLength]; img_upload.InputStream.Read(data, 0, img_upload.ContentLength); livesStock.Picture = data; if (ModelState.IsValid) { db.Entry(livesStock).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BatchID = new SelectList(db.Batches, "BatchID", "BatchCode", livesStock.BatchID); ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryType", livesStock.CategoryId); return(View(livesStock)); }
public ActionResult Create([Bind(Include = "LiveStockWeightID,LivestockID,Weight,Date")] LiveStockWeight liveStockWeight) { if (ModelState.IsValid) { liveStockWeight.Date = liveStockWeight.EntryDate(); db.LiveStockWeights.Add(liveStockWeight); db.SaveChanges(); LivesStock livesStock = db.LivesStocks.Find(liveStockWeight.LivestockID); livesStock.Weight = liveStockWeight.Weight; CategoryCost categoryCost = new CategoryCost(); livesStock.SellingPrice = livesStock.calcSellingPrice(categoryCost.ValidategoryCost(db.CategoryCosts.ToList(), livesStock.CategoryId)); db.Entry(livesStock).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LivestockID = new SelectList(db.LivesStocks, "LivestockID", "Code", liveStockWeight.LivestockID); return(View(liveStockWeight)); }
// GET: LivesStocks/Create //[Authorize(Roles = "Stock Controller")] public ActionResult AutoCreate(Batch batch) { //loop this create process as many times as there are livestock in the batch for (int i = 0; i < batch.Quantity; i++) { Category category = db.Categories.Find(batch.CategoryID); //use the constructor to create default livestock //using correct batch number and correct category LivesStock livestock = new LivesStock(batch, category); livestock.DateOfBirth = DateTime.Now; db.LivesStocks.Add(livestock); db.SaveChanges(); livestock.Code = livestock.GenerateCode(category); db.Entry(livestock).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
public void remove_item_from_cart(string id) { shoppingCartID = GetCartID(); var item = db.Cart_Items.Find(id); if (item != null) { var cartItem = db.Cart_Items.FirstOrDefault(predicate: x => x.cart_id == shoppingCartID && x.item_id == item.item_id); if (cartItem != null) { db.Cart_Items.Remove(entity: cartItem); LivesStock livesStock = db.LivesStocks.Find(item.item_id); livesStock.addedtocart = false; db.Entry(item).State = EntityState.Modified; } db.SaveChanges(); } }
public ActionResult Edit([Bind(Include = "C_ID,CategoryId,BasicCost,CostPerKG")] CategoryCost categoryCost) { if (ModelState.IsValid) { db.Entry(categoryCost).State = EntityState.Modified; db.SaveChanges(); LivesStock livesStock = new LivesStock(); List <LivesStock> listLivestocks = livesStock.LivestocksInCategory(db.LivesStocks.ToList(), categoryCost); for (int i = 0; i < listLivestocks.Count; i++) { livesStock = listLivestocks[i]; livesStock.SellingPrice = livesStock.calcSellingPrice(categoryCost); db.Entry(livesStock).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryType", categoryCost.CategoryId); return(View(categoryCost)); }
public ActionResult Create([Bind(Include = "ID,CategoryId,BatchID,Weight,Age,Gender,Image,CostPrice")] LivesStock livesStock) { if (ModelState.IsValid) { db.LivesStocks.Add(livesStock); if (livesStock.BatchID != null) { db.Batches.Find(livesStock.BatchID).Quantity--; } db.SaveChanges(); if (livesStock.BatchID != null) { if (db.Batches.Find(livesStock.BatchID).Quantity > 0) { return(RedirectToAction("Create", db.Batches.Find(livesStock.BatchID))); } } return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryType", livesStock.CategoryId); return(View(livesStock)); }
public ActionResult PlaceOrder(string id) { var customer = db.Customers.ToList().Find(x => x.Email == HttpContext.User.Identity.Name); db.Orders.Add(new Order() { Email = customer.Email, date_created = DateTime.Now, shipped = false, status = "Awaiting Payment" }); db.SaveChanges(); var order = db.Orders.ToList() .FindAll(x => x.Email == HttpContext.User.Identity.Name) .LastOrDefault(); if (id == "deliver") { db.Order_Addresses.Add(new Order_Address() { Order_ID = order.Order_ID, street = Session["Street"].ToString(), city = Session["City"].ToString(), zipcode = Session["PostalCode"].ToString() }); db.SaveChanges(); } else if (id == "Same") { var cus = db.Customers.ToList().Find(x => x.Email == HttpContext.User.Identity.Name); db.Order_Addresses.Add(new Order_Address() { Order_ID = order.Order_ID, street = cus.address, city = cus.City, zipcode = cus.PostalCode }); db.SaveChanges(); } var items = get_Cart_Items(); foreach (var item in items) { var x = new Order_Item() { Order_id = order.Order_ID, LivestockID = item.item_id, quantity = item.quantity, price = item.price }; LivesStock itemAlia = (from i in db.LivesStocks where i.LivestockID == x.LivestockID select i).Single(); // itemAlia.QuantityInStock -= x.quantity; db.Entry(itemAlia).State = EntityState.Modified; db.Order_Items.Add(x); db.SaveChanges(); } empty_Cart(); //order tracking db.Order_Trackings.Add(new Order_Tracking() { order_ID = order.Order_ID, date = DateTime.Now, status = "Awaiting Payment", Recipient = "" }); db.SaveChanges(); //Redirect to payment return(RedirectToAction("Payment", new { id = order.Order_ID })); }