public bool UpdateTestimonial(Models.Testimonial.Testimonial testimonial) { bool isUpdate = true; using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.UPDATETESTIMONIAL, connection); command.CommandType = CommandType.StoredProcedure; foreach (var testimonials in testimonial.GetType().GetProperties()) { string name = testimonials.Name; var value = testimonials.GetValue(testimonial, null); command.Parameters.Add(new SqlParameter("@" + name, value == null ? DBNull.Value : value)); } try { connection.Open(); command.ExecuteNonQuery(); } catch (Exception e) { isUpdate = false; throw new Exception("Exception Updating Data." + e.Message); } finally { connection.Close(); } } return(isUpdate); }
public long InsertTestimonial(Models.Testimonial.Testimonial testimonial) { long id = 0; using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.INSERTTESTIMONIAL, connection); command.CommandType = CommandType.StoredProcedure; SqlParameter returnValue = new SqlParameter("@" + "TestimonialId", SqlDbType.Int); returnValue.Direction = ParameterDirection.Output; command.Parameters.Add(returnValue); foreach (var testimonials in testimonial.GetType().GetProperties()) { if (testimonials.Name != "TestimonialId") { string name = testimonials.Name; var value = testimonials.GetValue(testimonial, null); command.Parameters.Add(new SqlParameter("@" + name, value == null ? DBNull.Value : value)); } } try { connection.Open(); command.ExecuteNonQuery(); id = (int)command.Parameters["@TestimonialId"].Value; } catch (Exception ex) { throw new Exception("Execption Adding Data. " + ex.Message); } finally { connection.Close(); } } return(id); }