Beispiel #1
0
        public string Add(UserSession userSession, string username)
        {
            string resultString = "";
            User.eAddFriendResult result = userSession.AddToFriends(username);
            switch (result)
            {
                case Classes.User.eAddFriendResult.eAlreadyAdded:
                    resultString = Lang.Trans("The user you selected already exists in your friend list");
                    break;
                case Classes.User.eAddFriendResult.eInvalidUsername:
                    resultString = Lang.Trans("No such user!");
                    break;
                case Classes.User.eAddFriendResult.eMaximumFriendsReached:
                    resultString =
                        String.Format(
                            Lang.Trans(
                                "The maximum friends of {0} is reached! Please remove someone and try again!"),
                            Config.Users.MaxFriendUsers);
                    break;
                case Classes.User.eAddFriendResult.eSuccess:
                    if (Classes.User.IsUserInFriendList(username, userSession.Username))
                    {
                        resultString = String.Format(Lang.Trans("{0} has been added to your friend list"), username);
                        AddNewFriendFriendEvent(username, userSession.Username);
                        AddNewFriendFriendEvent(userSession.Username, username);
                    }
                    else
                    {
                        resultString = String.Format(Lang.Trans("Friendship request has been sent to {0}"), username);
                    }

                    if (Config.Users.NewEventNotification)
                    {
                        int imageID = 0;
                        User user = null;
                        try
                        {
                            user = Classes.User.Load(username);
                        }
                        catch (NotFoundException) { break; }

                        try
                        {
                            imageID = Photo.GetPrimary(userSession.Username).Id;
                        }
                        catch (NotFoundException)
                        {
                            imageID = ImageHandler.GetPhotoIdByGender(userSession.Gender);
                        }
                        string text = String.Format("User {0} added you to friends".Translate(),
                                              "<b>" + userSession.Username + "</b>");

                        string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                        Classes.User.SendOnlineEventNotification(userSession.Username, user.Username, text,
                                                                 thumbnailUrl,
                                                                 UrlRewrite.CreateShowUserUrl(
                                                                     userSession.Username));
                    }
                    break;
            }
            return resultString;
        }