<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data;
using DataAccessLayer;


/// <summary>
/// Business Access Layer mainly deals with the Business;
/// Since this is a E-commerce site
/// so the main business belongs with product and category and company
/// </summary>
namespace BusinessAccessLayer
{
    public class ECommerceBusiness
    {
        public Category CategoryObj { get; set; }
        public Product ProductObj { get; set; }
        public Company CompanyObj { get; set; }
        public Admin AdminObj { get; set; }
        public User UserObj { get; set; }

        public void addNewCategory()
        {
            SqlParameter[] parameters = new SqlParameter[2];
            parameters[0] = DataAccess.addParameter("@categoryName", CategoryObj.CategoryName);
            parameters[1] = DataAccess.addParameter("@categoryDesc", CategoryObj.CategoryDescription);
            DataAccess.executeDTByProcedure("sp_addNewCategory", parameters);
        }
        public void addNewProduct()
        {
            SqlParameter[] parameters = new SqlParameter[7];
            parameters[0] = DataAccess.addParameter("@productCode", ProductObj.ProductCode);
            parameters[1] = DataAccess.addParameter("@productName", ProductObj.ProductName);
            parameters[2] = DataAccess.addParameter("@description", ProductObj.ProductDescription);
            parameters[3] = DataAccess.addParameter("@price", ProductObj.ProductPrice);
            parameters[4] = DataAccess.addParameter("@categoryID", ProductObj.ProductCategory);
            parameters[5] = DataAccess.addParameter("@companyID", ProductObj.ProductCompany);
            parameters[6] = DataAccess.addParameter("@imageUrl", ProductObj.ProductImage);
            DataAccess.executeDTByProcedure("sp_addNewProduct", parameters);
        }
        public void addNewCompany()
        {
            SqlParameter[] parameters = new SqlParameter[3];
            parameters[0] = DataAccess.addParameter("@CompanyName", CompanyObj.CompanyName);
            parameters[1] = DataAccess.addParameter("@CompanyDesc", CompanyObj.CompanyDescription);
            parameters[2] = DataAccess.addParameter("@PartnershipDate", CompanyObj.PartnershipDate);
            DataAccess.executeDTByProcedure("sp_addNewCompany", parameters);
        }
        public void addNewUser()
        {
            SqlParameter[] parameters = new SqlParameter[10];
            parameters[0] = DataAccess.addParameter("@username", UserObj.getUsername());
            parameters[1] = DataAccess.addParameter("@fullname", UserObj.getFullName());
            parameters[2] = DataAccess.addParameter("@email", UserObj.getEmail());
            parameters[3] = DataAccess.addParameter("@dob", UserObj.getDateOfBirth());
            parameters[4] = DataAccess.addParameter("@age", UserObj.getAge());
            parameters[5] = DataAccess.addParameter("@religion", UserObj.getReligion());
            parameters[6] = DataAccess.addParameter("@password", <PASSWORD>());
            parameters[7] = DataAccess.addParameter("@gender", UserObj.getGender());
            parameters[8] = DataAccess.addParameter("@salt", UserObj.getSalt());
            parameters[9] = DataAccess.addParameter("@hash", UserObj.getHash());
            DataAccess.executeDTByProcedure("sp_addNewUser", parameters);
        }
        public bool selectAdmin()
        {
            SqlParameter[] parameters = new SqlParameter[2];
            parameters[0] = DataAccess.addParameter("@username", AdminObj.UserName);
            parameters[1] = DataAccess.addParameter("@password", <PASSWORD>());
            DataTable dt = DataAccess.executeDTByProcedure("sp_selectAdmin", parameters);

            if (dt == null)
            {
                return false;
            }
            else
            {
                return dt.Rows.Count > 0 ? true : false;
            }
        }
        public bool selectUser()
        {
            SqlParameter[] parameters = new SqlParameter[2];
            parameters[0] = DataAccess.addParameter("@username", UserObj.getUsername());
            parameters[1] = DataAccess.addParameter("@hash", UserObj.getHash());
            DataTable dt = DataAccess.executeDTByProcedure("sp_selectUser", parameters);

            if (dt == null)
            {
                return false;
            }
            else
            {
                return dt.Rows.Count > 0 ? true : false;
            }
        }
        public string retriveSaltAgainstUser()
        {
            string salt;
            SqlParameter[] parameter = new SqlParameter[1];
            parameter[0] = DataAccess.addParameter("@username", UserObj.getUsername());
            DataTable dt = DataAccess.executeDTByProcedure("sp_retriveSaltAgainstUser", parameter);

            if (dt == null)
            {
                salt = null;
            }
            else
            {
                if (dt.Rows.Count > 0)
                {
                    salt = dt.Rows[0]["salt"].ToString();
                }
                else
                {
                    salt = null;
                }
            }
            return salt;
        }
        public DataTable resetPassword()
        {
            SqlParameter[] parameter = new SqlParameter[1];
            parameter[0] = DataAccess.addParameter("@email", UserObj.getEmail());
            DataTable dt = DataAccess.executeDTByProcedure("SP_RESET_PASSWORD", parameter);

            if (dt == null)
            {
                return new DataTable();
            }
            else
            {
                return dt;
            }
        }
        public DataTable getAllCategories()
        {
            // second parameter is set to be null because of it is select query
            DataTable dt = DataAccess.executeDTByProcedure("sp_getAllCategory", null);

            if (dt == null)
            {
                return new DataTable();
            }
            else
            {
                return dt;
            }
        }
        public DataTable getAllCompanies()
        {
            // second parameter is set to be null because of it is select query
            DataTable dt = DataAccess.executeDTByProcedure("sp_getAllCompanies", null);

            if (dt == null)
            {
                return new DataTable();
            }
            else
            {
                return dt;
            }
        }
        public bool IsPasswordResetLinkValid()
        {
            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = DataAccess.addParameter("@GUID", UserObj.GlobalUniqueIDForResetPassword);

            DataTable dt = DataAccess.executeDTByProcedure("SP_IS_PASSWORD_RESET_LINK_VALID", parameters);

            if (dt == null)
            {
                return false;
            }
            else
            {
                if (dt.Rows.Count > 0)
                {
                    return dt.Rows[0]["returnCode"].ToString().Equals("1");
                }
                else
                {
                    return false;
                }
            }
        }
        public bool IsPasswordChanged()
        {
            SqlParameter[] parameters = new SqlParameter[4];
            parameters[0] = DataAccess.addParameter("@GUID", UserObj.GlobalUniqueIDForResetPassword);
            parameters[1] = DataAccess.addParameter("@password", UserObj.getPassword());
            parameters[2] = DataAccess.addParameter("@salt", UserObj.getSalt());
            parameters[3] = DataAccess.addParameter("@hash", UserObj.getHash());

            DataTable dt = DataAccess.executeDTByProcedure("SP_CHANGE_PASSWORD", parameters);

            if (dt == null)
            {
                return false;
            }
            else
            {
                if (dt.Rows.Count > 0)
                {
                    return dt.Rows[0]["returnCode"].ToString().Equals("1");
                }
                else
                {
                    return false;
                }
            }
        }

    }
}
<commit_msg>BusinessAccessLayer modified<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data;
using DataAccessLayer;


