public ActionResult UpdateAttendanceStatus(int eventPageId, int attendanceStatusId)
        {
            if (_workContext.CurrentCustomer.IsGuest())
            {
                return(Json(new { redirect = Url.RouteUrl("Login") }, JsonRequestBehavior.AllowGet));
            }



            try
            {
                if (!Enum.IsDefined(typeof(AttendanceStatus), attendanceStatusId))
                {
                    throw new ApplicationException("Invalid attendance status.");
                }


                var customerId = _workContext.CurrentCustomer.Id;
                var customerAttendanceStatus =
                    _eventPageAttendanceService.GetCustomerAttendanceStatus(eventPageId, customerId);
                var previousAttendanceStatusId = attendanceStatusId;

                if (customerAttendanceStatus == null) // new attendance
                {
                    customerAttendanceStatus = new EventPageAttendance()
                    {
                        EventPageId        = eventPageId,
                        CustomerId         = customerId,
                        AttendanceStatusId = attendanceStatusId,
                        DateCreated        = DateTime.Now,
                        DateUpdated        = DateTime.Now
                    };
                    _eventPageAttendanceService.Insert(customerAttendanceStatus);
                }
                else // update existing attendance
                {
                    previousAttendanceStatusId = customerAttendanceStatus.AttendanceStatusId;
                    customerAttendanceStatus.AttendanceStatusId = attendanceStatusId;
                    customerAttendanceStatus.DateUpdated        = DateTime.Now;
                    _eventPageAttendanceService.Update(customerAttendanceStatus);
                }

                return(Json(new {
                    PreviousAttendanceStatusId = previousAttendanceStatusId,
                    EventPageAttendanceId = customerAttendanceStatus.Id,
                    EventPageId = eventPageId,
                    CustomerId = customerId,
                    AttendanceStatusId = attendanceStatusId,
                    FullName = _workContext.CurrentCustomer.GetFullName(),
                    PictureUrl = _pictureService.GetPictureUrl(
                        _workContext.CurrentCustomer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                        _mobSocialSettings.EventPageAttendanceThumbnailSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar),
                    ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(_workContext.CurrentCustomer, 0) }),
                }));
            }
            catch
            {
                return(Json(false));
            }
        }
        public ActionResult GetInvited(int eventPageId)
        {
            var invited = _eventPageAttendanceService.GetAllInvited(eventPageId);


            if (invited.Count == 0)
            {
                return(Json(null));
            }

            var invitedCustomers = _customerService.GetCustomersByIds(invited.Select(x => x.CustomerId).ToArray());

            var models = new List <object>();

            foreach (var customer in invitedCustomers)
            {
                models.Add(new
                {
                    CustomerId = customer.Id,
                    FullName   = customer.GetFullName(),
                    PictureUrl = _pictureService.GetPictureUrl(
                        customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                        _mobSocialSettings.EventPageAttendanceThumbnailSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar),
                    ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(customer, 0) }),
                });
            }

            return(Json(models));
        }
        public ActionResult InviteFriends(int eventPageId, int[] customerIds)
        {
            if (_workContext.CurrentCustomer.IsGuest())
            {
                return(Json(new { redirect = Url.RouteUrl("Login") }, JsonRequestBehavior.AllowGet));
            }


            var invitedCustomers = _eventPageAttendanceService.InviteFriends(eventPageId, customerIds);

            var models = new List <object>();

            foreach (var customer in invitedCustomers)
            {
                models.Add(new
                {
                    CustomerId = customer.Id,
                    FullName   = customer.GetFullName(),
                    PictureUrl = _pictureService.GetPictureUrl(
                        customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                        _mobSocialSettings.EventPageAttendanceThumbnailSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar),
                    ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(customer, 0) }),
                });
            }

            return(Json(models));
        }
        public ActionResult GetAttendance(int start, int count, int attendanceStatusId)
        {
            if (Enum.IsDefined(typeof(AttendanceStatus), attendanceStatusId))
            {
                return(Json(null));
            }


            var attendances          = new List <EventPageAttendance>();
            var attendanceStatusName = string.Empty;


            switch (attendanceStatusId)
            {
            case (int)AttendanceStatus.Invited:
                attendanceStatusName = AttendanceStatus.Invited.ToString();
                attendances          = _eventPageAttendanceService.GetInvited(start, count);
                break;

            case (int)AttendanceStatus.Going:
                attendanceStatusName = AttendanceStatus.Going.ToString();
                attendances          = _eventPageAttendanceService.GetGoing(start, count);
                break;

            case (int)AttendanceStatus.Maybe:
                attendanceStatusName = AttendanceStatus.Maybe.ToString();
                attendances          = _eventPageAttendanceService.GetMaybies(start, count);
                break;

            case (int)AttendanceStatus.NotGoing:
                attendanceStatusName = AttendanceStatus.NotGoing.ToString();
                attendances          = _eventPageAttendanceService.GetNotGoing(start, count);
                break;
            }

            var customerIds = attendances.Select(x => x.CustomerId).ToArray();
            var customers   = _customerService.GetCustomersByIds(customerIds);

            var models = new List <object>();

            foreach (var customer in customers)
            {
                models.Add(new
                {
                    FullName   = customer.GetFullName(),
                    PictureUrl = _pictureService.GetPictureUrl(
                        customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                        _mobSocialSettings.EventPageAttendanceThumbnailSize, _customerSettings.DefaultAvatarEnabled,
                        defaultPictureType: PictureType.Avatar),
                    ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(customer, 0) }),
                });
            }

            return(Json(new
            {
                AttendanceStatusName = attendanceStatusName,
                Customers = models
            }));
        }
        public ActionResult GetUninvitedFriends(int eventPageId, int index)
        {
            var customerId = _workContext.CurrentCustomer.Id;

            var uninvitedFriends = _eventPageAttendanceService.GetUninvitedFriends(eventPageId, customerId,
                                                                                   index, 20);


            if (uninvitedFriends.Count == 0)
            {
                return(Json(null));
            }

            var uninvitedFriendsAsCustomers = _customerService.GetCustomersByIds(
                uninvitedFriends.Select(x => (x.ToCustomerId == customerId)
                    ? x.FromCustomerId
                    : x.ToCustomerId)
                .ToArray());

            var models = new List <object>();

            foreach (var customer in uninvitedFriendsAsCustomers)
            {
                models.Add(new
                {
                    CustomerId = customer.Id,
                    FullName   = customer.GetFullName(),
                    PictureUrl = _pictureService.GetPictureUrl(
                        customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                        _mobSocialSettings.EventPageAttendanceThumbnailSize, _customerSettings.DefaultAvatarEnabled,
                        defaultPictureType: PictureType.Avatar),
                    ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(customer, 0) }),
                });
            }

            return(Json(models));
        }
        public ActionResult FeaturedVideos()
        {
            var model = new FeaturedVideosModel();

            var featuredVideos = _customerVideoAlbumService.GetFeaturedVideos();

            /*foreach (var video in featuredVideos)
             * {*/

            if (featuredVideos != null)
            {
                var videoCustomer = _customerService.GetCustomerById(featuredVideos.VideoAlbum.CustomerId);


                var featuredVideoUrlParts = featuredVideos.VideoUrl.Split('/');

                var embedId = featuredVideoUrlParts.LastOrDefault();

                var featuredVideoModel = new FeaturedVideoModel()
                {
                    ThumbnailUrl       = "//img.youtube.com/vi/" + embedId + "/1.jpg",
                    CustomerProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(videoCustomer, 0) })
                };

                model.FeaturedVideos.Add(featuredVideoModel);
            }


            return(View(MobSocialConstant.ViewsPath + "/mobSocial/_FeaturedVideosBlock.cshtml", model));
        }
        // todo add security to pertinent actions
        public ActionResult Team(int teamId)
        {
            var team = _socialNetworkService.GetTeam(teamId);

            if (teamId == 1 && team == null)
            {
                CreateSampleData();
                team = _socialNetworkService.GetTeam(teamId);
            }



            var model = new TeamPageModel()
            {
                TeamName        = team.Name,
                TeamDescription = team.Description,
                TeamPictureUrl  = team.TeamPictureUrl
            };

            var groupPages = team.GroupPages.OrderBy(x => x.DisplayOrder);

            // team groups
            foreach (var group in groupPages)
            {
                var groupModel = new TeamPageGroupModel()
                {
                    Name        = group.Name,
                    Description = group.Description,
                };


                var groupMembers = group.Members.OrderBy(x => x.DisplayOrder);

                // team group members
                foreach (var member in groupMembers)
                {
                    var memberCustomer     = _customerService.GetCustomerById(member.CustomerId);
                    var memberThumbnailUrl = _pictureService.GetPictureUrl(
                        memberCustomer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                        150,
                        true);


                    groupModel.Members.Add(new TeamPageGroupMemberModel()
                    {
                        DisplayName  = memberCustomer.GetFullName(),
                        ProfileUrl   = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(memberCustomer, 0) }),
                        ThumbnailUrl = memberThumbnailUrl
                    });
                }

                model.Groups.Add(groupModel);
            }

            return(View(MobSocialConstant.ViewsPath + "/mobSocial/TeamPage.cshtml", model));
        }
        // todo add security to pertinent actions
        public ActionResult CustomerFriends(int customerId)
        {
            if (customerId == -1)
            {
                customerId = _workContext.CurrentCustomer.Id;
            }

            var friends = _socialNetworkService.GetFriends(customerId);

            var model = new List <CustomerFriendsModel>();

            foreach (var friend in friends)
            {
                var friendId = (friend.FromCustomerId == customerId) ? friend.ToCustomerId : friend.FromCustomerId;

                var friendCustomer = _customerService.GetCustomerById(friendId);

                if (friendCustomer == null)
                {
                    continue;
                }

                var friendThumbnailUrl = _pictureService.GetPictureUrl(
                    friendCustomer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                    100,
                    true);

                model.Add(new CustomerFriendsModel()
                {
                    CustomerDisplayName = friendCustomer.GetFullName().ToTitleCase(),
                    ProfileUrl          = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(friendCustomer, 0) }),
                    ProfileThumbnailUrl = friendThumbnailUrl
                });
            }



            return(View(MobSocialConstant.ViewsPath + "/mobSocial/_CustomerFriends.cshtml", model));
        }
        public ActionResult FriendRequests()
        {
            var friendRequests = _socialNetworkService.GetFriendRequests(_workContext.CurrentCustomer.Id);

            var model = new FriendRequestsModel();

            model.NavigationModel = SessionState.Instance.CustomerNavigationModel;

            foreach (var request in friendRequests)
            {
                var friendId           = request.FromCustomerId;
                var friendCustomer     = _customerService.GetCustomerById(friendId);
                var friendThumbnailUrl = _pictureService.GetPictureUrl(
                    friendCustomer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                    75);

                model.FriendRequests.Add(new FriendRequestModel()
                {
                    FriendId            = friendId,
                    CustomerDisplayName = friendCustomer.GetFullName(),
                    ProfileUrl          = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(friendCustomer, 0) }),
                    ProfileThumbnailUrl = friendThumbnailUrl
                });
            }



            return(View(MobSocialConstant.ViewsPath + "/mobSocial/FriendRequests.cshtml", model));
        }
        public ActionResult SearchTermAutoComplete(string term, bool excludeLoggedInUser = true)
        {
            if (String.IsNullOrWhiteSpace(term) || term.Length < _mobSocialSettings.PeopleSearchTermMinimumLength)
            {
                return(Json(new object()));
            }

            _mobSocialSettings.PeopleSearchAutoCompleteNumberOfResults = 10;

            //TODO: Find a better way to implement this search

            //a search term may be first name or last name...nopcommerce puts an 'and' filter rather than an 'or' filter.
            //we therefore need to first get all the customers and then filter them according to name

            var customerRole    = _customerService.GetCustomerRoleBySystemName("Registered");
            var customerRoleIds = new int[1];

            if (customerRole != null)
            {
                customerRoleIds[0] = customerRole.Id;
            }

            var customers = _customerService.GetAllCustomers(null, null, 0, 0, customerRoleIds).ToList();

            customers = excludeLoggedInUser ? customers.Where(x => x.Id != _workContext.CurrentCustomer.Id).ToList() : customers;
            var count = _mobSocialSettings.PeopleSearchAutoCompleteNumberOfResults;

            term = term.ToLowerInvariant();
            var filteredCustomers = new List <Customer>();

            customers.ForEach(x =>
            {
                if (filteredCustomers.Count >= _mobSocialSettings.PeopleSearchAutoCompleteNumberOfResults)
                {
                    return;
                }

                var firstName = x.GetAttribute <string>(SystemCustomerAttributeNames.FirstName);
                firstName     = firstName == null ? "" : firstName.ToLowerInvariant();
                var lastName  = x.GetAttribute <string>(SystemCustomerAttributeNames.LastName);
                lastName      = lastName == null ? "" : lastName.ToLowerInvariant();
                var email     = x.Email;
                if (!firstName.Contains(term) && !lastName.Contains(term) && email != term)
                {
                    return;
                }

                count--;
                filteredCustomers.Add(x);
            });


            var models = new List <object>();

            foreach (var c in filteredCustomers)
            {
                models.Add(new
                {
                    DisplayName = c.GetFullName(),
                    PictureUrl  = _pictureService.GetPictureUrl(
                        c.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), 50),

                    ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(c, 0) }),
                    Id         = c.Id
                });
            }

            return(Json(models, JsonRequestBehavior.AllowGet));
        }