コード例 #1
0
        private void UpdateSearchUsers(List <User> newList)
        {
            SearchedUsers.RemoveItems(SearchedUsers.Where(w => !newList.Any(a => a.FirebaseKey == w.FirebaseKey)).ToArray());

            SearchedUsers.AddRange(newList
                                   .Where(w => !SearchedUsers.Any(a => a.FirebaseKey == w.FirebaseKey))
                                   .Select(s => new UserViewModel(s)));
        }
コード例 #2
0
        public IHttpActionResult SearchMembers(UserSearch search)
        {
            List <AspNetUser>    list_AspNetUser = null;
            List <SearchedUsers> searchedUsers   = new List <SearchedUsers>();
            StringBuilder        query           = new StringBuilder();

            try
            {
                var  userId      = User.Identity.GetUserId();
                bool validSearch = false;
                //Get employee
                List <string> searchList = new List <string>();
                if (search.School != "All Schools")
                {
                    validSearch = true;
                    searchList.Add(" School = '" + search.School + "' ");
                }
                if (search.Batch != "All Batches")
                {
                    validSearch = true;
                    searchList.Add(" LeavingYear = '" + search.Batch + "' ");
                }
                if (search.Profession != "All Professions" && search.Profession != "All Categories")
                {
                    validSearch = true;
                    searchList.Add(" Profession = '" + search.Profession + "' ");
                }
                if (!string.IsNullOrEmpty(search.FirstName))
                {
                    validSearch = true;
                    searchList.Add(" FirstName like '%" + search.FirstName + "%' ");
                }
                if (!string.IsNullOrEmpty(search.LastName))
                {
                    validSearch = true;
                    searchList.Add(" LastName like '%" + search.LastName + "%' ");
                }
                if (!string.IsNullOrEmpty(search.Department))
                {
                    validSearch = true;
                    searchList.Add(" Department like '%" + search.Department + "%' ");
                }
                if (!string.IsNullOrEmpty(search.Designation))
                {
                    validSearch = true;
                    searchList.Add(" Designation like '%" + search.Designation + "%' ");
                }
                if (search.City != "All Cities")
                {
                    validSearch = true;
                    searchList.Add(" Posting = '" + search.City + "' ");
                }
                if (!string.IsNullOrEmpty(search.RollNo))
                {
                    validSearch = true;
                    searchList.Add(" RollNo = '" + search.RollNo + "' ");
                }
                if (validSearch)
                {
                    query.Append("select * from AspNetUsers where ");

                    foreach (var s in searchList)
                    {
                        query.Append(s);
                        if (searchList.Count > 1)
                        {
                            query.Append(" and ");
                        }
                    }
                    if (query.ToString().EndsWith(" and "))
                    {
                        query.Remove(query.ToString().Length - 5, 5);
                    }
                    LogApi.Log(User.Identity.GetUserId(), "SearchMembers " + query.ToString());
                    list_AspNetUser = db.AspNetUsers.SqlQuery(query.ToString()).ToList <AspNetUser>();

                    SearchedUsers SearchedUser = null;
                    foreach (var x in list_AspNetUser)
                    {
                        SearchedUser             = new SearchedUsers();
                        SearchedUser.Id          = x.Id;
                        SearchedUser.FirstName   = x.FirstName;
                        SearchedUser.LastName    = x.LastName;
                        SearchedUser.Address     = x.Address;
                        SearchedUser.BloodGroup  = x.BloodGroup;
                        SearchedUser.City        = x.City;
                        SearchedUser.Department  = x.Department;
                        SearchedUser.School      = x.School;
                        SearchedUser.Designation = x.Designation;
                        SearchedUser.House       = x.House;
                        SearchedUser.PostalCode  = x.PostalCode;
                        SearchedUser.Posting     = x.Posting;
                        SearchedUser.RollNo      = x.RollNo;
                        SearchedUser.JoiningYear = x.JoiningYear;
                        SearchedUser.LeavingYear = x.LeavingYear;
                        SearchedUser.PhoneNumber = x.PhoneNumber;
                        SearchedUser.Profession  = x.Profession;
                        SearchedUser.ProfileLink = x.ProfileLink;
                        searchedUsers.Add(SearchedUser);
                    }
                }
            }
            catch (Exception ex)
            {
                return(Ok(ex.Message + "  " + query));
            }
            return(Ok(searchedUsers.OrderBy(u => u.JoiningYear)));
        }