Example #1
0
        public bool Allowed(int performer, int id, int receiver, string comment)
        {
            if (performer > 0 && (!MandatoryComment || (MandatoryComment && comment.Length >= _minCommentLenght) )) {

                if (AllowedGroups != null && AllowedGroups.Length > 0)
                {
                    bool allowed = false;
                    foreach(string group in AllowedGroups)
                        if(Library.Utils.IsMemberInGroup(group, performer)){
                            allowed = true;
                            break;
                        }

                    if(!allowed)
                        return false;
                }

                Reputation r = new Reputation(performer);

                bool doneBefore = Data.SqlHelper.ExecuteScalar<int>("SELECT count(id) from " + DataBaseTable + " WHERE id = @id and memberId = @memberId",
                    Data.SqlHelper.CreateParameter("@id", id),
                    Data.SqlHelper.CreateParameter("@memberId", performer)
                    ) > 0;

                return ( (MinimumReputation <= r.Current) && !doneBefore && performer != receiver);
            } else
                return false;
        }
Example #2
0
        public bool Allowed(int performer, int id, int receiver, string comment)
        {
            if (performer > 0 && (!MandatoryComment || (MandatoryComment && comment.Length >= _minCommentLenght)))
            {
                if (AllowedGroups != null && AllowedGroups.Length > 0)
                {
                    var allowed = false;
                    foreach (var group in AllowedGroups)
                    {
                        if (Library.Utils.IsMemberInGroup(group, performer))
                        {
                            allowed = true;
                            break;
                        }
                    }

                    if (!allowed)
                    {
                        return(false);
                    }
                }

                var reputation = new Reputation(performer);
                using (var sqlHelper = Application.SqlHelper)
                {
                    var doneBefore = sqlHelper.ExecuteScalar <int>(
                        "SELECT count(id) from " + DataBaseTable +
                        " WHERE id = @id and memberId = @memberId",
                        sqlHelper.CreateParameter("@id", id),
                        sqlHelper.CreateParameter("@memberId", performer)
                        ) > 0;

                    return(MinimumReputation <= reputation.Current && !doneBefore && performer != receiver);
                }
            }

            return(false);
        }
Example #3
0
        public bool Perform(int performer, int itemId, int receiver, string comment)
        {
            ActionEventArgs e = new ActionEventArgs();

            e.PerformerId = performer;
            e.ItemId      = itemId;
            e.ReceiverId  = receiver;
            e.ActionType  = TypeAlias;

            FireBeforePerform(e);



            if (!e.Cancel)
            {
                bool allowed = Allowed(performer, itemId, receiver, comment);

                if (allowed)
                {
                    using (var sqlHelper = Application.SqlHelper)
                    {
                        sqlHelper.ExecuteNonQuery(
                            "INSERT INTO " + DataBaseTable +
                            "(id, memberId, points, receiverId, receiverPoints, performerPoints, comment) VALUES(@id, @memberId, @points, @receiverId, @receiverPoints, @performerPoints, @comment)",
                            sqlHelper.CreateParameter("@id", e.ItemId),
                            sqlHelper.CreateParameter("@table", DataBaseTable),
                            sqlHelper.CreateParameter("@memberId", e.PerformerId),
                            sqlHelper.CreateParameter("@points", Weight),
                            sqlHelper.CreateParameter("@receiverid", e.ReceiverId),
                            sqlHelper.CreateParameter("@receiverPoints", ReceiverReward),
                            sqlHelper.CreateParameter("@performerPoints", PerformerReward),
                            sqlHelper.CreateParameter("@comment", comment + " ")
                            );
                    }

                    //the performer gets his share
                    if (PerformerReward != 0)
                    {
                        Reputation r = new Reputation(e.PerformerId);
                        r.Current = (r.Current + (PerformerReward));
                        r.Total   = (r.Total + (PerformerReward));
                        r.Save();
                    }

                    //And maybe the author of the item gets a cut as well..
                    if (e.ReceiverId > 0 && ReceiverReward != 0)
                    {
                        Reputation pr = new Reputation(e.ReceiverId);
                        pr.Current = (pr.Current + (ReceiverReward));
                        pr.Total   = (pr.Total + (ReceiverReward));
                        pr.Save();
                    }

                    //And maybe there are some additional receivers
                    if (e.ExtraReceivers != null)
                    {
                        foreach (int r in e.ExtraReceivers)
                        {
                            if (allowed)
                            {
                                using (var sqlHelper = Application.SqlHelper)
                                {
                                    //make sure the extra receivers also get inserted (but no points for item and performer)
                                    sqlHelper.ExecuteNonQuery(
                                        "INSERT INTO " + DataBaseTable +
                                        "(id, memberId, points, receiverId, receiverPoints, performerPoints, comment) VALUES(@id, @memberId, @points, @receiverId, @receiverPoints, @performerPoints, @comment)",
                                        sqlHelper.CreateParameter("@id", e.ItemId),
                                        sqlHelper.CreateParameter("@table", DataBaseTable),
                                        sqlHelper.CreateParameter("@memberId", e.PerformerId),
                                        sqlHelper.CreateParameter("@points", 0),
                                        sqlHelper.CreateParameter("@receiverid", r),
                                        sqlHelper.CreateParameter("@receiverPoints", ReceiverReward),
                                        sqlHelper.CreateParameter("@performerPoints", 0),
                                        sqlHelper.CreateParameter("@comment", comment + " "));
                                }
                            }

                            Reputation pr = new Reputation(r);
                            pr.Current = (pr.Current + (ReceiverReward));
                            pr.Total   = (pr.Total + (ReceiverReward));
                            pr.Save();
                        }
                    }


                    FireAfterPerform(e);
                    return(true);
                }
            }

            return(false);
        }
