Lisen

Lisen

  • NA
  • 63
  • 1.6k

model and repository in C#

Nov 29 2018 6:05 AM
Hi,
 
i am working in a C# project using model and repository..
 
im not sure if im using the method correctly or not because im new in C# programming
i am adding some code in below.. pls tell me if im using it correctly or not..
 
for me its working fine..
 
but i want to use with begin,commit and rollback
 
pls help me in this matter
 
models.cs
  1. namespace sample.Models  
  2. {  
  3. class Model_Sample  
  4. {  
  5. public string Database { getset; }  
  6. public string ServerInstance { getset; }  
  7. public string UserID { getset; }  
  8. public string Password { getset; }  
  9. }  
  10. class Model_Customer  
  11. {  
  12. public int CustomerID { getset; }  
  13. public string CustomerName { getset; }  
  14. public int age { getset; }  
  15. public string Phone { getset; }  
  16. }  
  17. }  
Repository.cs
  1. public List< Model_Customer > Customer(Model_Sample data, Model_Customer mCustomer)  
  2. {  
  3. IDbConnection db = new SqlConnection("Data Source=" + data.Instance + ";Initial Catalog=" + data.Database + ";User ID=" + data.UserID + ";Password=" + data.Password + "");  
  4. List<Model_Customer> list = db.Query<Model_Customer>("ProcCustomerCRUD", mCustomer,  
  5. commandType: CommandType.StoredProcedure).ToList<Model_Customer>();  
  6. return list;  
windows form
  1. public partial class frmCustomerMaster : Form  
  2. {  
  3. Model_Sample data= new Model_Sample ();  
  4. Model_Customer mycustomer = new Model_Customer();  
  5. private void BtnSave_Click(object sender, EventArgs e)  
  6. {  
  7. mycustomer.CustomerID = Convert.ToInt32(txtcustomerID.text);  
  8. mycustomer.CustomerName = txtCustomerName.text  
  9. mycustomer.age = Convert.ToInt32(txtage.text);  
  10. mycustomer.phone = txtphone.Text;  
  11. rep.Customer(data, mycustomer);  
  12. }  
  13. }  

Answers (4)