Esempio n. 1
0
        //
        // GET: /Crm/VisitRecord/

        public ActionResult Index(VisitRecordRequest request)
        {
            this.TryUpdateModel<VisitRecord>(request.VisitRecord);

            this.ModelState.Clear();
            
            this.RenderMyViewData(request.VisitRecord, true);
            var areas = this.AreaDic.Values.Select(c => new { Id = c.ID, Name = c.Name + "-" + this.CityDic[c.CityId].Name });
            ViewData.Add("AreaId", new SelectList(areas, "Id", "Name", request.VisitRecord.AreaId));
            
            var result = this.CrmService.GetVisitRecordList(request);
            return View(result);
        }
Esempio n. 2
0
        public IEnumerable<VisitRecord> GetVisitRecordList(VisitRecordRequest request = null)
        {
            request = request ?? new VisitRecordRequest();
            using (var dbContext = new CrmDbContext())
            {
                IQueryable<VisitRecord> queryList = dbContext.VisitRecords.Include("Project").Include("Customer");

                var model = request.VisitRecord;

                if (!string.IsNullOrEmpty(model.Username))
                    queryList = queryList.Where(d => d.Username.Contains(model.Username));

                if (model.Customer != null && !string.IsNullOrEmpty(model.Customer.Name))
                    queryList = queryList.Where(d => d.Customer.Name.Contains(model.Customer.Name));

                if (model.Customer != null && !string.IsNullOrEmpty(model.Customer.Number))
                    queryList = queryList.Where(d => d.Customer.Number.Contains(model.Customer.Number));

                if (model.Customer != null && !string.IsNullOrEmpty(model.Customer.Tel))
                    queryList = queryList.Where(d => d.Customer.Tel.Contains(model.Customer.Tel));

                if (request.StartHour != null && request.EndHour != null)
                {
                    var startHour = request.StartHour.Value - 1;
                    var endHour = request.EndHour.Value - 1;

                    queryList = queryList.Where(d => d.VisitTime.Hour >= startHour && d.VisitTime.Hour <= endHour);
                }

                var startDate = request.StartDate == null ? DateTime.Now.AddMonths(-3) : request.StartDate.Value;
                queryList = queryList.Where(d => d.VisitTime > startDate);

                var endDate = request.EndDate == null ? DateTime.Now.AddDays(1) : request.EndDate.Value;
                queryList = queryList.Where(d => d.VisitTime < endDate);

                if (model.FollowStep > 0)
                    queryList = queryList.Where(d => d.FollowStep == model.FollowStep);

                if (model.FollowLevel > 0)
                    queryList = queryList.Where(d => d.FollowLevel == model.FollowLevel);

                if (model.ProjectId > 0)
                    queryList = queryList.Where(d => d.ProjectId == model.ProjectId);

                if (model.Motivation > 0)
                    queryList = queryList.Where(d => d.Motivation == model.Motivation);

                if (model.AreaDemand > 0)
                    queryList = queryList.Where(d => d.AreaDemand == model.AreaDemand);

                if (model.PriceResponse > 0)
                    queryList = queryList.Where(d => d.PriceResponse == model.PriceResponse);

                if (model.Focus > 0)
                    queryList = queryList.Where(d => (d.Focus & model.Focus) != 0);

                if (model.CognitiveChannel > 0)
                    queryList = queryList.Where(d => (d.CognitiveChannel & model.CognitiveChannel) != 0);

                if (model.VisitWay > 0)
                    queryList = queryList.Where(d => d.VisitWay == model.VisitWay);

                if (model.AreaId > 0)
                    queryList = queryList.Where(d => d.AreaId == model.AreaId);

                return queryList.OrderByDescending(u => u.ID).ToPagedList(request.PageIndex, request.PageSize);
            }
        }