<commit_before>﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web;
using System.Collections.Generic;
using Microsoft.ApplicationBlocks.Data;
using GRA.SRP.Core.Utilities;

namespace GRA.SRP.DAL
{

    [Serializable()]
    public class Badge : EntityBase
    {
        public static new string Version { get { return "2.0"; } }

        #region Private Variables

        private static string conn = GlobalUtilities.SRPDB;

        #endregion

        #region Accessors

        public int BID { get; set; }
        public string AdminName { get; set; }
        public string UserName { get; set; }
        public bool GenNotificationFlag { get; set; }
        public string NotificationSubject { get; set; }
        public string NotificationBody { get; set; }
        public string CustomEarnedMessage { get; set; }
        public bool HideDefaultDescriptionFlag { get; set; }
        public string CustomDescription { get; set; }
        public bool IncludesPhysicalPrizeFlag { get; set; }
        public string PhysicalPrizeName { get; set; }
        public bool AssignProgramPrizeCode { get; set; }
        public string PCNotificationSubject { get; set; }
        public string PCNotificationBody { get; set; }
        public DateTime LastModDate { get; set; }
        public string LastModUser { get; set; }
        public DateTime AddedDate { get; set; }
        public string AddedUser { get; set; }
        public int TenID { get; set; }
        public int FldInt1 { get; set; }
        public int FldInt2 { get; set; }
        public int FldInt3 { get; set; }
        public bool FldBit1 { get; set; }
        public bool FldBit2 { get; set; }
        public bool FldBit3 { get; set; }
        public string FldText1 { get; set; }
        public string FldText2 { get; set; }
        public string FldText3 { get; set; }
        public bool HiddenFromPublic { get; set; }
        #endregion

        #region Constructors

        public Badge()
        {
            this.TenID = (HttpContext.Current.Session["TenantID"] == null || HttpContext.Current.Session["TenantID"].ToString() == "" ? -1 : (int)HttpContext.Current.Session["TenantID"]);
            this.NotificationSubject = string.Empty;
            this.NotificationBody = string.Empty;
            this.CustomEarnedMessage = string.Empty;
            this.CustomDescription = string.Empty;
            this.PhysicalPrizeName = string.Empty;
            this.PCNotificationSubject = string.Empty;
            this.PCNotificationBody = string.Empty;
            this.FldText1 = string.Empty;
            this.FldText2 = string.Empty;
            this.FldText3 = string.Empty;
        }

        #endregion

        #region stored procedure wrappers

        public static DataSet GetList(string ids)
        {
            SqlParameter[] arrParams = new SqlParameter[1];
            arrParams[0] = new SqlParameter("@ids", ids);
            return SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "app_Badge_GetList", arrParams);
        }

        public static int GetVisibleCount()
        {
            var arrParams = new SqlParameter[1];
            arrParams[0] = new SqlParameter("@TenID",
                                (HttpContext.Current.Session["TenantID"] == null || HttpContext.Current.Session["TenantID"].ToString() == "" ?
                                        -1 :
                                        (int)HttpContext.Current.Session["TenantID"])
                            );


            var result = SqlHelper.ExecuteScalar(conn, CommandType.StoredProcedure, "app_Badge_GetVisibleCount", arrParams);
            if (result == null)
            {
                return 0;
            }
            else
            {
                return (int)result;
            }
        }

