private void UpdateProductionTotalYield(FarmYieldDTO uDto) { var pr = new ProductionTotalRepository(); var prod = new ProductionTotal(); var prodexists = pr.GetByDateAndPond(DateTime.Parse(uDto.YieldDate), int.Parse(uDto.PondID)); decimal ay = 0; var y1 = uDto.PercentYield == null ? 0 : decimal.Parse(uDto.PercentYield); var y2 = uDto.PercentYield2 == null ? 0 : decimal.Parse(uDto.PercentYield2); if (y1 > 0 || y2 > 0) { if (y2 > 0) { if (y1 > 0) { ay = (y1 + y2) / 2; } else { ay = y2; } } else { ay = y1; } } if (prodexists == null) { prod.PondId = int.Parse(uDto.PondID); prod.ProductionDate = DateTime.Parse(uDto.YieldDate); prod.AverageYield = ay; pr.Save(prod); } else { prod = prodexists; var fyr = new FarmYieldRepository(); List <FarmYield> fyl = fyr.GetByDateAndPond(DateTime.Parse(uDto.YieldDate), int.Parse(uDto.PondID)); int fycount = fyl.Where(x => x.PercentYield != null).Count(); int fycount2 = fyl.Where(x => x.PercentYield2 != null).Count(); decimal fysum1 = fyl.Where(x => x.PercentYield != null).Sum(x => x.PercentYield).Value; decimal fysum2 = fyl.Where(x => x.PercentYield2 != null).Sum(x => x.PercentYield2).Value; prod.AverageYield = (fysum1 + fysum2) / (fycount + fycount2); //if (prod.AverageYield == null) //{ // prod.AverageYield = ay; //} //else //{ // prod.AverageYield = (prod.AverageYield + ay) / 2; //} pr.Save(prod); } }
private void UpdateProductionTotalYield(FarmYieldDTO uDto) { var pr = new ProductionTotalRepository(); var prod = new ProductionTotal(); var prodexists = pr.GetByDateAndPond(DateTime.Parse(uDto.YieldDate), int.Parse(uDto.PondID)); decimal ay = 0; var y1 = uDto.PercentYield == null ? 0 : decimal.Parse(uDto.PercentYield); var y2 = uDto.PercentYield2 == null ? 0 : decimal.Parse(uDto.PercentYield2); if (y1 > 0 || y2 > 0) { if (y2 > 0) { if (y1 > 0) { ay = (y1 + y2) / 2; } else { ay = y2; } } else { ay = y1; } } if (prodexists == null) { prod.PondId = int.Parse(uDto.PondID); prod.ProductionDate = DateTime.Parse(uDto.YieldDate); prod.AverageYield = ay; pr.Save(prod); } else { prod = prodexists; var fyr = new FarmYieldRepository(); List<FarmYield> fyl = fyr.GetByDateAndPond(DateTime.Parse(uDto.YieldDate), int.Parse(uDto.PondID)); int fycount = fyl.Where(x => x.PercentYield != null).Count(); int fycount2 = fyl.Where(x => x.PercentYield2 != null).Count(); decimal fysum1 = fyl.Where(x => x.PercentYield != null).Sum(x => x.PercentYield).Value; decimal fysum2 = fyl.Where(x => x.PercentYield2 != null).Sum(x => x.PercentYield2).Value; prod.AverageYield = (fysum1 + fysum2) / (fycount + fycount2); //if (prod.AverageYield == null) //{ // prod.AverageYield = ay; //} //else //{ // prod.AverageYield = (prod.AverageYield + ay) / 2; //} pr.Save(prod); } }