Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            CategoryCost categoryCost = db.CategoryCosts.Find(id);

            db.CategoryCosts.Remove(categoryCost);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "C_ID,CategoryId,BasicCost,CostPerKG")] CategoryCost categoryCost)
        {
            if (ModelState.IsValid)
            {
                db.CategoryCosts.Add(categoryCost);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryType", categoryCost.CategoryId);
            return(View(categoryCost));
        }
Beispiel #4
0
        // GET: CategoryCosts/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CategoryCost categoryCost = db.CategoryCosts.Find(id);

            if (categoryCost == null)
            {
                return(HttpNotFound());
            }
            return(View(categoryCost));
        }
Beispiel #5
0
        // GET: CategoryCosts/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CategoryCost categoryCost = db.CategoryCosts.Find(id);

            if (categoryCost == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryType", categoryCost.CategoryId);
            return(View(categoryCost));
        }
Beispiel #6
0
        public List <LivesStock> LivestocksInCategory(List <LivesStock> list, CategoryCost categoryCost)
        {
            List <LivesStock> refinedList = new List <LivesStock>();
            int count = list.Count;

            while (count > 0)
            {
                if (list[count - 1].CategoryId == categoryCost.CategoryId)
                {
                    refinedList.Add(list[count - 1]);
                }
                count--;
            }
            return(refinedList);
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
        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));
        }
Beispiel #9
0
 public decimal calcSellingPrice(CategoryCost categoryCost)
 {
     return((Weight * categoryCost.CostPerKG) + categoryCost.BasicCost);
 }