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(Milker milker)
        {
            milker.State = "A";
            if (ModelState.IsValid)
            {
                db.Milkers.Add(milker);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(milker);
        }
        public ActionResult Create(Milker milker)
        {
            milker.State = "A";
            if (ModelState.IsValidField("JoinDate") && DateTime.Now < milker.JoinDate)
                ModelState.AddModelError("JoinDate", "Input a current or past date");
            if (milker.Age > 60 || milker.Age < 18)
                ModelState.AddModelError("Age", "The age of the milker is not appropiate for job");
            if (ModelState.IsValid)
            {
                db.Milkers.Add(milker);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(milker);
        }
        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 ActionResult Edit(Milker milker)
 {
     if (ModelState.IsValid)
     {
         db.Entry(milker).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(milker);
 }