        public static DataSet GetAll()
        {
            var arrParams = new SqlParameter[1];
            arrParams[0] = new SqlParameter("@TenID",
                                (HttpContext.Current.Session["TenantID"] == null || HttpContext.Current.Session["TenantID"].ToString() == "" ?
                                        -1 :
                                        (int)HttpContext.Current.Session["TenantID"])
                            );


            return SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "app_Badge_GetAll", arrParams);
        }

        public static DataSet GetAll(int TenID)
        {
            var arrParams = new SqlParameter[1];
            arrParams[0] = new SqlParameter("@TenID", TenID);

            return SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "app_Badge_GetAll", arrParams);
        }

        public static Badge FetchObject(int BID)
        {

            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

            if (dr.Read())
            {

                // declare return value

                Badge result = new Badge();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["BID"].ToString(), out _int)) result.BID = _int;
                result.AdminName = dr["AdminName"].ToString();
                result.UserName = dr["UserName"].ToString();
                result.GenNotificationFlag = bool.Parse(dr["GenNotificationFlag"].ToString());
                result.NotificationSubject = dr["NotificationSubject"].ToString();
                result.NotificationBody = dr["NotificationBody"].ToString();
                result.CustomEarnedMessage = dr["CustomEarnedMessage"].ToString();
                result.HideDefaultDescriptionFlag = bool.Parse(dr["HideDefaultDescriptionFlag"].ToString());
                result.CustomDescription = dr["CustomDescription"].ToString();
                result.IncludesPhysicalPrizeFlag = bool.Parse(dr["IncludesPhysicalPrizeFlag"].ToString());
                result.PhysicalPrizeName = dr["PhysicalPrizeName"].ToString();
                result.AssignProgramPrizeCode = bool.Parse(dr["AssignProgramPrizeCode"].ToString());
                result.PCNotificationSubject = dr["PCNotificationSubject"].ToString();
                result.PCNotificationBody = dr["PCNotificationBody"].ToString();
                if (DateTime.TryParse(dr["LastModDate"].ToString(), out _datetime)) result.LastModDate = _datetime;
                result.LastModUser = dr["LastModUser"].ToString();
                if (DateTime.TryParse(dr["AddedDate"].ToString(), out _datetime)) result.AddedDate = _datetime;
                result.AddedUser = dr["AddedUser"].ToString();

                if (int.TryParse(dr["TenID"].ToString(), out _int)) result.TenID = _int;
                if (int.TryParse(dr["FldInt1"].ToString(), out _int)) result.FldInt1 = _int;
                if (int.TryParse(dr["FldInt2"].ToString(), out _int)) result.FldInt2 = _int;
                if (int.TryParse(dr["FldInt3"].ToString(), out _int)) result.FldInt3 = _int;
                result.FldBit1 = bool.Parse(dr["FldBit1"].ToString());
                result.FldBit2 = bool.Parse(dr["FldBit2"].ToString());
                result.FldBit3 = bool.Parse(dr["FldBit3"].ToString());
                result.FldText1 = dr["FldText1"].ToString();
                result.FldText2 = dr["FldText2"].ToString();
                result.FldText3 = dr["FldText3"].ToString();<commit_msg>Accept null values without error<commit_after>﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web;
using System.Collections.Generic;
using Microsoft.ApplicationBlocks.Data;
using GRA.SRP.Core.Utilities;

namespace GRA.SRP.DAL
{

    [Serializable()]
    public class Badge : EntityBase
    {
        public static new string Version { get { return "2.0"; } }

        #region Private Variables

        private static string conn = GlobalUtilities.SRPDB;

        #endregion

        #region Accessors

        public int BID { get; set; }
        public string AdminName { get; set; }
        public string UserName { get; set; }
        public bool GenNotificationFlag { get; set; }
        public string NotificationSubject { get; set; }
        public string NotificationBody { get; set; }
        public string CustomEarnedMessage { get; set; }
        public bool HideDefaultDescriptionFlag { get; set; }
        public string CustomDescription { get; set; }
        public bool IncludesPhysicalPrizeFlag { get; set; }
        public string PhysicalPrizeName { get; set; }
        public bool AssignProgramPrizeCode { get; set; }
        public string PCNotificationSubject { get; set; }
        public string PCNotificationBody { get; set; }
        public DateTime LastModDate { get; set; }
        public string LastModUser { get; set; }
        public DateTime AddedDate { get; set; }
        public string AddedUser { get; set; }
        public int TenID { get; set; }
        public int FldInt1 { get; set; }
        public int FldInt2 { get; set; }
        public int FldInt3 { get; set; }
        public bool FldBit1 { get; set; }
        public bool FldBit2 { get; set; }
        public bool FldBit3 { get; set; }
        public string FldText1 { get; set; }
        public string FldText2 { get; set; }
        public string FldText3 { get; set; }
        public bool HiddenFromPublic { get; set; }
        #endregion

        #region Constructors

        public Badge()
        {
            this.TenID = (HttpContext.Current.Session["TenantID"] == null || HttpContext.Current.Session["TenantID"].ToString() == "" ? -1 : (int)HttpContext.Current.Session["TenantID"]);
            this.NotificationSubject = string.Empty;
            this.NotificationBody = string.Empty;
            this.CustomEarnedMessage = string.Empty;
            this.CustomDescription = string.Empty;
            this.PhysicalPrizeName = string.Empty;
            this.PCNotificationSubject = string.Empty;
            this.PCNotificationBody = string.Empty;
            this.FldText1 = string.Empty;
            this.FldText2 = string.Empty;
            this.FldText3 = string.Empty;
        }

