Exemple #1
0
        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));
            }
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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 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 <CustomerFriendModel>();

            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 CustomerFriendModel()
                {
                    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 CustomerProfile(ProfileIndexModel model)
        {
            var customerId = model.CustomerProfileId;

            //increment view count
            _customerProfileViewService.IncrementViewCount(customerId);

            //get customer object
            var customer = _customerService.GetCustomerById(customerId);

            if (customer == null)
            {
                return(null);
            }
            var profile = _customerProfileService.GetByCustomerId(customerId);

            var customerSeName = SeoExtensions.GetSeName(customer, _workContext.WorkingLanguage.Id, true, false);
            var profilemodel   = new CustomerProfilePublicModel()
            {
                CustomerId        = customerId,
                ViewCount         = _customerProfileViewService.GetViewCount(customerId),
                FriendCount       = _customerProfileService.GetFriendCount(customerId),
                CustomerName      = customer.GetFullName(),
                SeName            = customerSeName,
                ProfileUrl        = Url.RouteUrl("CustomerProfileUrl", new { SeName = customerSeName }),
                ProfileImageUrl   = _pictureService.GetPictureUrl(customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, true),
                CoverImageUrl     = _pictureService.GetPictureUrl(customer.GetAttribute <int>(AdditionalCustomerAttributeNames.CoverImageId)),
                ProfileIndexModel = model
            };

            if (_workContext.CurrentCustomer.Id == customerId)
            {
                profilemodel.FriendStatus = FriendStatus.Self;
                profilemodel.IsEditable   = true;
            }
            else
            {
                //depending on who is viewing the profile, let's set the friend status and other relevent values
                var customerFriend = _friendService.GetCustomerFriendship(_workContext.CurrentCustomer.Id, customer.Id);
                if (customerFriend == null)
                {
                    profilemodel.FriendStatus = FriendStatus.None;
                }
                else if (customerFriend.Confirmed)
                {
                    profilemodel.FriendStatus = FriendStatus.Friends;
                }
                else if (!customerFriend.Confirmed && customerFriend.FromCustomerId == _workContext.CurrentCustomer.Id)
                {
                    profilemodel.FriendStatus = FriendStatus.FriendRequestSent;
                }
                else
                {
                    profilemodel.FriendStatus = FriendStatus.NeedsConfirmed;
                }
            }

            //and the follower counts & logged in user following status
            var followers = _customerFollowService.GetFollowers <CustomerProfile>(customerId);

            profilemodel.FollowingStatus = followers.Any(x => x.CustomerId == _workContext.CurrentCustomer.Id) ? 1 : 0;
            profilemodel.FollowerCount   = followers.Count;
            return(View("mobSocial/CustomerProfile/Profile", profilemodel));
        }