Пример #1
0
        /// <summary>
        /// Search Seeds
        /// </summary>
        /// <param name="Criteria"></param>
        /// <param name="sortBy"></param>
        /// <param name="radius"></param>
        /// <param name="counter"></param>
        /// <returns></returns>
        public IList<SeedDetail> SearchSeeds(string Criteria, string sortBy, string radius, string counter)
        {
            SeedAction objSeed = new SeedAction();
            IList<Seed> seedData = new List<Seed>();
            IList<Seed> tmpSeedList = null;
            CategoryAction objCategory = new CategoryAction();

            string searchOthers = "";
            string searchZip = "";
            int seedCounter = Convert.ToInt32(counter) + 1;

            string[] criteriaArr = Criteria.Trim().Split(' ');

            foreach (string str in criteriaArr)
            {
                //Checking that searchstring contains zipcode
                if (this.checkCriteria(str))
                {
                    searchZip = str;
                }
                else
                {
                    searchOthers = searchOthers + " " + str;
                }
            }

            searchOthers = searchOthers.Trim();

            if (searchZip.Length > 0)
            {
               // radius = "50";
                tmpSeedList = objSeed.GetAllSeedsByZip(radius, searchZip);

                foreach (Seed sData in tmpSeedList)
                {
                    if (sData.status.Equals(SystemStatements.STATUS_NEW) || sData.status.Equals(SystemStatements.STATUS_GROWING))
                    {
                        seedData.Add(sData);
                    }
                    //seedData.Add(sData);
                }
            }

            if (searchOthers.Length > 0 && seedData.Distinct().ToList().Count < seedCounter)
            {
                //Searching in Category
                IList<Category> catList = objCategory.GetAllCategoriesByName(searchOthers);

                foreach (Category cat in catList)
                {
                    tmpSeedList = objSeed.GetAllSeedsByCategory(cat.id.ToString());
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    tmpSeedList = objSeed.GetAllSeedsByTitle(searchOthers);
                    foreach (Seed sData in tmpSeedList)

                    {
                        seedData.Add(sData);
                    }
                }

                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    //Searching in Description
                    tmpSeedList = objSeed.GetAllSeedsByDescription(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    //Searching in FirstName
                    tmpSeedList = objSeed.GetAllSeedsByUserName(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    //Searching in CrossStreet
                    tmpSeedList = objSeed.GetSeedByCrossStreet(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }
                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    //Searching in City
                    tmpSeedList = objSeed.GetSeedByCity(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

            }

              //  string tmp = "";

            seedData = seedData.Distinct().Take(seedCounter).ToList();

            if (!string.IsNullOrEmpty(sortBy))
            {
                switch (sortBy)
                {
                    case "1":
                        seedData = seedData.OrderBy(x => x.Categories.FirstOrDefault() != null ? x.Categories.FirstOrDefault().name : "").ToList();
                        break;
                    case "2":
                        seedData = seedData.OrderBy(x => x.Location.zipcode).ToList();
                        break;
                    case "3":
                        seedData = seedData.OrderBy(x => x.title).ToList();
                        break;
                    default:
                        seedData = seedData.OrderBy(x => x.title).ToList();
                        break;
                }
            }

            string tmpCName = "";

            IList<SeedDetail> lstSeedList = new List<SeedDetail>();

            foreach (Seed s in seedData)
            {

                SeedDetail objSeedDetail = new SeedDetail();

                string imgPath = "No Image";

                int likesCount = s.Ratings.Where(x => x.likes.Equals("Like")).ToList().Count;
                int replyCount =Convert.ToInt16(objSeed.GetReplySeedCount(s.id.ToString()));// s.Commitments.ToList().Count;
                int commentsCount = s.Comments.ToList().Count;

                if (s.Media != null && s.Media.Count > 0)
                {
                    imgPath = s.Media.FirstOrDefault().path;

                    imgPath = imgPath.Substring(imgPath.LastIndexOf('/'));

                    if (imgPath.Length > 1)
                        imgPath = System.Configuration.ConfigurationManager.AppSettings["RootURL"].ToString() + "/UploadedMedia" + imgPath;
                    else
                        imgPath = "No Image";
                }

                objSeedDetail.SeedID = s.id.ToString();
                objSeedDetail.Title = s.title;

                if (s.Location.City != null)
                {
                   // tmp += "||" + s.Location.City.name;
                    objSeedDetail.City = s.Location.City.name;
                }

                if (s.Location.City.Region != null)
                {
                    objSeedDetail.State = s.Location.City.Region.code;
                    //tmp += "||" + s.Location.City.Region.code;
                }

                if (s.Location != null)
                {
                    objSeedDetail.Zip = s.Location.zipcode;
                  //  tmp += "||" + s.Location.zipcode;
                }
                objSeedDetail.Path = imgPath;
               // tmp += "||" + imgPath;

                if (s.Categories != null && s.Categories.Count > 0)
                {
                    tmpCName = s.Categories.FirstOrDefault().name;
                }

                if (s.Location != null)
                {

                    objSeedDetail.Latitude = s.Location.localLat.ToString();
                    objSeedDetail.Longitude = s.Location.localLong.ToString();
                }
                objSeedDetail.TempCategory = tmpCName;
               // tmp += "||" + tmpCName;

                objSeedDetail.MemberName = s.Member.firstName + " " + s.Member.lastName;
                objSeedDetail.Address = s.Location.crossStreet;
                objSeedDetail.CreateDate = Convert.ToDateTime(s.createDate).ToString();
                objSeedDetail.Description = s.description;
                objSeedDetail.Likes = likesCount + " Likes";
                objSeedDetail.Comments = commentsCount + " Comments";
                objSeedDetail.ReplySeeds = replyCount + " Reply Seeds";
                objSeedDetail.PopularCount = (likesCount + commentsCount + replyCount).ToString();
                //tmp += "||" + s.Member.firstName + " " + s.Member.lastName + "||" + s.Location.crossStreet + "||" + Convert.ToDateTime(s.createDate).ToString("dd MMMM yyyy") + "||" + s.description + "||" + likesCount + " Likes" + "||" + commitmentCount + " Commitments" + "||" + commentsCount + " Comments";

                string tmpCategory = "";
                foreach (Category c in s.Categories)
                {
                    if (tmpCategory.Length > 0)
                        tmpCategory = tmpCategory + "," + c.name;
                    else
                        tmpCategory = c.name;
                }
                objSeedDetail.Categories = tmpCategory;
             //   tmp = tmp + "||" + tmpCategory;

                lstSeedList.Add(objSeedDetail);
            }//For each seed

            return lstSeedList;
        }
Пример #2
0
        public IList<Seed> HomeSearchSeeds(string Criteria, string sortBy, string radius, string counter)
        {
            #region
            SeedAction objSeed = new SeedAction();
            IList<Seed> seedData = new List<Seed>();
            IList<Seed> tmpSeedList = null;
            CategoryAction objCategory = new CategoryAction();

            string searchOthers = "";
            string searchZip = "";
            int seedCounter = Convert.ToInt32(counter) + 1;

            string[] criteriaArr = Criteria.Trim().Split(' ');

            foreach (string str in criteriaArr)
            {
                if (this.checkCriteria(str))
                {
                    searchZip = str;
                }
                else
                {
                    searchOthers = searchOthers + " " + str;
                }
            }

            searchOthers = searchOthers.Trim();

            if (searchZip.Length > 0)
            {
                tmpSeedList = objSeed.GetAllSeedsByZip(radius, searchZip);

                foreach (Seed sData in tmpSeedList)
                {
                    seedData.Add(sData);
                }
            }

            if (searchOthers.Length > 0 && seedData.Distinct().ToList().Count < seedCounter)
            {
                IList<Category> catList = objCategory.GetAllCategoriesByName(searchOthers);

                foreach (Category cat in catList)
                {
                    tmpSeedList = objSeed.GetAllSeedsByCategory(cat.id.ToString());
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    tmpSeedList = objSeed.GetAllSeedsByTitle(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    tmpSeedList = objSeed.GetAllSeedsByDescription(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    tmpSeedList = objSeed.GetSeedByCrossStreet(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }
                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    tmpSeedList = objSeed.GetSeedByCity(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

            }
            seedData = seedData.Distinct().Take(seedCounter).ToList();
            return seedData;
            #endregion
        }
        public string SearchSeeds(string Criteria, string sortBy,string radius,string counter)
        {
            #region
            SeedAction objSeed = new SeedAction();
            IList<Seed> seedData = new List<Seed>();
            IList<Seed> tmpSeedList = null;
            CategoryAction objCategory = new CategoryAction();

            string searchOthers = "";
            string searchZip = "";
            int seedCounter = Convert.ToInt32(counter) + 1;

            string[] criteriaArr = Criteria.Trim().Split(' ');

            foreach(string str in criteriaArr)
            {
                if (this.checkCriteria(str))
                {
                    searchZip = str;
                }
                else
                {
                    searchOthers = searchOthers + " " + str;
                }
            }

            searchOthers = searchOthers.Trim();

            if (searchZip.Length > 0)
            {
                tmpSeedList = objSeed.GetAllSeedsByZip(radius, searchZip);

                foreach (Seed sData in tmpSeedList)
                {
                    seedData.Add(sData);
                }
            }

            if (searchOthers.Length > 0 && seedData.Distinct().ToList().Count < seedCounter)
            {
                IList<Category> catList = objCategory.GetAllCategoriesByName(searchOthers);

                foreach (Category cat in catList)
                {
                    tmpSeedList = objSeed.GetAllSeedsByCategory(cat.id.ToString());
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    tmpSeedList = objSeed.GetAllSeedsByTitle(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    tmpSeedList = objSeed.GetAllSeedsByDescription(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    tmpSeedList = objSeed.GetSeedByCrossStreet(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }
                if (seedData.Distinct().ToList().Count < seedCounter)
                {
                    tmpSeedList = objSeed.GetSeedByCity(searchOthers);
                    foreach (Seed sData in tmpSeedList)
                    {
                        seedData.Add(sData);
                    }
                }

             }

            string tmp = "";

            seedData = seedData.Distinct().Take(seedCounter).ToList();

            if (!string.IsNullOrEmpty(sortBy))
            {
                switch (sortBy)
                {
                    case "1":
                        seedData = seedData.OrderBy(x => x.Categories.FirstOrDefault() != null ? x.Categories.FirstOrDefault().name : "").ToList();
                        break;
                    case "2":
                        seedData = seedData.OrderBy(x => x.Location.zipcode).ToList();
                        break;
                    case "3":
                        seedData = seedData.OrderBy(x => x.title).ToList();
                        break;
                    default:
                        seedData = seedData.OrderBy(x => x.title).ToList();
                        break;
                }
            }

            string tmpCName = "";

            foreach (Seed s in seedData)
            {

                string imgPath = "No Image";

                int likesCount = s.Ratings.Where(x => x.likes.Equals("Like")).ToList().Count;
                int commitmentCount = s.Commitments.ToList().Count;
                int commentsCount = s.Comments.ToList().Count;

                if (s.Media != null && s.Media.Count > 0)
                {
                    imgPath = s.Media.FirstOrDefault().path;

                    imgPath = imgPath.Substring(imgPath.LastIndexOf('/'));

                    if (imgPath.Length > 1)
                        imgPath = System.Configuration.ConfigurationManager.AppSettings["RootURL"].ToString() + "/UploadedMedia" + imgPath;
                    else
                        imgPath = "No Image";
                }

                tmp += s.id.ToString() + "||" + s.title;

                if (s.Location.City != null)
                {
                    tmp += "||" + s.Location.City.name;
                }

                if (s.Location.City.Region != null)
                {
                    tmp += "||" + s.Location.City.Region.code;
                }

                if (s.Location != null)
                {
                    tmp += "||" + s.Location.zipcode;
                }

                tmp += "||" + imgPath;

                if (s.Categories != null && s.Categories.Count > 0)
                {
                    tmpCName = s.Categories.FirstOrDefault().name;
                }

                tmp += "||" + tmpCName;

                tmp += "||" + s.Member.firstName + " " + s.Member.lastName + "||" + s.Location.crossStreet + "||" + Convert.ToDateTime(s.createDate).ToString("dd MMMM yyyy") + "||" + s.description + "||" + likesCount + " Likes" + "||" + commitmentCount + " Commitments" + "||" + commentsCount + " Comments";

                string tmpCategory = "";
                foreach (Category c in s.Categories)
                {
                    if (tmpCategory.Length > 0)
                        tmpCategory = tmpCategory + "," + c.name;
                    else
                        tmpCategory = c.name;
                }
                tmp = tmp + "||" + tmpCategory;

                tmp += "##";

            }

            if (tmp.Length > 2)
                tmp = tmp.Substring(0, tmp.Length - 2);

            if (seedData.Count < 1)
                tmp = "No Matching Seeds Found";

            return tmp;
            #endregion
        }