Example #1
0
        public static PatronBadges FetchObject(int PBID)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@PBID", PBID);

            dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_PatronBadges_GetByID", arrParams);

            if (dr.Read())
            {
                // declare return value

                PatronBadges result = new PatronBadges();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["PBID"].ToString(), out _int))
                {
                    result.PBID = _int;
                }
                if (int.TryParse(dr["PID"].ToString(), out _int))
                {
                    result.PID = _int;
                }
                if (int.TryParse(dr["BadgeID"].ToString(), out _int))
                {
                    result.BadgeID = _int;
                }
                if (DateTime.TryParse(dr["DateEarned"].ToString(), out _datetime))
                {
                    result.DateEarned = _datetime;
                }

                dr.Close();

                return(result);
            }

            dr.Close();

            return(null);
        }
Example #2
0
        public static int Insert(PatronBadges o)
        {
            SqlParameter[] arrParams = new SqlParameter[4];

            arrParams[0]           = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode()));
            arrParams[1]           = new SqlParameter("@BadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeID, o.BadgeID.GetTypeCode()));
            arrParams[2]           = new SqlParameter("@DateEarned", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.DateEarned, o.DateEarned.GetTypeCode()));
            arrParams[3]           = new SqlParameter("@PBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PBID, o.PBID.GetTypeCode()));
            arrParams[3].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronBadges_Insert", arrParams);

            o.PBID = int.Parse(arrParams[3].Value.ToString());

            return(o.PBID);
        }
Example #3
0
        public static int Delete(PatronBadges o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@PBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PBID, o.PBID.GetTypeCode()));

            try
            {
                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronBadges_Delete", arrParams);
            }

            catch (SqlException exx)
            {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            return(iReturn);
        }
        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;
            }
        }
        public static PatronBadges FetchObject(int PBID)
        {

            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@PBID", PBID);

            dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_PatronBadges_GetByID", arrParams);

            if (dr.Read())
            {

                // declare return value

                PatronBadges result = new PatronBadges();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["PBID"].ToString(), out _int)) result.PBID = _int;
                if (int.TryParse(dr["PID"].ToString(), out _int)) result.PID = _int;
                if (int.TryParse(dr["BadgeID"].ToString(), out _int)) result.BadgeID = _int;
                if (DateTime.TryParse(dr["DateEarned"].ToString(), out _datetime)) result.DateEarned = _datetime;

                dr.Close();

                return result;

            }

            dr.Close();

            return null;

        }
        public static int Delete(PatronBadges o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@PBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PBID, o.PBID.GetTypeCode()));

            try
            {

                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronBadges_Delete", arrParams);

            }

            catch (SqlException exx)
            {

                System.Diagnostics.Debug.Write(exx.Message);

            }

            return iReturn;

        }
        public static int Insert(PatronBadges o)
        {

            SqlParameter[] arrParams = new SqlParameter[4];

            arrParams[0] = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@BadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeID, o.BadgeID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@DateEarned", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.DateEarned, o.DateEarned.GetTypeCode()));
            arrParams[3] = new SqlParameter("@PBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PBID, o.PBID.GetTypeCode()));
            arrParams[3].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronBadges_Insert", arrParams);

            o.PBID = int.Parse(arrParams[3].Value.ToString());

            return o.PBID;

        }