//Method to get number of animals currently in feeding lots
        private static int CalcAniFeeding(FeedingSchemeView model)
        {
            AnimalBusiness aniBl       = new AnimalBusiness();
            BatchTypeBl    batchTypeBl = new BatchTypeBl();
            var            bDesc       = batchTypeBl.GetAllBatchTypes().Find(x => x.BatchTypeid == model.BatchTypeid);

            return(aniBl.GetAllAnimals().Count(animalpar => animalpar.AniFeedingStatus == "FeedLot" &&
                                               animalpar.BatchTypeDesc == bDesc.BatchTypeDesc));
        }
        public ActionResult AddFeedingScheme(FeedingSchemeView model)
        {
            if (ModelState.IsValid)
            {
                ViewBag.BatchTypeid = new SelectList(_bTypeBl.GetAllBatchTypes(), "BatchTypeid", "BatchTypeDesc");
                _fSchemeBl.AddFeedScheme(model);
                return(RedirectToAction("GetAllSchemes"));
            }

            return(View());
        }
        public void DeleteFeedScheme(FeedingSchemeView model)
        {
            using (var feedSchemeRepo = new FeedingSchemeRepository())
            {
                FeedingScheme feed = feedSchemeRepo.GetById(model.FeedingSchemeId);

                if (feed != null)
                {
                    feedSchemeRepo.Delete(feed);
                }
            }
        }
        public void AddFeedScheme(FeedingSchemeView model)
        {
            var    datePre = DateTime.Today;
            Random rand    = new Random();

            using (var feedSchemeRepo = new FeedingSchemeRepository())
            {
                var feed = new FeedingScheme()
                {
                    FeedingSchemeId   = model.FeedingSchemeId,
                    BatchTypeid       = _bTypeRepo.GetAll().ToList().Find(x => x.BatchTypeid == model.BatchTypeid).BatchTypeid,
                    NoOfAnimals       = CalcAniFeeding(model),
                    DatePrepared      = datePre,
                    SchemeCode        = datePre.DayOfYear + "#SC#" + CalcAniFeeding(model) + "#" + rand.Next(1, 1000000),
                    FeedCostPerAnimal = 0,
                    TotalFeedingCost  = 0,
                    NumberOfItems     = 0
                };
                feedSchemeRepo.Insert(feed);
            }
        }
        public int IngredientCount(FeedingSchemeView model)
        {
            PercentageBl percBl = new PercentageBl();

            return(percBl.GetAllIngredients().Count(j => j.SchemeCode == model.SchemeCode));
        }