Ejemplo n.º 1
0
        public CDataResults <CWmtSoilMoistureListDto> GetWmtSoilMoisture(CWmtSoilMoistureInput input)
        {
            //Check Ip & customer
            if (!checkIPandCustomer(input.customerId))
            {
                AddVisitRecord(input.customerId, Entities.VisitRecordFlag.Black);
                return(new CDataResults <CWmtSoilMoistureListDto>()
                {
                    IsSuccess = false,
                    ErrorMessage = "Validation failed.",
                    Data = null
                });
            }

            //Extract data from DB
            var query = this._wmtSoilMoistureRepository.GetAll();

            if (input.pageNumber.HasValue && input.pageNumber.Value > 0 && input.pageSize.HasValue)
            {
                query = query.OrderBy(r => r.Id).Take(input.pageSize.Value * input.pageNumber.Value).Skip(input.pageSize.Value * (input.pageNumber.Value - 1));
            }

            var result = query.ToList().MapTo <List <CWmtSoilMoistureListDto> >();

            //Add visit record
            AddVisitRecord(input.customerId, Entities.VisitRecordFlag.White);
            return(new CDataResults <CWmtSoilMoistureListDto>()
            {
                IsSuccess = true,
                ErrorMessage = null,
                Data = result
            });
        }
Ejemplo n.º 2
0
        public CDataResults <CWmtSoilMoistureDetailListDto> GetWmtSoilMoistureDetail(CWmtSoilMoistureInput input)
        {
            //Check Ip & customer
            if (!checkIPandCustomer(input.customerId))
            {
                AddVisitRecord(input.customerId, Entities.VisitRecordFlag.Black);
                return(new CDataResults <CWmtSoilMoistureDetailListDto>()
                {
                    IsSuccess = false,
                    ErrorMessage = "Validation failed.",
                    Data = null
                });
            }

            //Extract data from DB
            var query = from r in _wmtSoilMoistureRepository.GetAll()
                        join s in _stnInfoBRepository.GetAll() on r.stcd equals s.areaCode
                        join res in _relationReposity.GetAll() on s.Id equals res.site_id
                        where res.customer_id == input.customerId
                        orderby r.collecttime
                        select new CWmtSoilMoistureDetailListDto
            {
                areaCode    = s.areaCode,
                areaName    = s.areaName,
                stcd        = r.stcd,
                paravalue   = r.paravalue,
                collecttime = r.collecttime,
                systemtime  = r.systemtime,
                uniquemark  = r.uniquemark,
                gentm       = r.gentm
            };

            if (input.fromTime != null)
            {
                query = query.Where(r => r.collecttime > input.fromTime);
            }
            if (input.toTime != null)
            {
                query = query.Where(r => r.collecttime < input.toTime);
            }
            if (!string.IsNullOrEmpty(input.stcd))
            {
                query = query.Where(r => r.stcd == input.stcd);
            }
            if (input.pageNumber.HasValue && input.pageNumber.Value > 0 && input.pageSize.HasValue)
            {
                query = query.OrderByDescending(r => r.collecttime).Take(input.pageSize.Value * input.pageNumber.Value).Skip(input.pageSize.Value * (input.pageNumber.Value - 1));
            }

            var result = query.ToList();

            //Add visit record
            AddVisitRecord(input.customerId, Entities.VisitRecordFlag.White);
            return(new CDataResults <CWmtSoilMoistureDetailListDto>()
            {
                IsSuccess = true,
                ErrorMessage = null,
                Data = result,
                Total = query.Count()
            });
        }