Пример #1
0
        public CDataResults <CVisitRecordListDto> GetVisitRecord(CVisitRecordInput input)
        {
            //Check Ip & visitRecord
            if (!checkIPandCustomer(input.customerId))
            {
                AddVisitRecord(input.customerId, Entities.VisitRecordFlag.Black);
                return(new CDataResults <CVisitRecordListDto>()
                {
                    IsSuccess = false,
                    ErrorMessage = "Validation failed.",
                    Data = null
                });
            }

            //Extract data from DB
            var query = this._visitRecordRepository.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 <CVisitRecordListDto> >();

            //Add visit record
            AddVisitRecord(input.customerId, Entities.VisitRecordFlag.White);
            return(new CDataResults <CVisitRecordListDto>()
            {
                IsSuccess = true,
                ErrorMessage = null,
                Data = result,
                Total = query.Count()
            });
        }
Пример #2
0
        public CDataResults <CVisitRecordDetailListDto> GetVisitWhiteRecord(CVisitRecordInput input)
        {
            //Check Ip & visitRecord
            if (!checkIPandCustomer(input.customerId))
            {
                AddVisitRecord(input.customerId, Entities.VisitRecordFlag.Black);
                return(new CDataResults <CVisitRecordDetailListDto>()
                {
                    IsSuccess = false,
                    ErrorMessage = "Validation failed.",
                    Data = null
                });
            }

            //Extract data from DB
            //var query = this._visitRecordRepository.GetAll();
            var query = from r in _visitRecordRepository.GetAll()
                        join s in this._customerRepository.GetAll() on r.customerId equals s.Id into rs
                        from rst in rs.DefaultIfEmpty()
                        orderby r.visit_dateTime descending
                        where r.flag == (int)VisitRecordFlag.White
                        select new CVisitRecordDetailListDto
            {
                customerId     = r.customerId,
                customerName   = rst.customerName,
                visit_dateTime = r.visit_dateTime,
                ip             = r.ip,
                flag           = r.flag
            };

            if (input.pageNumber.HasValue && input.pageNumber.Value > 0 && input.pageSize.HasValue)
            {
                query = query.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 <CVisitRecordDetailListDto>()
            {
                IsSuccess = true,
                ErrorMessage = null,
                Data = result
            });
        }