public void Increment(Version version) { if (version.IsLocked) throw new InvalidOperationException("Version object is already locked!"); var connection = Context.Data.Open(); try { using (var command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = string.Format(UPDATE_SQL, (version.Value + 1), version.ModifiedBy, version.Modified.ToString(), version.Id, version.Value); command.Transaction = Context.Data.Transaction; int rowCount = command.ExecuteNonQuery(); if (rowCount == 0) throw new ConcurrencyException("Concurrency exception"); } } catch (DbException dbe) { throw new Exception("Unexpected sql error incrementing version: " + dbe.Message); } finally { Context.Data.Close(); } }
public void Delete(Version version) { if (!version.IsNew || version.IsLocked) throw new InvalidOperationException("Invalid Version object to delete!"); var connection = Context.Data.Open(); try { using (var command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = string.Format(DELETE_SQL, version.Id.ToString(), version.Value); command.Transaction = Context.Data.Transaction; int rowCount = command.ExecuteNonQuery(); if (rowCount == 0) throw new ConcurrencyException("Concurrency exception"); } } catch (DbException dbe) { throw new Exception("Unexpected sql error incrementing version: " + dbe.Message); } finally { Context.Data.Close(); } }
internal static Address Create(Customer customer, Version version, string line1, string line2, string phone) { var createdBy = CurrentContext.Session.OwnerName; var address = new Address(Guid.NewGuid(), customer, line1, line2, phone); address.SetSystemFields(version, DateTime.UtcNow, createdBy); address.isNew = true; return address; }
public void Insert(Version version) { if (!version.IsNew) throw new InvalidOperationException("Version object is not new!"); var connection = Context.Data.Open(); try { using (var command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = string.Format(INSERT_SQL, version.Id.ToString(), version.Value, version.ModifiedBy, version.Modified.ToString()); command.Transaction = Context.Data.Transaction; command.ExecuteNonQuery(); Context.IdentityMap.Add(version.Id, version); } } catch (DbException dbe) { throw new Exception("Unexpected sql error inserting version: " + dbe.Message); } finally { Context.Data.Close(); } }