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 }));
        }
Exemplo n.º 2
0
        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 IHttpActionResult GetFriendRequests()
        {
            var friendRequests = _friendService.GetCustomerFriendRequests(_workContext.CurrentCustomer.Id);

            var friendRequestCustomers =
                _customerService.GetCustomersByIds(friendRequests.Select(x => x.FromCustomerId).ToArray());

            var model = new List <FriendPublicModel>();

            foreach (var c in friendRequestCustomers)
            {
                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) }
                    }),
                    FriendStatus = FriendStatus.NeedsConfirmed
                };
                model.Add(friendModel);
            }

            return(Json(new { Success = true, People = model }));
        }
Exemplo n.º 4
0
        public IHttpActionResult GetFriendRequests()
        {
            var friendRequests = _friendService.GetCustomerFriendRequests(ApplicationContext.Current.CurrentUser.Id);

            var friendRequestCustomers =
                _customerService.Get(x => friendRequests.Select(r => r.FromCustomerId).ToArray().Contains(x.Id), null);

            var model = new List <FriendPublicModel>();

            foreach (var c in friendRequestCustomers)
            {
                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() }
                    }),
                    FriendStatus = FriendStatus.NeedsConfirmed
                };
                model.Add(friendModel);
            }

            return(Json(new { Success = true, People = model }));
        }
        public IHttpActionResult GetFriendRequests()
        {
            var friendRequests         = _friendService.GetFriendRequests(ApplicationContext.Current.CurrentUser.Id);
            var friendUserIds          = friendRequests.Select(x => x.FromCustomerId).ToList();
            var friendRequestCustomers =
                _customerService.Get(x => friendUserIds.Contains(x.Id), null).ToList();

            var model = new List <FriendPublicModel>();

            foreach (var c in friendRequestCustomers)
            {
                var friendModel = new FriendPublicModel()
                {
                    Id           = c.Id,
                    DisplayName  = c.Name,
                    PictureUrl   = _pictureService.GetPictureUrl(c.GetPropertyValueAs <int>(PropertyNames.DefaultPictureId)),
                    SeName       = c.GetPermalink().ToString(),
                    FriendStatus = FriendStatus.NeedsConfirmed
                };
                model.Add(friendModel);
            }

            return(Json(new { Success = true, People = model }));
        }