Esempio n. 1
0
        public ActionResult GenerateBatchStandardFollowUp(Guid batchId, Guid standardId)
        {
            var batch = _batchService.GetByIdComplete(batchId);

            var weeksAge    = Math.Ceiling(DateTime.Now.Subtract(batch.DateOfBirth).Days / (double)7);
            var standardIds = standardId == Standard.Death
                ? new List <Guid> {
                Standard.Death, Standard.Remove
            }
                : new List <Guid> {
                standardId
            };
            var obj = new
            {
                batch.Id,
                Name = String.Format("Lote {0}", batch.Number),
                batch.InitialBirds,
                FirstHalf   = batch.StageId == Stage.BREEDING || batch.StageId == Stage.REBREEDING,
                GeneticLine = new
                {
                    batch.GeneticLine.Name,
                    Standards = batch.GeneticLine.StandardGeneticLines.Where(sql => !sql.IsDeleted & standardIds.Contains(sql.StandardId)).Select(sgl => new
                    {
                        sgl.Standard.Name,
                        ShowSecondValue = sgl.Standard.StandardTypeId == StandardType.VALUES_RANGE,
                        sgl.Standard.AggregateOperation,
                        sgl.Standard.AllowDecimal,
                        sgl.Standard.MeasureUnity,
                        StandardItems = sgl.StandardItems.Where(sql => !sgl.IsDeleted && sql.Sequence <= weeksAge).OrderBy(s => s.Sequence).Select(si => new
                        {
                            si.Value1,
                            si.Value2,
                            si.Sequence,
                            Measures =
                                si.Measures.Where(m => !m.IsDeleted && m.BatchId == batch.Id).Select(m => new
                            {
                                m.Value,
                                m.StandardItemId
                            })
                        })
                    })
                }
            };

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }