Ejemplo n.º 1
0
        public List <InfractionDetails> GetAll()
        {
            List <Infraction> AllInfra = new List <Infraction>();
            var FacIds = db.Factory11.Select(f => f.Id).ToList();
            var sMonth = DateTime.Now.AddMonths(-1).Month.ToString();

            foreach (var ID in FacIds)
            {
                var qq = db.VisitDetails.Where(f => f.FactoryId == ID);
                List <VisitDetail> TempV = new List <VisitDetail>();
                foreach (var item in qq)
                {
                    if (item.VisitDate.Month.ToString() == sMonth)
                    {
                        TempV.Add(item);
                    }
                }
                var Last = TempV.OrderByDescending(d => d.VisitDate).FirstOrDefault();
                if (Last != null)
                {
                    if ((DateTime.Now - Last.VisitDate).TotalDays >= 29)
                    {
                        var FaInfra = db.Infractions.Where(infra => infra.FactoryId == Last.FactoryId).ToList();
                        AllInfra.AddRange(FaInfra);
                    }
                }
            }

            List <InfractionDetails> InfraList = new List <InfractionDetails>();

            foreach (var item in AllInfra)
            {
                InfractionDetails f = new InfractionDetails();
                f.AdminApproved   = item.AdminApproved;
                f.C8Day           = item.C8Day;
                f.FactoryId       = item.FactoryId;
                f.Landing         = item.Landing;
                f.MonitorApproved = item.MonitorApproved;
                f.SampleNo        = item.SampleNo;
                f.Temperature     = item.Temperature;
                f.VisitDate       = item.VisitDate;
                f.ID          = item.ID;
                f.FactoryName = db.Factory11.Where(fac => fac.Id == item.FactoryId).Select(fa => fa.Name).FirstOrDefault();
                f.Location    = db.Factory11.Where(fac => fac.Id == item.FactoryId).Select(fa => fa.Location).FirstOrDefault();
                InfraList.Add(f);
            }
            return(InfraList);
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <InfractionDetails> > GetInfractionsByDriverAsync(DNIProperties dni)
        {
            var result = await _dbConnection.QueryAsync <DNIProperties, DriverProperties, CarProperties, TypeInfraction, DateTime, InfractionDetails>("dbo.ISSP_GetInfractionsByDriver",
                                                                                                                                                      map : (dp, d, c, ti, dt) =>
            {
                InfractionDetails ide = new InfractionDetails();
                ide.dNI               = dp;
                ide.driverDetails     = d;
                ide.carDetails        = c;
                ide.infractionDetails = ti;
                ide.dateInfraction    = dt;
                return(ide);
            }, splitOn : "name,idCar,IdTypeInfraction,dateInfraction", param : dni, commandType : CommandType.StoredProcedure);

            return(result);
        }