public IHttpActionResult GetFriends([FromUri] FriendSearchModel requestModel) { if (requestModel == null || !ModelState.IsValid) { requestModel = new FriendSearchModel() { Count = int.MaxValue, Page = 1, ExcludeLoggedInUser = true, SearchTerm = "" }; } var currentUser = ApplicationContext.Current.CurrentUser; var friends = _friendService.GetFriends(currentUser.Id, requestModel.Page, int.MaxValue, true).Where(x => x.Confirmed).Take(requestModel.Count).ToList(); //get user entities var userIds = friends.Select(x => x.FromCustomerId == currentUser.Id ? x.ToCustomerId : x.FromCustomerId).ToArray(); var users = _userService.Get(x => userIds.Contains(x.Id)).ToList(); //todo: implement checks to evaluate last login time and see if the user is online var model = users.Select(x => x.ToModel(_pictureService, _mediaSettings)).ToList(); return(RespondSuccess(new { Friends = model })); }
public IHttpActionResult SearchPeople([FromUri] FriendSearchModel model) { var customers = _mobSocialService.SearchPeople(model.SearchTerm, model.ExcludeLoggedInUser, model.Page, model.Count); var models = new List <object>(); //get all the friends of logged in customer IList <CustomerFriend> friends = null; if (_workContext.CurrentCustomer.IsRegistered()) { friends = _friendService.GetAllCustomerFriends(_workContext.CurrentCustomer.Id); } if (friends == null) { friends = new List <CustomerFriend>(); } foreach (var c in customers) { var friendModel = new FriendPublicModel() { Id = c.Id, DisplayName = c.GetFullName(), PictureUrl = _pictureService.GetPictureUrl( c.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId)), ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new RouteValueDictionary() { { "SeName", c.GetSeName(_workContext.WorkingLanguage.Id, true, false) } }), }; var friend = friends.FirstOrDefault(x => x.FromCustomerId == c.Id || x.ToCustomerId == c.Id); if (friend == null) { friendModel.FriendStatus = FriendStatus.None; } else if (friend.Confirmed) { friendModel.FriendStatus = FriendStatus.Friends; } else if (!friend.Confirmed && friend.FromCustomerId == _workContext.CurrentCustomer.Id) { friendModel.FriendStatus = FriendStatus.FriendRequestSent; } else if (_workContext.CurrentCustomer.Id == c.Id) { friendModel.FriendStatus = FriendStatus.Self; } else { friendModel.FriendStatus = FriendStatus.NeedsConfirmed; } models.Add(friendModel); } return(Json(new { Success = true, People = models })); }
public IHttpActionResult SearchPeople([FromUri] FriendSearchModel model) { var customers = _userService.SearchUsers(model.SearchTerm, model.ExcludeLoggedInUser, model.Page, model.Count); var models = new List <object>(); var currentUser = ApplicationContext.Current.CurrentUser; //get all the friends of logged in customer IList <Friend> friends = null; if (currentUser.IsRegistered()) { friends = _friendService.GetAllCustomerFriends(currentUser.Id); } if (friends == null) { friends = new List <Friend>(); } foreach (var c in customers) { var friendModel = new FriendPublicModel() { Id = c.Id, DisplayName = c.GetPropertyValueAs <string>(PropertyNames.DisplayName), PictureUrl = _pictureService.GetPictureUrl(c.GetPropertyValueAs <int>(PropertyNames.DefaultPictureId)), ProfileUrl = Url.Route("CustomerProfileUrl", new RouteValueDictionary() { { "SeName", c.GetPermalink().ToString() } }), }; var friend = friends.FirstOrDefault(x => x.FromCustomerId == c.Id || x.ToCustomerId == c.Id); if (friend == null) { friendModel.FriendStatus = FriendStatus.None; } else if (friend.Confirmed) { friendModel.FriendStatus = FriendStatus.Friends; } else if (!friend.Confirmed && friend.FromCustomerId == currentUser.Id) { friendModel.FriendStatus = FriendStatus.FriendRequestSent; } else if (currentUser.Id == c.Id) { friendModel.FriendStatus = FriendStatus.Self; } else { friendModel.FriendStatus = FriendStatus.NeedsConfirmed; } models.Add(friendModel); } return(Json(new { Success = true, People = models })); }
public ActionResult SearchPeople(string searchTerm = "", bool excludeLoggedInUser = true, int page = 1, int count = 15) { var model = new FriendSearchModel() { SearchTerm = searchTerm, ExcludeLoggedInUser = excludeLoggedInUser, Count = count, Page = page }; return(View("mobSocial/Friends/SearchPeople", model)); }