Ejemplo n.º 1
0
    public static void CreateUserCustomGroup(UserCustomGroup userGroup, CustomGroup customGroup, IEnumerable <AdPack> adPackList, Member user, string name, string description, string videoURL = "",
                                             string email = "", string skype = "", string phoneNumber = "", string facebookURL = "")
    {
        userGroup.CreatorUserId = user.Id;
        userGroup.Name          = name;
        userGroup.Description   = description;

        if (!string.IsNullOrWhiteSpace(videoURL))
        {
            userGroup.PromoUrl = videoURL;
        }

        if (!string.IsNullOrWhiteSpace(email))
        {
            userGroup.Email = email;
        }

        if (!string.IsNullOrWhiteSpace(skype))
        {
            userGroup.Skype = skype;
        }

        if (!string.IsNullOrWhiteSpace(phoneNumber))
        {
            userGroup.PhoneNumber = phoneNumber;
        }

        if (!string.IsNullOrWhiteSpace(facebookURL))
        {
            userGroup.FacebookUrl = facebookURL;
        }

        userGroup.CustomGroupId = customGroup.Id;
        userGroup.AdPacksAdded  = adPackList.Count();
        userGroup.GotBonus      = false;


        userGroup.Save();

        foreach (AdPack adpack in adPackList)
        {
            adpack.UserCustomGroupId = userGroup.Id;
            adpack.Save();
        }
    }
Ejemplo n.º 2
0
    protected void JoinLeaveGroupButton_Click(object sender, EventArgs e)
    {
        SPanel.Visible = false;
        EPanel.Visible = false;

        try
        {
            int numberOfAdPacks = Convert.ToInt32(AdPacksTextBox.Text);

            if (numberOfAdPacks <= 0)
            {
                throw new MsgException(U4200.CANTBUYZEROADPACKS.Replace("%n%", AppSettings.RevShare.AdPack.AdPackName));
            }

            var TheButton = (Button)sender;

            if (TheButton.CommandArgument == "true")
            {
                CustomGroupManager.AddRemoveUsersAdPacksToCustomGroup(User.Id, numberOfAdPacks, userCustomGroup, true);
            }
            else if (TheButton.CommandArgument == "false")
            {
                CustomGroupManager.AddRemoveUsersAdPacksToCustomGroup(User.Id, numberOfAdPacks, userCustomGroup, false);
            }

            SPanel.Visible = true;
            if (TheButton.CommandArgument == "true")
            {
                SText.Text = U4200.JOINGROUPSUCCESS.Replace("%n%", userCustomGroup.Name).Replace("%p%", numberOfAdPacks + " " + AppSettings.RevShare.AdPack.AdPackNamePlural);
            }
            else if (TheButton.CommandArgument == "false")
            {
                SText.Text = U4200.LEAVEGROUPSUCCESS.Replace("%n%", numberOfAdPacks.ToString()).Replace("%p%", AppSettings.RevShare.AdPack.AdPackNamePlural);
            }

            CustomGroup customGroup = new CustomGroup(userCustomGroup.CustomGroupId);
            if (userCustomGroup.AdPacksAdded >= customGroup.AdPacksLimit)
            {
                if (AppSettings.RevShare.AdPack.CustomReturnOption == CustomReturnOption.Increase)
                {
                    CustomGroupManager.IncreaseAdPacksReturnAmountInClosedGroup(customGroup, userCustomGroup);
                }
                userCustomGroup.Status = CustomGroupStatus.Active;

                if (AppSettings.RevShare.AdPack.RevShareCustomGroupRewardsEnabled)
                {
                    GroupRewardManager.Apply(customGroup, userCustomGroup);
                }
            }
            else
            {
                userCustomGroup.Status = CustomGroupStatus.InProgress;
            }

            userCustomGroup.Save();

            UpdateAvailableAdPacks();
            DataBind();
        }
        catch (MsgException ex)
        {
            EPanel.Visible = true;
            EText.Text     = ex.Message;
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
        }
    }
