Ejemplo n.º 1
0
 protected virtual void FireAfterPerform(ActionEventArgs e)
 {
     if (AfterPerform != null)
         AfterPerform(this, e);
 }
Ejemplo n.º 2
0
 protected virtual void FireBeforePerform(ActionEventArgs e)
 {
     _e.FireCancelableEvent(BeforePerform, this, e);
 }
Ejemplo n.º 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)
                    {

                    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;
        }