public static bool AwardBadgeToPatron(int badgeToAward, Patron patron, ref List<Badge> earnedBadges)
        {
            var now = DateTime.Now;

            // check if badge was already earned...
            var pbds = PatronBadges.GetAll(patron.PID);
            var a = pbds.Tables[0].AsEnumerable().Where(r => r.Field<int>("BadgeID") == badgeToAward);

            var newTable = new DataTable();
            try { newTable = a.CopyToDataTable(); } catch { }

            // badge not found, award it!
            if(newTable.Rows.Count == 0) {
                var pb = new PatronBadges { BadgeID = badgeToAward, DateEarned = now, PID = patron.PID };
                pb.Insert();

                var earnedBadge = Badge.GetBadge(badgeToAward);
                if(earnedBadge != null) {
                    earnedBadges.Add(earnedBadge);

                    //if badge generates notification, then generate the notification
                    if(earnedBadge.GenNotificationFlag) {
                        var not = new Notifications {
                            PID_To = patron.PID,
                            PID_From = 0,  //0 == System Notification
                            Subject = earnedBadge.NotificationSubject,
                            Body = earnedBadge.NotificationBody,
                            isQuestion = false,
                            AddedDate = now,
                            LastModDate = now,
                            AddedUser = patron.Username,
                            LastModUser = "******"
                        };
                        not.Insert();
                    }

                    //if badge generates prize, then generate the prize
                    if(earnedBadge.IncludesPhysicalPrizeFlag) {
                        var ppp = new DAL.PatronPrizes {
                            PID = patron.PID,
                            PrizeSource = 1,
                            BadgeID = badgeToAward,
                            PrizeName = earnedBadge.PhysicalPrizeName,
                            RedeemedFlag = false,
                            AddedUser = patron.Username,
                            LastModUser = "******",
                            AddedDate = now,
                            LastModDate = now
                        };

                        ppp.Insert();
                    }

                    // if badge generates award code, then generate the code
                    if(earnedBadge.AssignProgramPrizeCode) {
                        var rewardCode= string.Empty;
                        // get the Code value
                        // save the code value for the patron
                        rewardCode = ProgramCodes.AssignCodeForPatron(patron.ProgID, patron.ProgID);

                        // generate the notification
                        var not = new Notifications {
                            PID_To = patron.PID,
                            PID_From = 0,  //0 == System Notification
                            Subject = earnedBadge.PCNotificationSubject,
                            Body = earnedBadge.PCNotificationBody.Replace("{ProgramRewardCode}", rewardCode),
                            isQuestion = false,
                            AddedDate = now,
                            LastModDate = now,
                            AddedUser = patron.Username,
                            LastModUser = "******"
                        };
                        not.Insert();
                    }
                }

                return true;
            } else {
                return false;
            }
        }
        //protected void btnUnread_Click(object sender, EventArgs e)
        //{
        //    var o = Notifications.FetchObject(int.Parse(NID.Text));
        //    o.isUnread = true;
        //    o.Update();
        //    Response.Redirect("~/Mail/");
        //}

        protected void btnAskSubmit_Click(object sender, EventArgs e) {
            bool somethingHasError = false;
            if(string.IsNullOrWhiteSpace(txtSubject.Text)) {
                somethingHasError = true;
                this.SubjectHasError = "has-error";
            }

            if(string.IsNullOrWhiteSpace(txtBody.Text)) {
                somethingHasError = true;
                this.BodyHasError = "has-error";
            }

            if(!somethingHasError) {
                var o = new Notifications();
                o.PID_From = ((Patron)Session["Patron"]).PID;
                o.PID_To = 0;
                o.isQuestion = true;
                o.Subject = txtSubject.Text;
                o.Body = txtBody.Text;
                o.AddedDate = o.LastModDate = DateTime.Now;
                o.LastModUser = o.AddedUser = ((Patron)Session["Patron"]).Username;
                o.Insert();
                txtSubject.Text = txtBody.Text= string.Empty;

                pnlAsk.Visible = false;
                pnlList.Visible = true;
                new SessionTools(Session).AlertPatron(((BaseSRPPage)this.Page).GetResourceString("notifications-message-sent"),
                                                      glyphicon: "send");
                Response.Redirect("~/Mail/");
            }
        }
