Esempio n. 1
0
 public InsurancePolicy Create(InsurancePolicy item)
 {
     try
     {
         using (SqlConnection con = new SqlConnection(_connectionString))
         {
             con.Open();
             return(con.QuerySingleOrDefault <InsurancePolicy>($@"INSERT INTO [InsurancePolicy] ([PersonId], [Number], [Company])
                     VALUES (@{nameof(InsurancePolicy.PersonId)}, @{nameof(InsurancePolicy.Number)}, @{nameof(InsurancePolicy.Company)})", item));
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Esempio n. 2
0
        public bool Update(InsurancePolicy item)
        {
            try
            {
                using (SqlConnection con = new SqlConnection(_connectionString))
                {
                    con.Open();
                    int rowsAffected = con.Execute($@"UPDATE [InsurancePolicy]
                        SET [Number] = @{nameof(InsurancePolicy.Number)}, [Company] = @{nameof(InsurancePolicy.Company)}
                        WHERE [PersonId] = @{nameof(InsurancePolicy.PersonId)}", item);

                    return(rowsAffected > 0);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }