public ViewResult ConsumptionReportHerdDay(DateTime day)
        {
            List<ConsumptionReportHerd> report = new List<ConsumptionReportHerd>();

            Herd aux = new Herd();

            Milker aux1 = new Milker();

            Cow aux2 = new Cow();

            List<Cow> cows = new List<Cow>();

            Production production = new Production();

            var Herd = from h in db.Herds.ToList() select h;

            var Milker = from o in db.Milkers.ToList() select o;

            //var Cow = from c in a.Cows.ToList() select c;

            foreach (Herd h in Herd)
            {
                ConsumptionReportHerd item = new ConsumptionReportHerd();
                Double hay = new Double();
                Double Silage = new Double();

                item.IdHerd = h.Id;
                item.NameHerd = h.Name;
                item.HowCows = h.Cows.Count();
                foreach (Milker o in Milker)
                {
                    aux1.Name = o.Name;

                }
                item.NameOpe = aux1.Name;

                cows = h.Cows;

                foreach (Cow c in cows)
                {
                    var query = from co in db.Consumptions.ToList()
                                where co.Id == c.Id && co.Date == day && c.State.Equals('A')
                                select co;

                    foreach (Consumption co in query)
                    {
                        hay = hay + co.HayAmount;
                        Silage = Silage + co.SilageAmout;

                    }

                    item.HayAmount = hay;
                    item.SilageAmout = Silage;
                }

                report.Add(item);
            }

            return View(report);
        }
        public ActionResult Create(Production production)
        {
            if (ModelState.IsValidField("Date") && DateTime.Now < production.Date)
                ModelState.AddModelError("Date", "Input a current or past date");
            if (ModelState.IsValid)
            {
                db.Productions.Add(production);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CowId = new SelectList(db.Cows, "Id", "Name", production.CowId);
            return View(production);
        }
        public ViewResult ConsumptionReportCowMonth(DateTime Month)
        {
            List<ConsumptionReportCow> report = new List<ConsumptionReportCow>();

            Cow aux = new Cow();

            Production production = new Production();

            var cows = from c in db.Cows.ToList() select c;

            //var Consumption = from co in a.Consumptions.ToList() select co;

            foreach (Cow c in cows)
            {
                ConsumptionReportCow item = new ConsumptionReportCow();
                Double Hay = new Double();
                Double Silage = new Double();
                item.IdCow = c.Id;
                item.NameCow = c.Name;
                //var resultPro = Consumption.Where(p => p.CowId.Equals(c.Id));

                var query = from co in db.Consumptions.ToList()
                            where co.Id == c.Id && co.Date.Month.Equals(Month.Month) && co.Date.Month.Equals(Month.Year) && c.State.Equals('A')
                            select co;

                foreach (Consumption co in query)
                {
                    Hay = Hay + co.HayAmount;
                    Silage = Silage + co.SilageAmout;
                }
                item.HayAmount = Hay;
                item.SilageAmout = Silage;
                report.Add(item);
            }
            return View(report);
        }
 public ActionResult Edit(Production production)
 {
     if (ModelState.IsValid)
     {
         db.Entry(production).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.CowId = new SelectList(db.Cows, "Id", "Name", production.CowId);
     return View(production);
 }
        public ViewResult ProductionReportHerdMonth(DateTime Month)
        {
            List<ProductionReportHerd> report = new List<ProductionReportHerd>();

            Herd aux = new Herd();

            Milker aux1 = new Milker();

            Cow aux2 = new Cow();

            List<Cow> cows = new List<Cow>();

            Production production = new Production();

            var Herd = from h in db.Herds.ToList() select h;

            var Milker = from o in db.Milkers.ToList() select o;

            //var Cow = from c in a.Cows.ToList() select c;

            foreach (Herd h in Herd)
            {
                ProductionReportHerd item = new ProductionReportHerd();
                Double quant = new Double();
                item.IdHerd = h.Id;
                item.NameHerd = h.Name;
                foreach (Milker o in Milker)
                {
                    aux1.Name = o.Name;

                }
                item.NameOpe = aux1.Name;

                cows = h.Cows;

                foreach (Cow c in cows)
                {
                    var query = from co in db.Productions.ToList()
                                where co.Id == c.Id && c.State.Equals('A') && co.Date.Month.Equals(Month.Month) && co.Date.Year.Equals(Month.Year) && c.State.Equals('A')
                                select co;

                    foreach (Production p in query)
                    {
                        quant = quant + p.Quant;
                    }

                    quant = quant / (query.ToList<Production>().Count);
                }

                report.Add(item);
            }

            return View(report);
        }
        public ViewResult ProductionReportCowMonth(string month, string year)
        {
            DateTime Month = new DateTime(Int32.Parse(year), Int32.Parse(month), 1);
            List<ProductionReportCow> report = new List<ProductionReportCow>();
            Cow aux = new Cow();
            Production production = new Production();

            var cows = from c in db.Cows.ToList() select c;
            var cowsq = from c in cows.ToList()
                        where c.State == "A"
                        select c;

            foreach (Cow c in cowsq)
            {
                ProductionReportCow item = new ProductionReportCow();
                Double sum = new Double();
                item.IdCow = c.Id;
                item.NameCow = c.Name;
                // var resultPro = productions.Where(p => p.CowId.Equals(c.Id));

                var query = from p in db.Productions
                            where   p.CowId == c.Id &&
                                    p.Date.Month == Month.Month &&
                                    p.Date.Year == Month.Year
                            select p;

                foreach (Production p in query)
                    sum += p.Quant;

                item.Quant = sum;
                report.Add(item);
            }
            return View(report);
        }