Ejemplo n.º 3
0
    public static void AddRemoveUsersAdPacksToCustomGroup(int userId, int numberOfAdPacks, UserCustomGroup userCustomGroup, bool join)
    {
        CustomGroup customGroup = new CustomGroup(userCustomGroup.CustomGroupId);

        if (userId == userCustomGroup.CreatorUserId && !join)
        {
            var packsAvailableToWithdraw = AdPackManager.GetUsersActiveAdPacksForGroups(userId, customGroup, userCustomGroup.Id).Count - customGroup.CreatorsMinNumberOfAdPacks;
            if (numberOfAdPacks > packsAvailableToWithdraw)
            {
                throw new MsgException(U4200.NOTENOUGHADPACKSAVAILABLEFORGROUPS.Replace("%n%", AppSettings.RevShare.AdPack.AdPackNamePlural));
            }
        }

        List <AdPack> allAdPacksList;

        if (join)
        {
            allAdPacksList = AdPackManager.GetUsersActiveAdPacksForGroups(userId, customGroup, -1);
        }
        else
        {
            allAdPacksList = AdPackManager.GetUsersActiveAdPacksForGroups(userId, customGroup, userCustomGroup.Id);
        }


        //HAS ENOUGH ADPACKS?
        if (allAdPacksList.Count < numberOfAdPacks)
        {
            throw new MsgException(U4200.NOTENOUGHADPACKSAVAILABLEFORGROUPS.Replace("%n%", AppSettings.RevShare.AdPack.AdPackNamePlural));
        }

        IEnumerable <AdPack> adPacksList = (from a in allAdPacksList select a).Take(numberOfAdPacks);

        //NUMBER OF PACKS TO CLOSE
        if (join)
        {
            if (customGroup.AdPacksLimit - userCustomGroup.AdPacksAdded < numberOfAdPacks)
            {
                throw new MsgException(U4200.TOOMANYPACKS.Replace("%n%", AppSettings.RevShare.AdPack.AdPackNamePlural) + " " + (customGroup.AdPacksLimit - userCustomGroup.AdPacksAdded));
            }

            //Max number of creator/user adpack limit check
            var  myCurrentAdPacksInThisGroupCount = AdPackManager.GetUsersActiveAdPacksForGroups(userId, customGroup, userCustomGroup.Id).Count;
            bool IsGroupCreator = userId == userCustomGroup.CreatorUserId;

            if (IsGroupCreator && myCurrentAdPacksInThisGroupCount + numberOfAdPacks > customGroup.CreatorsMaxNumberOfAdPacks)
            {
                throw new MsgException(U4200.TOOMANYPACKS.Replace("%n%", AppSettings.RevShare.AdPack.AdPackNamePlural) + " " + (customGroup.CreatorsMaxNumberOfAdPacks - myCurrentAdPacksInThisGroupCount));
            }

            if (!IsGroupCreator && myCurrentAdPacksInThisGroupCount + numberOfAdPacks > customGroup.UsersMaxNumberOfAdPacks)
            {
                throw new MsgException(U4200.TOOMANYPACKS.Replace("%n%", AppSettings.RevShare.AdPack.AdPackNamePlural) + " " + (customGroup.UsersMaxNumberOfAdPacks - myCurrentAdPacksInThisGroupCount));
            }
        }
        else
        {
            if (customGroup.AdPacksLimit == userCustomGroup.AdPacksAdded)
            {
                throw new MsgException("Can't leave closed group");
            }
        }

        if (join)
        {
            userCustomGroup.AdPacksAdded += numberOfAdPacks;
            foreach (AdPack adpack in adPacksList)
            {
                adpack.UserCustomGroupId = userCustomGroup.Id;
                adpack.Save();
            }
        }
        else
        {
            userCustomGroup.AdPacksAdded -= numberOfAdPacks;
            foreach (AdPack adpack in adPacksList)
            {
                adpack.UserCustomGroupId = -1;
                adpack.Save();
            }
        }

        userCustomGroup.Save();
    }