/// <summary> /// Method adds the values to the table and return true if added or false /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public bool AddContact(AddressBookModel model) { try { using (this.connection) { // Created instance of the given query and connection SqlCommand sqlCommand = new SqlCommand("spContact", this.connection); // Command type as text for stored procedure sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; // Adds the values to the stored procedure sqlCommand.Parameters.AddWithValue("@first_name", model.firstName); sqlCommand.Parameters.AddWithValue("@last_name", model.lastName); sqlCommand.Parameters.AddWithValue("@Address", model.Address); sqlCommand.Parameters.AddWithValue("@City", model.City); sqlCommand.Parameters.AddWithValue("@State", model.State); sqlCommand.Parameters.AddWithValue("@Zip", model.zip); sqlCommand.Parameters.AddWithValue("@Phone_Number", model.PhoneNumber); sqlCommand.Parameters.AddWithValue("@Contact_typeID", model.ContactTypeId); sqlCommand.Parameters.AddWithValue("@AddedDate", DateTime.Now); this.connection.Open(); // Returns the number of rows effected var result = sqlCommand.ExecuteNonQuery(); this.connection.Close(); // If number of rows not equal to zero then retuns true // Else returns false if (result != 0) { return(true); } return(false); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { this.connection.Close(); } return(false); }
static void Main(string[] args) { AddressBookRepo addressBookRepo = new AddressBookRepo(); AddressBookModel addressBookModel = new AddressBookModel(); //addressBookRepo.GetAllContactTable("Contact"); addressBookRepo.GetAllDataOfContactBookName("Contact_BookName"); addressBookRepo.GetAllDataOfContactType("Contact_Type"); addressBookRepo.UpdateContactTable("PersonId =3"); addressBookRepo.RetriveContactInGivenDateRange(); addressBookRepo.RetriveContactInGivenCity(); addressBookRepo.RetriveContactInGivenState(); addressBookModel.firstName = "kalyan"; addressBookModel.lastName = "Goud"; addressBookModel.Address = "sriramnager"; addressBookModel.City = "Nlg"; addressBookModel.State = "TS"; addressBookModel.zip = "508001"; addressBookModel.PhoneNumber = "7732063720"; addressBookModel.ContactTypeId = 3; addressBookRepo.AddContact(addressBookModel); }