Beispiel #1
0
        //
        // GET: /Crm/Customer/

        public ActionResult Index(CustomerRequest request)
        {
            this.TryUpdateModel<Customer>(request.Customer);

            this.ModelState.Clear();
            
            this.RenderMyViewData(request.Customer, true);
            
            var result = this.CrmService.GetCustomerList(request);
            return View(result);
        }
Beispiel #2
0
        public IEnumerable<Customer> GetCustomerList(CustomerRequest request = null)
        {
            request = request ?? new CustomerRequest();
            using (var dbContext = new CrmDbContext())
            {
                IQueryable<Customer> queryList = dbContext.Customers.Include("VisitRecords");

                if (request.Customer.UserId > 0)
                    queryList = queryList.Where(d => d.UserId == request.Customer.UserId);
                
                if (!string.IsNullOrEmpty(request.Customer.Name))
                    queryList = queryList.Where(d => d.Name.Contains(request.Customer.Name));

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

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

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

                if (request.Customer.Gender > 0)
                    queryList = queryList.Where(d => d.Gender == request.Customer.Gender);

                if (request.Customer.Category > 0)
                    queryList = queryList.Where(d => d.Category == request.Customer.Category);

                if (request.Customer.Profession > 0)
                    queryList = queryList.Where(d => d.Profession == request.Customer.Profession);

                if (request.Customer.AgeGroup > 0)
                    queryList = queryList.Where(d => d.AgeGroup == request.Customer.AgeGroup);

                return queryList.OrderByDescending(u => u.ID).ToPagedList(request.PageIndex, request.PageSize);
            }
        }
        private void RenderMyViewData(VisitRecord model, bool isBasic = false)
        {
            ViewData.Add("VisitWay", new SelectList(EnumHelper.GetItemValueList<EnumVisitWay>(), "Key", "Value", model.VisitWay));
            ViewData.Add("FollowLevel", new SelectList(EnumHelper.GetItemValueList<EnumFollowLevel>(), "Key", "Value", model.FollowLevel));
            ViewData.Add("FollowStep", new SelectList(EnumHelper.GetItemValueList<EnumFollowStep>(), "Key", "Value", model.FollowStep));
            ViewData.Add("ProductType", new SelectList(EnumHelper.GetItemValueList<EnumProductType>(), "Key", "Value", model.ProductType));

            ViewData.Add("Focus", new SelectList(EnumHelper.GetItemList<EnumFocus>(), "Key", "Value", (EnumFocus)model.Focus));
            ViewData.Add("CognitiveChannel", new SelectList(EnumHelper.GetItemList<EnumCognitiveChannel>(), "Key", "Value", (EnumCognitiveChannel)model.CognitiveChannel));
            ViewData.Add("PriceResponse", new SelectList(EnumHelper.GetItemValueList<EnumPriceResponse>(), "Key", "Value", model.PriceResponse));
            ViewData.Add("AreaDemand", new SelectList(EnumHelper.GetItemValueList<EnumAreaDemand>(), "Key", "Value", model.AreaDemand));
            ViewData.Add("Motivation", new SelectList(EnumHelper.GetItemValueList<EnumMotivation>(), "Key", "Value", model.Motivation));

            ViewData.Add("ProjectId", new SelectList(this.CrmService.GetProjectList(), "Id", "Name", model.ProjectId));

            if (isBasic)
                return;

            ViewData.Add("CityId", new SelectList(this.CityDic.Values, "Id", "Name", model.CityId));

            if (model.CityId == 0)
                model.CityId = this.CityDic.First().Key;

            var areas = this.AreaDic.Values.Where(a => a.CityId == model.CityId);
            ViewData.Add("AreaId", new SelectList(areas, "Id", "Name", model.AreaId));

            var request = new CustomerRequest();
            request.Customer.UserId = this.UserContext.LoginInfo.UserID;
            var customerList = this.CrmService.GetCustomerList(request).ToList();
            customerList.ForEach(c => c.Name = string.Format("{0}({1})", c.Name, c.Tel));
            ViewData.Add("CustomerId", new SelectList(customerList, "Id", "Name", model.CustomerId));

        }