Пример #1
0
        /// <summary>
        /// Method to get all seeds by Id.
        /// </summary>
        /// <param name="SeedId"></param>
        /// <returns></returns>
        public IList<SeedDetail> GetSeedsById(string SeedId, string MemberId)
        {
            IList<SeedDetail> lstSeedDetail = new List<SeedDetail>();
            SeedDetail objSeedDetail = new SeedDetail();
            SeedAction objSeed = new SeedAction();
            //For finding total reply seeds of the current seed
            //int getCounter = 200;
               // IList<Seed> seedDataCounter = (objSeed.GetSeedsByParrentSeedID(SeedId)).Take(getCounter).OrderBy(x => x.createDate).ToList();
            //

            Seed seedData = objSeed.GetSeedBySeedId(SeedId);
            int likesCount = seedData.Ratings.Where(x => x.likes.Equals("Like")).ToList().Count;
            int replyCount = Convert.ToInt16(objSeed.GetReplySeedCount(SeedId));// seedData.Commitments.ToList().Count;
            int commentsCount = seedData.Comments.ToList().Count;

            objSeedDetail.Title = seedData.title;
            if (seedData.Member.organisationName != null)
            {
                objSeedDetail.MemberName = seedData.Member.organisationName;
            }
            else
            {
                objSeedDetail.MemberName = seedData.Member.firstName + " " + seedData.Member.lastName;
            }

            objSeedDetail.City = seedData.Location.City.name;
            objSeedDetail.Address = seedData.Location.crossStreet;
            objSeedDetail.State = seedData.Location.City.Region.name;
            objSeedDetail.CreateDate = Convert.ToDateTime(seedData.createDate).ToString("MMMM dd, yyyy");
            objSeedDetail.Description = seedData.description;
            objSeedDetail.Likes = likesCount + " Likes";
            objSeedDetail.ReplySeeds = replyCount + " Reply Seeds";
            objSeedDetail.Comments=   commentsCount + " Comments";
            objSeedDetail.RootSeedID =seedData.id.ToString();
            objSeedDetail.ParentSeedID = seedData.parentSeedID != null ? seedData.parentSeedID.ToString() : seedData.id.ToString();
            string tmpCategory = "";
            foreach (Category c in seedData.Categories)
            {
                if (tmpCategory.Length > 0)
                    tmpCategory = tmpCategory + ", " + c.name;
                else
                    tmpCategory = c.name;
            }
            objSeedDetail.Categories = tmpCategory;
            if (seedData.Tags != null && seedData.Tags.Count > 0)
            {
                objSeedDetail.Keywords = seedData.Tags.FirstOrDefault().name.ToString();

            }
            else
            {
                objSeedDetail.Keywords = "";
            }

            objSeedDetail.MemberID = seedData.Member.id.ToString();
            objSeedDetail.Zip = seedData.Location.zipcode;

            int counter = objSeed.getSeedRatingCountByMemberId(SeedId, MemberId, "Like");

            if (counter > 0)
            {
             objSeedDetail.Rating= "Disable";
            }
            else
            {
                objSeedDetail.Rating = "Enable";
            }

            objSeedDetail.Latitude = seedData.Location.localLat.ToString();
            objSeedDetail.Longitude = seedData.Location.localLong.ToString();

            string imgPath = "No Image";

            if (seedData.Media != null && seedData.Media.Where(x => x.type.Equals("Image")).Count() > 0)
            {
                imgPath = seedData.Media.Where(x => x.type.Equals("Image")).OrderByDescending(x => x.dateUploaded).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.Path = imgPath;

            lstSeedDetail.Add(objSeedDetail);
            return lstSeedDetail;
        }
Пример #2
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;
        }