Пример #1
0
 public ActionResult UserPage(Search conditon)
 {
     //首先有两个条件: 地方,年龄。
     var id = CheckValid();
     if (CheckValid() == -1)
     {
         return RedirectToAction("Logon", "User");//不知道有没有效果
     }
     var baseusers = GetBaseUsers(id);
     var simpleUsers = new List<SimpleUser>();
     if (conditon.AgeUp != 0)
     {
         // 找到uninusers
         simpleUsers.AddRange(from user1 in baseusers
                              select new UninUser
                              {
                                  BaseInfo = LoveDb.One((BaseInfo b) => b.UserId == user1.UserId),
                                  DetailInfo = LoveDb.One((DetailInfo d) => d.UserId == user1.UserId),
                                  User = user1
                              }
                                  into uni
                                  where MarchUser(conditon, uni)
                                  select new SimpleUser
                                  {
                                      Age = uni.User.Age,
                                      ImgUrl = uni.User.ImgUrl,
                                      UserName = uni.User.UserName,
                                      UserId = uni.User.UserId,
                                      City = uni.BaseInfo.ResidenceCity
                                  });
     }
     else
     {
         simpleUsers = GetSimpleUsers(baseusers);
     }
     return PartialView(simpleUsers);
 }
Пример #2
0
        /// <summary>
        /// 匹配user是否符合搜索条件
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="biguser"></param>
        /// <returns></returns>
        private bool MarchUser(Search condition, UninUser biguser)
        {
            // 先判断user的部分
            var residenceflag = false;
            var ageflag = false;
            var educationflag = false;
            var incomeflag = false;
            var housingflag = false;
            var carflag = false;
            var conflag = false;
            var hightflag = false;
            var nativeflag = false;
            var peopleflag = false;
            var stateflag = false;

            // 还要判断user 自身的资料是否是不为null的。

            if ((biguser.BaseInfo.ResidenceCity != null && biguser.BaseInfo.ResidenceCity.Contains(condition.ResidenceCity)) || string.IsNullOrEmpty(condition.ResidenceCity))
            {
                residenceflag = true;
            }
            //年龄
            if ((condition.AgeUp == 0 || (biguser.User.Age != 0 && biguser.User.Age <= condition.AgeLow && biguser.User.Age >= condition.AgeUp))//agelow 要比 ageup 大
                || (condition.AgeLow == 0 && biguser.User.Age >= condition.AgeUp))
            {
                ageflag = true;
            }
            //学历
            if (string.IsNullOrEmpty(condition.Education) || condition.Education == "学历不限" || biguser.BaseInfo.Education != null && ((condition.Education.Contains("及以上") && IntEducation(biguser.BaseInfo.Education) >= IntEducation(condition.Education))
                 || (!condition.Education.Contains("及以上") && IntEducation(biguser.BaseInfo.Education) == IntEducation(condition.Education))))
            {
                educationflag = true;
            }
            //收入
            if (string.IsNullOrEmpty(condition.MonthlyIncome) ||
              (biguser.BaseInfo.MonthlyIncome != null && ((IntIncome(biguser.BaseInfo.MonthlyIncome) >= IntIncome(condition.MonthlyIncome) && condition.MonthlyIncome != "3000元以下") ||
              IntIncome(biguser.BaseInfo.MonthlyIncome) <= IntIncome(condition.MonthlyIncome) && condition.MonthlyIncome == "3000元以下")))
            {
                incomeflag = true;
            }
            // 汽车
            if (string.IsNullOrEmpty(condition.Car) || (biguser.DetailInfo.Car != null && biguser.DetailInfo.Car == condition.Car))
            {
                carflag = true;
            }
            //住房
            if (string.IsNullOrEmpty(condition.Housing) ||
                (biguser.DetailInfo.Housing != null && biguser.DetailInfo.Housing == condition.Housing))
            {
                housingflag = true;
            }
            //星座
            if (string.IsNullOrEmpty(condition.Constellation) || (biguser.DetailInfo.Constellation != null && biguser.DetailInfo.Constellation == condition.Constellation))
            {
                conflag = true;
            }
            //身高
            int hight = Convert.ToInt32(biguser.BaseInfo.Height.Split('厘')[0]);
            if (condition.HightUp == 0 || (biguser.BaseInfo.Height != null && ((hight <= condition.HightLow && hight >= condition.HightUp && condition.HightLow != 0)
                || (condition.HightLow == 0 && hight >= condition.HightUp))))
            {
                hightflag = true;
            }
            //籍贯
            if (string.IsNullOrEmpty(condition.NativePlace) || (biguser.DetailInfo.NativePlace != null && (condition.NativePlace == Trimplace(biguser.DetailInfo.NativePlace) ||
                biguser.DetailInfo.NativePlace.Contains(condition.NativePlace))))
            {
                nativeflag = true;
            }
            if (string.IsNullOrEmpty(condition.People) || (biguser.DetailInfo.People != null && condition.People == biguser.DetailInfo.People))
            {
                peopleflag = true;
            }
            if (string.IsNullOrEmpty(condition.State) || (biguser.BaseInfo.State != null && condition.State == biguser.BaseInfo.State))
            {
                stateflag = true;
            }

            return residenceflag && ageflag && educationflag && incomeflag && housingflag &&
                   carflag && conflag && hightflag && nativeflag && peopleflag && stateflag;
        }