コード例 #1
0
        public ActionResult SearchEducationalCenters(SearchEducationalCenterDto model)
        {
            var allEducationalCenters = _db.Set <EducationalCenter>()
                                        .Include(ec => ec.Site)
                                        .Include(ec => ec.Area.Province)
                                        .Include(ec => ec.Area.Site)
                                        .Include(ec => ec.Sex)
                                        .Where(ec => ec.SexId == model.SexId)
                                        .Where(ec => ec.Category == model.EducationalCenterCategory)
                                        .Where(ec => model.EducationalCenterCode == null || ec.Id == model.EducationalCenterCode)
                                        .Where(ec => model.EducationalCenterName == null || ec.Site.Name.Contains(model.EducationalCenterName))

                                        .AsQueryable();

            var educationalCenters = model.AreaId <= 0 ?
                                     allEducationalCenters.Where(ec => ec.Area.ProvinceId == model.ProvinceId) :
                                     allEducationalCenters.Where(ec => ec.AreaId == model.AreaId);

            var r = educationalCenters.ToList().Select(ec => new
            {
                EducationalCenterName = ec.Site.Name,
                EducationalCenterCode = ec.Id,
                Province = ec.Area.Province.Name,
                Area     = ec.Area.Site.Name,
                Category = ec.Category,
                Sex      = ec.Sex.Title
            });

            return(Json(r, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public ActionResult SearchEducationalCenters()
        {
            var searchEducationalCenterDto = new SearchEducationalCenterDto
            {
                Provinces = _db.Set <Province>().ToList().Select(p => new SelectListItem
                {
                    Text  = p.Name,
                    Value = p.Id.ToString()
                }),
                Areas = new List <SelectListItem>
                {
                    new SelectListItem
                    {
                        Text  = "همه ناحیه ها",
                        Value = "1"
                    }
                },
                Sexes = _db.Set <Sex>().ToList().Select(p => new SelectListItem
                {
                    Text  = p.Title,
                    Value = p.Id.ToString()
                }),
                EducationalCenterCategories = new List <SelectListItem>
                {
                    new SelectListItem
                    {
                        Text  = "مرکز زبان خارجه",
                        Value = "مرکز زبان خارجه"
                    },
                    new SelectListItem
                    {
                        Text  = "مرکز علمی آزاد",
                        Value = "مرکز علمی آزاد"
                    }
                }
            };

            return(View(searchEducationalCenterDto));
        }