Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Presentation Layer
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DAL;

namespace _3_tiersample
{
    public partial class RegistrationForm : System.Web.UI.Page
    {
        classBLL Objbal = new classBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
         
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                string Output = string.Empty;
                classBLL Objbalregistration = new classBLL();
                Objbalregistration.Name = TextBox1.Text;
                Objbalregistration.Roll_Number = Convert.ToInt32(TextBox2.Text);
                Objbalregistration.Email_Id = TextBox3.Text;
                Objbalregistration.Mobile_Number = TextBox4.Text;
                Objbalregistration.InsertUserDetails(Objbal);
                Console.WriteLine("Data Inserted");
            }
            catch(Exception Ex)
            {
                Console.WriteLine(Ex);
            }
        }

    }
}

Business Logic Layer
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;


namespace BLL
{
    public class classBLL
    {
        private string _Name;
        private int _Roll_Number;
        private string _Email_Id;
        public string _Mobile_Number;


        public string Name
        {
            set { _Name = value; }
            get { return _Name; }
        }
        public int Roll_Number
        {
            set { _Roll_Number = value; }
            get { return _Roll_Number; }
        }
        public string Email_Id
        {
            set { _Email_Id = value; }
            get { return _Email_Id; }
        }
        public string Mobile_Number
        {
            set { _Mobile_Number = value; }
            get { return _Mobile_Number; }
        }

    }
}


Data Access Layer
C#
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using BLL;

namespace DAL
{
    public class classDAL
    {
        string connection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
     
        public void InsertUserDetails(classBLL Objbal)
      {
          SqlConnection con = new SqlConnection(connection);
          SqlCommand cmd = new SqlCommand("sp_InsertEmpdetails", con);
          cmd.CommandType = CommandType.StoredProcedure;
          con.Open();
          try
          {
              cmd.Parameters.AddWithValue("@Name", Objbal.Name);
              cmd.Parameters.AddWithValue("@Roll_Number", Objbal.Roll_Number);
              cmd.Parameters.AddWithValue("@Email_Id", Objbal.Email_Id);
              cmd.Parameters.AddWithValue("@Mobile_Number", Objbal.Mobile_Number);
              Console.WriteLine( "data saved");
          }
          catch (Exception Ex)
          {
              Console.WriteLine(Ex);
          }
          finally
          {
              con.Dispose();
          }

      }
       
    }  
}

In the above code i have written the business Logic Layer code in Dataaccesslayer i mean my business rule is to insert the data into database but i have written the logic in data access layer but i want it to write in business logic layer.what is the code to write within the business logic layer.(in real time everyone used to write the business logic code with in the Business logic layer right)
Help me Out i'am getting Confused
Thanks in advance
Posted
Updated 5-Mar-14 22:53pm
v2

The code-block of "Business Logic Layer" from your question is actually Entities(creating variables for fields to be used on other layers). And the method InsertUserDetails is missing there. So in your ClassCLL you have to create that method & you should pass values to Data Access Layer.

Passing values from page to Data Access Layer is not a good method. So you have to create a layer for businesslogics.
Quote:
what is the business logic code for this three tier architecture application?
And you should know about differences between tiers & layers.
Difference in layer and tier architecture[^]
3 Layer vs 3 Tier Architecture | Difference Between 3 Layer and 3 Tier Architecture[^]
And this one is ultimate
Dude, where's my business logic?[^]

Here few articles on your topic
3-Tier Architecture in C# Web Application[^]
Three Layer Architecture in C# .NET[^]
N-Tier Architecture and Tips[^]
 
Share this answer
 
Comments
george4986 6-Mar-14 7:14am    
+5v nice presentation ;-)
raxhemanth 7-Mar-14 1:42am    
thanks raja
refer CP link here....
ASP-Net-Tier-architecture
 
Share this answer
 
Comments
raxhemanth 6-Mar-14 5:07am    
ThankYou So much Opees
OPees 6-Mar-14 5:11am    
:) Welcome
Please refer the below link here....

ASP.NET 3 Tier Architecture[^]

Thanks,
-RG
 
Share this answer
 
Comments
raxhemanth 6-Mar-14 5:07am    
Thankyou Ramu
Ramug10 6-Mar-14 5:12am    
You most welcome.
friend,

Layer is logical. like Presentation layer, Business Layer, Data Access Layer.

but tier is Physical. it means it's totally depends on you environment. or you can say server. like DB server, Application server, and Web server.

So conclusion is

Presentation Layer = Web server / or IIS related things

Business Logic = Application server (Means you DLL, Services Or other API etc. and Data Access Layer also can come.

DB server = Where your DB host or (some time come you Data Access also on it. Or if CLR stored procedures, functions & trigger using).

Thanks,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900