/// <summary>
/// Business Access Layer mainly deals with the Business;
/// Since this is a E-commerce site
/// so the main business belongs with product and category and company
/// </summary>
namespace BusinessAccessLayer
{
    public class ECommerceBusiness
    {
        public Category CategoryObj { get; set; }
        public Product ProductObj { get; set; }
        public Company CompanyObj { get; set; }
        public Admin AdminObj { get; set; }
        public User UserObj { get; set; }

        public void addNewCategory()
        {
            SqlParameter[] parameters = new SqlParameter[2];
            parameters[0] = DataAccess.addParameter("@categoryName", CategoryObj.CategoryName);
            parameters[1] = DataAccess.addParameter("@categoryDesc", CategoryObj.CategoryDescription);
            DataAccess.executeDTByProcedure("sp_addNewCategory", parameters);
        }

        public void addNewProduct()
        {
            SqlParameter[] parameters = new SqlParameter[7];
            parameters[0] = DataAccess.addParameter("@productCode", ProductObj.ProductCode);
            parameters[1] = DataAccess.addParameter("@productName", ProductObj.ProductName);
            parameters[2] = DataAccess.addParameter("@description", ProductObj.ProductDescription);
            parameters[3] = DataAccess.addParameter("@price", ProductObj.ProductPrice);
            parameters[4] = DataAccess.addParameter("@categoryID", ProductObj.ProductCategory);
            parameters[5] = DataAccess.addParameter("@companyID", ProductObj.ProductCompany);
            parameters[6] = DataAccess.addParameter("@imageUrl", ProductObj.ProductImage);
            DataAccess.executeDTByProcedure("sp_addNewProduct", parameters);
        }

        public void addNewCompany()
        {
            SqlParameter[] parameters = new SqlParameter[3];
            parameters[0] = DataAccess.addParameter("@CompanyName", CompanyObj.CompanyName);
            parameters[1] = DataAccess.addParameter("@CompanyDesc", CompanyObj.CompanyDescription);
            parameters[2] = DataAccess.addParameter("@PartnershipDate", CompanyObj.PartnershipDate);
            DataAccess.executeDTByProcedure("sp_addNewCompany", parameters);
        }