        #endregion

        #region stored procedure wrappers

        public static DataSet GetList(string ids)
        {
            SqlParameter[] arrParams = new SqlParameter[1];
            arrParams[0] = new SqlParameter("@ids", ids);
            return SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "app_Badge_GetList", arrParams);
        }

        public static int GetVisibleCount()
        {
            var arrParams = new SqlParameter[1];
            arrParams[0] = new SqlParameter("@TenID",
                                (HttpContext.Current.Session["TenantID"] == null || HttpContext.Current.Session["TenantID"].ToString() == "" ?
                                        -1 :
                                        (int)HttpContext.Current.Session["TenantID"])
                            );


            var result = SqlHelper.ExecuteScalar(conn, CommandType.StoredProcedure, "app_Badge_GetVisibleCount", arrParams);
            if (result == null)
            {
                return 0;
            }
            else
            {
                return (int)result;
            }
        }

        public static DataSet GetAll()
        {
            var arrParams = new SqlParameter[1];
            arrParams[0] = new SqlParameter("@TenID",
                                (HttpContext.Current.Session["TenantID"] == null || HttpContext.Current.Session["TenantID"].ToString() == "" ?
                                        -1 :
                                        (int)HttpContext.Current.Session["TenantID"])
                            );


            return SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "app_Badge_GetAll", arrParams);
        }

        public static DataSet GetAll(int TenID)
        {
            var arrParams = new SqlParameter[1];
            arrParams[0] = new SqlParameter("@TenID", TenID);

            return SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "app_Badge_GetAll", arrParams);
        }

        public static Badge FetchObject(int BID)
        {

            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

            if (dr.Read())
            {

                // declare return value

                Badge result = new Badge();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["BID"].ToString(), out _int)) result.BID = _int;
                result.AdminName = dr["AdminName"].ToString();
                result.UserName = dr["UserName"].ToString();
                result.GenNotificationFlag = bool.Parse(dr["GenNotificationFlag"].ToString());
                result.NotificationSubject = dr["NotificationSubject"].ToString();
                result.NotificationBody = dr["NotificationBody"].ToString();
                result.CustomEarnedMessage = dr["CustomEarnedMessage"].ToString();
                result.HideDefaultDescriptionFlag = dr["HideDefaultDescriptionFlag"] as bool? ?? false;
                result.CustomDescription = dr["CustomDescription"] as string;
                result.IncludesPhysicalPrizeFlag = bool.Parse(dr["IncludesPhysicalPrizeFlag"].ToString());
                result.PhysicalPrizeName = dr["PhysicalPrizeName"].ToString();
                result.AssignProgramPrizeCode = bool.Parse(dr["AssignProgramPrizeCode"].ToString());
                result.PCNotificationSubject = dr["PCNotificationSubject"].ToString();
                result.PCNotificationBody = dr["PCNotificationBody"].ToString();
                if (DateTime.TryParse(dr["LastModDate"].ToString(), out _datetime)) result.LastModDate = _datetime;
                result.LastModUser = dr["LastModUser"].ToString();
                if (DateTime.TryParse(dr["AddedDate"].ToString(), out _datetime)) result.AddedDate = _datetime;
                result.AddedUser = dr["AddedUser"].ToString();

                if (int.TryParse(dr["TenID"].ToString(), out _int)) result.TenID = _int;
                if (int.TryParse(dr["FldInt1"].ToString(), out _int)) result.FldInt1 = _int;
                if (int.TryParse(dr["FldInt2"].ToString(), out _int)) result.FldInt2 = _int;
                if (int.TryParse(dr["FldInt3"].ToString(), out _int)) result.FldInt3 = _int;
                result.FldBit1 = bool.Parse(dr["FldBit1"].ToString());
                result.FldBit2 = bool.Parse(dr["FldBit2"].ToString());
                result.FldBit3 = bool.Parse(dr["FldBit3"].ToString());
                result.FldText1 = dr["FldText1"].ToString();
                result.FldText2 = dr["FldText2"].ToString();
                result.FldText3 = dr["FldText3"].ToString();
{'fraction_non_alphanumeric': 0.11014112241549065, 'fraction_numerical': 0.006038726616343945, 'mean_word_length': 2.050861033239888, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4285248', 'n_tokens_mistral': 4086, 'n_tokens_neox': 3931, 'n_words': 870}