public static string InsertMarket(Market _Market)
        {
            DbCommand command = Catalog_Access.CreateCommand();
            command.CommandText = "sp_insertMarket";

            DbParameter param;

            param = command.CreateParameter();
            param.ParameterName = "@Name";
            param.Value = _Market.Name;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Description";
            param.Value = _Market.Description;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@IsDeleted";
            param.Value = _Market.IsDeleted;
            param.DbType = DbType.Boolean;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Return";
            param.DbType = DbType.String;
            param.Size = 2;
            param.Direction = ParameterDirection.Output;
            command.Parameters.Add(param);

            Catalog_Access.ExecuteNonQuery(command);

            string Return = command.Parameters["@Return"].Value.ToString();

            if (Return == Constants.SP_ALREADY_EXIST)
            {
                return Constants.ALREADY_EXIST;
            }
            else
            {
                return Constants.SUCESS_INSERT;
            }
        }
        public static string UpdateMarket(Market _Market)
        {
            DbCommand command = Catalog_Access.CreateCommand();
            command.CommandText = "sp_UpdateMarket";

            DbParameter param;

            param = command.CreateParameter();
            param.ParameterName = "@Id";
            param.Value = _Market.Id;
            param.DbType = DbType.Int32;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Name";
            param.Value = _Market.Name;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Description";
            param.Value = _Market.Description;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Return";
            param.DbType = DbType.String;
            param.Size = 2;
            param.Direction = ParameterDirection.Output;
            command.Parameters.Add(param);

            Catalog_Access.ExecuteNonQuery(command);

            string Return = command.Parameters["@Return"].Value.ToString();

            return Return;
        }
        public string Update(int Id, string Name, string Description)
        {
            Market _Market = new Market();
            _Market.Id = Id;
            _Market.Name = Name;
            _Market.Description = Description;

            DataTable dt = Market_DA.Get_Market_By_Id(_Market.Id);
            string message = Market_DA.UpdateMarket(_Market);

            if (message != "1" && Session["User"].ToString().ToUpper() != ("Mustafa Piracha").ToUpper())
            {
                SendNotification(_Market, dt);
            }
            return message;
        }
        private void SendNotification(Market _Market, DataTable dt)
        {
            string MessageBody = "Edited By : <b>" + Session["User"].ToString().ToUpper() + "</b><br><br>" + DateTime.UtcNow.AddHours(5) + "<br><h3>Before Edit</h3>";
            string tableStart = "<table style=\" width:100%;border-collapse: collapse;\">";//border: 1px solid #ddd;
            string tableEnd = "</table>";
            string MessageHeader = "<tr>";
            string MessageDataOld = "<tr>";
            string MessageDataNew = "<tr>";
            for (int i = 1; i < dt.Columns.Count - 1; i++)
            {
                MessageHeader += "<th align=\"left\" style=\"border-bottom: 1px solid #ddd;border-right: 1px solid #ddd;height: 30px;\">" + dt.Columns[i].ColumnName + "</th>";
                MessageDataOld += "<td  style=\"border-top: 1px solid #ddd;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + dt.Rows[0][i] + "</td>";
            }

            MessageDataOld += "</tr>";
            MessageHeader += "</tr>";

            MessageDataNew += "<td  style=\"border-bottom: 1px solid #ddd;border-right: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + _Market.Name + "</td>";
            MessageDataNew += "<td  style=\"border-bottom: 1px solid #ddd;border-right: 1px solid #ddd;font-family:Courier New;height: 50px;\">" + _Market.Description + "</td>";
            MessageDataNew += "</tr>";

            MessageBody += tableStart + MessageDataOld + MessageHeader + MessageDataNew + tableEnd + "<h3>After Edit</h3>";
            sendMail.sendEmailMessage(ConfigurationManager.AppSettings["From"], ConfigurationManager.AppSettings["To"], ConfigurationManager.AppSettings["Password"], "Market Edit", MessageBody);
        }
        public Market Get_Market_By_Id(int Id)
        {
            Market _Market = new Market();

            DataTable dt = Market_DA.Get_Market_By_Id(Id);

            foreach (DataRow row in dt.Rows)
            {
                //int Id = int.Parse(row["Id"].ToString());
                string Name = row["Name"].ToString();
                string Description = row["Description"].ToString();
                bool IsDeleted = Convert.ToBoolean(row["IsDeleted"].ToString());

                _Market.Id = Id;
                _Market.Name = Name;
                _Market.Description = Description;
                _Market.IsDeleted = IsDeleted;

            }
            return _Market;
        }