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 ProductionReportHerdDay(DateTime dayp) { List<ProductionReportHerd> report = new List<ProductionReportHerd>(); var Herd = from h in db.Herds.Include(h => h.Cows).ToList() where h.State == "A" select h; //var Cow = from c in a.Cows.ToList() select c; foreach (Herd h in Herd) { ProductionReportHerd item = new ProductionReportHerd(); item.IdHerd = h.Id; item.NameHerd = h.Name; var milker = from m in db.Milkers.ToList() where m.Id == h.MilkerId && m.State == "A" select m; Milker mi = milker.Single(); item.NameOpe = mi.Name; List<Cow> cows = h.Cows; Double quant = 0.0; foreach (Cow c in cows) { quant = new Double(); var query = from pro in db.Productions.ToList() where pro.CowId == c.Id && pro.Date == dayp && c.State == "A" select pro; foreach (Production p in query) { quant = quant + p.Quant; } item.Quant += quant; } if(item.Quant>0) report.Add(item); } return View(report); }