        public void addNewUser()
        {
            SqlParameter[] parameters = new SqlParameter[10];
            parameters[0] = DataAccess.addParameter("@username", UserObj.getUsername());
            parameters[1] = DataAccess.addParameter("@fullname", UserObj.getFullName());
            parameters[2] = DataAccess.addParameter("@email", UserObj.getEmail());
            parameters[3] = DataAccess.addParameter("@dob", UserObj.getDateOfBirth());
            parameters[4] = DataAccess.addParameter("@age", UserObj.getAge());
            parameters[5] = DataAccess.addParameter("@religion", UserObj.getReligion());
            parameters[6] = DataAccess.addParameter("@password", UserObj.getPassword());
            parameters[7] = DataAccess.addParameter("@gender", UserObj.getGender());
            parameters[8] = DataAccess.addParameter("@salt", UserObj.getSalt());
            parameters[9] = DataAccess.addParameter("@hash", UserObj.getHash());
            DataAccess.executeDTByProcedure("sp_addNewUser", parameters);
        }

        public DataTable selectAdmin()
        {
            SqlParameter[] parameters = new SqlParameter[2];
            parameters[0] = DataAccess.addParameter("@username", AdminObj.UserName);
            parameters[1] = DataAccess.addParameter("@password", <PASSWORD>Obj.<PASSWORD>());
            DataTable dt = DataAccess.executeDTByProcedure("sp_selectAdmin", parameters);

            if (dt == null)
            {
                return new DataTable();
            }
            else
            {
                return dt;
            }
        }

        public bool selectUser()
        {
            SqlParameter[] parameters = new SqlParameter[2];
            parameters[0] = DataAccess.addParameter("@username", UserObj.getUsername());
            parameters[1] = DataAccess.addParameter("@hash", UserObj.getHash());
            DataTable dt = DataAccess.executeDTByProcedure("sp_selectUser", parameters);

            if (dt == null)
            {
                return false;
            }
            else
            {
                return dt.Rows.Count > 0 ? true : false;
            }
        }

        public string retriveSaltAgainstUser()
        {
            string salt;
            SqlParameter[] parameter = new SqlParameter[1];
            parameter[0] = DataAccess.addParameter("@username", UserObj.getUsername());
            DataTable dt = DataAccess.executeDTByProcedure("sp_retriveSaltAgainstUser", parameter);

            if (dt == null)
            {
                salt = null;
            }
            else
            {
                if (dt.Rows.Count > 0)
                {
                    salt = dt.Rows[0]["salt"].ToString();
                }
                else
                {
                    salt = null;
                }
            }
            return salt;
        }

        public DataTable resetPassword()
        {
            SqlParameter[] parameter = new SqlParameter[1];
            parameter[0] = DataAccess.addParameter("@email", UserObj.getEmail());
            DataTable dt = DataAccess.executeDTByProcedure("SP_RESET_PASSWORD", parameter);

            if (dt == null)
            {
                return new DataTable();
            }
            else
            {
                return dt;
            }
        }

        public DataTable getAllCategories()
        {
            // second parameter is set to be null because of it is select query
            DataTable dt = DataAccess.executeDTByProcedure("sp_getAllCategory", null);

            if (dt == null)
            {
                return new DataTable();
            }
            else
            {
                return dt;
            }
        }

        public DataTable getAllCompanies()
        {
            // second parameter is set to be null because of it is select query
            DataTable dt = DataAccess.executeDTByProcedure("sp_getAllCompanies", null);

            if (dt == null)
            {
                return new DataTable();
            }
            else
            {
                return dt;
            }
        }

        public bool IsPasswordResetLinkValid()
        {
            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = DataAccess.addParameter("@GUID", UserObj.GlobalUniqueIDForResetPassword);

            DataTable dt = DataAccess.executeDTByProcedure("SP_IS_PASSWORD_RESET_LINK_VALID", parameters);

            if (dt == null)
            {
                return false;
            }
            else
            {
                if (dt.Rows.Count > 0)
                {
                    return dt.Rows[0]["returnCode"].ToString().Equals("1");
                }
                else
                {
                    return false;
                }
            }
        }

        public bool IsPasswordChanged()
        {
            SqlParameter[] parameters = new SqlParameter[4];
            parameters[0] = DataAccess.addParameter("@GUID", UserObj.GlobalUniqueIDForResetPassword);
            parameters[1] = DataAccess.addParameter("@password", <PASSWORD>());
            parameters[2] = DataAccess.addParameter("@salt", UserObj.getSalt());
            parameters[3] = DataAccess.addParameter("@hash", UserObj.getHash());

            DataTable dt = DataAccess.executeDTByProcedure("SP_CHANGE_PASSWORD", parameters);

            if (dt == null)
            {
                return false;
            }
            else
            {
                if (dt.Rows.Count > 0)
                {
                    return dt.Rows[0]["returnCode"].ToString().Equals("1");
                }
                else
                {
                    return false;
                }
            }
        }

    }
}

{'fraction_non_alphanumeric': 0.10330238570924903, 'fraction_numerical': 0.006287460336114702, 'mean_word_length': 1.6767851525636992, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4139053', 'n_tokens_mistral': 4220, 'n_tokens_neox': 4028, 'n_words': 821}