Example #4
0
        public bool Perform(int performer, int itemId, int receiver, string comment)
        {
            ActionEventArgs e = new ActionEventArgs();
                e.PerformerId = performer;
                e.ItemId = itemId;
                e.ReceiverId = receiver;
                e.ActionType = TypeAlias;

                FireBeforePerform(e);

                if (!e.Cancel) {

                    bool allowed = Allowed(performer, itemId, receiver, comment);

                    if (allowed)
                    {

                    Data.SqlHelper.ExecuteNonQuery("INSERT INTO " + DataBaseTable + "(id, memberId, points, receiverId, receiverPoints, performerPoints, comment) VALUES(@id, @memberId, @points, @receiverId, @receiverPoints, @performerPoints, @comment)",
                        Data.SqlHelper.CreateParameter("@id", e.ItemId),
                        Data.SqlHelper.CreateParameter("@table", DataBaseTable),
                        Data.SqlHelper.CreateParameter("@memberId", e.PerformerId),
                        Data.SqlHelper.CreateParameter("@points", Weight),
                        Data.SqlHelper.CreateParameter("@receiverid", e.ReceiverId),
                        Data.SqlHelper.CreateParameter("@receiverPoints", ReceiverReward),
                        Data.SqlHelper.CreateParameter("@performerPoints", PerformerReward),
                        Data.SqlHelper.CreateParameter("@comment", comment + " ")
                    );

                    //the performer gets his share
                    if(PerformerReward != 0){
                        Reputation r = new Reputation(e.PerformerId);
                        r.Current = (r.Current + (PerformerReward) );
                        r.Total = (r.Total + (PerformerReward) );
                        r.Save();
                    }

                    //And maybe the author of the item gets a cut as well..
                    if (e.ReceiverId > 0 && ReceiverReward != 0) {
                        Reputation pr = new Reputation(e.ReceiverId);
                        pr.Current = (pr.Current + (ReceiverReward) );
                        pr.Total = (pr.Total + (ReceiverReward));
                        pr.Save();
                    }

                    //And maybe there are some additional receivers
                    if (e.ExtraReceivers != null)
                    {
                        foreach (int r in e.ExtraReceivers)
                        {
                            if (allowed)
                            {
                                //make sure the extra receivers also get inserted (but no points for item and performer)
                                Data.SqlHelper.ExecuteNonQuery("INSERT INTO " + DataBaseTable + "(id, memberId, points, receiverId, receiverPoints, performerPoints, comment) VALUES(@id, @memberId, @points, @receiverId, @receiverPoints, @performerPoints, @comment)",
                                    Data.SqlHelper.CreateParameter("@id", e.ItemId),
                                    Data.SqlHelper.CreateParameter("@table", DataBaseTable),
                                    Data.SqlHelper.CreateParameter("@memberId", e.PerformerId),
                                    Data.SqlHelper.CreateParameter("@points", 0),
                                    Data.SqlHelper.CreateParameter("@receiverid", r),
                                    Data.SqlHelper.CreateParameter("@receiverPoints", ReceiverReward),
                                    Data.SqlHelper.CreateParameter("@performerPoints", 0),
                                    Data.SqlHelper.CreateParameter("@comment", comment + " "));
                            }
                            Reputation pr = new Reputation(r);
                            pr.Current = (pr.Current + (ReceiverReward));
                            pr.Total = (pr.Total + (ReceiverReward));
                            pr.Save();
                        }
                    }

                    FireAfterPerform(e);
                    return true;
                }
            }

            return false;
        }
Example #5
0
        public bool Allowed(int performer, int id, int receiver, string comment)
        {
            if (performer > 0 && (!MandatoryComment || (MandatoryComment && comment.Length >= _minCommentLenght) )) {

                if (AllowedGroups != null && AllowedGroups.Length > 0)
                {
                    bool allowed = false;
                    foreach(string group in AllowedGroups)
                        if(Library.Utils.IsMemberInGroup(group, performer)){
                            allowed = true;
                            break;
                        }

                    if(!allowed)
                        return false;
                }

                Reputation r = new Reputation(performer);

                bool doneBefore = Data.SqlHelper.ExecuteScalar<int>("SELECT count(id) from " + DataBaseTable + " WHERE id = @id and memberId = @memberId",
                    Data.SqlHelper.CreateParameter("@id", id),
                    Data.SqlHelper.CreateParameter("@memberId", performer)
                    ) > 0;

                return ( (MinimumReputation <= r.Current) && !doneBefore && performer != receiver);
            } else
                return false;
        }