public long Insert(GiftListGroupEntity giftListGroup, IConnection conn) { CheckGiftListGroupForRequiredValues(giftListGroup, RepositoryUtils.RepositoryAction.Insert); using (Connection _conn = new Connection()) { var giftListGroupExists = GetGiftListGroup(giftListGroup.giftListFK, giftListGroup.groupFK); if (giftListGroupExists != null) { throw new Exception($"Gift List Group {giftListGroup.giftListFK} {giftListGroup.groupFK} already exists in database!"); } string sql = @"INSERT INTO[dbo].[giftListGroup] (giftListFK, groupFK, updateTimestamp, updatePersonFK) VALUES(@giftListFK, @groupFK, getdate(), @updatePersonFK );SELECT CAST(scope_identity() AS int)"; List<SqlParameter> prms = new List<SqlParameter>(); var param1 = new SqlParameter { ParameterName = "@giftListFK", Value = giftListGroup.giftListFK }; prms.Add(param1); var param2 = new SqlParameter { ParameterName = "@groupFK", Value = giftListGroup.groupFK }; prms.Add(param2); var param3 = new SqlParameter { ParameterName = "@updatePersonFK", Value = giftListGroup.updatePersonFK }; prms.Add(param3); try { return int.Parse(_conn.ExecuteScalar(sql,prms).ToString()); } catch (Exception) { throw new Exception($"Entity {giftListGroup.giftListFK} {giftListGroup.groupFK} not inserted in database!"); } } }