Example #3
0
        public static int DrawWinners(int PDID, int numWinners, int additional = 0)
        {
            SqlParameter[] arrParams = new SqlParameter[3];
            arrParams[0] = new SqlParameter("@PDID", PDID);
            arrParams[1] = new SqlParameter("@NumWinners", numWinners);
            arrParams[2] = new SqlParameter("@Additional", additional);
            var ds = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "app_PrizeDrawing_DrawWinners", arrParams);

            var ret = ds.Tables[0].Rows.Count;

            var pd  = PrizeDrawing.FetchObject(PDID);
            var pt  = PrizeTemplate.FetchObject(pd.TID);
            var now = DateTime.Now;

            for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                int PID   = (int)ds.Tables[0].Rows[i]["PatronID"];
                int NID   = (int)ds.Tables[0].Rows[i]["NotificationID"];
                int PDWID = (int)ds.Tables[0].Rows[i]["PDWID"];

                // insert patron prize
                var pp = new PatronPrizes
                {
                    PID          = PID,
                    PrizeSource  = 0,
                    BadgeID      = 0,
                    DrawingID    = PDWID,
                    PrizeName    = pd.PrizeName,
                    RedeemedFlag = false,
                    AddedDate    = now,
                    LastModDate  = now,
                    AddedUser    = "******",
                    LastModUser  = "******"
                };
                pp.Insert();

                if (pt.SendNotificationFlag)
                {
                    // generate notification
                    var not = new Notifications
                    {
                        PID_To      = PID,
                        PID_From    = 0, //0 == System Notification
                        Subject     = pt.NotificationSubject,
                        Body        = pt.NotificationMessage,
                        isQuestion  = false,
                        AddedDate   = now,
                        LastModDate = now,
                        AddedUser   = "******",
                        LastModUser = "******"
                    };
                    not.Insert();

                    var w = PrizeDrawingWinners.FetchObject(PDWID);
                    w.NotificationID = not.NID;
                    w.Update();
                }
                else
                {
                    var w = PrizeDrawingWinners.FetchObject(PDWID);
                    w.NotificationID = -1;
                    w.Update();
                }
            }

            return(ret);
        }
        public static int DrawWinners(int PDID, int numWinners, int additional = 0)
        {
            SqlParameter[] arrParams = new SqlParameter[3];
            arrParams[0] = new SqlParameter("@PDID", PDID);
            arrParams[1] = new SqlParameter("@NumWinners", numWinners);
            arrParams[2] = new SqlParameter("@Additional", additional);
            var ds = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "app_PrizeDrawing_DrawWinners", arrParams);

            var ret = ds.Tables[0].Rows.Count;

            var pd = PrizeDrawing.FetchObject(PDID);
            var pt = PrizeTemplate.FetchObject(pd.TID);
            var now = DateTime.Now;

            for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                int PID = (int)ds.Tables[0].Rows[i]["PatronID"];
                int NID = (int)ds.Tables[0].Rows[i]["NotificationID"];
                int PDWID = (int)ds.Tables[0].Rows[i]["PDWID"];

                // insert patron prize
                var pp = new PatronPrizes
                {
                    PID = PID,
                    PrizeSource = 0,
                    BadgeID = 0,
                    DrawingID = PDWID,
                    PrizeName = pd.PrizeName,
                    RedeemedFlag = false,
                    AddedDate = now,
                    LastModDate = now,
                    AddedUser = "******",
                    LastModUser = "******"
                };
                pp.Insert();

                if (pt.SendNotificationFlag)
                {
                    // generate notification
                    var not = new Notifications
                    {
                        PID_To = PID,
                        PID_From = 0,  //0 == System Notification
                        Subject = pt.NotificationSubject,
                        Body = pt.NotificationMessage,
                        isQuestion = false,
                        AddedDate = now,
                        LastModDate = now,
                        AddedUser = "******",
                        LastModUser = "******"
                    };
                    not.Insert();

                    var w = PrizeDrawingWinners.FetchObject(PDWID);
                    w.NotificationID = not.NID;
                    w.Update();
                }
                else
                {
                    var w = PrizeDrawingWinners.FetchObject(PDWID);
                    w.NotificationID = -1;
                    w.Update();
                }
            }

            return ret;

        }