// Copyright (c) 2015-2017 schick Informatik // Description: using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; namespace bsmd.database { public class MessageHistory : IDatabaseEntity { private const string tableName = "[MessageHistory]"; #region Properties public string Tablename { get { return tableName; } } public Guid? Id { get; set; } public Guid? ReportingPartyId { get; set; } public ReportingParty CreatedBy { get; set; } public Guid EntityId { get; internal set; } public string EntityType { get; internal set; } public string EntityName { get; internal set; } public string EntityValues { get; internal set; } public DateTime Created { get; private set; } #endregion #region IDatabaseEntity implementation public void PrepareSave(IDbCommand cmd) { SqlCommand scmd = cmd as SqlCommand; // es gibt nur insert this.Id = Guid.NewGuid(); scmd.Parameters.AddWithValue("@ID", this.Id); scmd.Parameters.AddWithNullableValue("@P1", this.ReportingPartyId); scmd.Parameters.AddWithValue("@P2", this.EntityId); scmd.Parameters.AddWithValue("@P3", this.EntityType); scmd.Parameters.AddWithValue("@P4", this.EntityName); scmd.Parameters.AddWithValue("@P5", this.EntityValues); scmd.Parameters.AddWithValue("@P6", DateTime.Now); cmd.CommandText = string.Format("INSERT INTO {0} (Id, ReportingPartyId, EntityId, EntityType, " + "EntityName, EntityValues, Timestamp) VALUES (@ID, @P1, @P2, @P3, @P4, @P5, @P6)", this.Tablename); } public void PrepareDelete(IDbCommand cmd) { SqlCommand scmd = cmd as SqlCommand; scmd.CommandText = string.Format("DELETE FROM {0} WHERE Id = @ID", Tablename); scmd.Parameters.AddWithValue("@ID", this.Id); } public List LoadList(IDataReader reader) { List result = new List(); while (reader.Read()) { MessageHistory mh = new MessageHistory(); mh.Id = reader.GetGuid(0); if (!reader.IsDBNull(1)) mh.ReportingPartyId = reader.GetGuid(1); if (!reader.IsDBNull(2)) mh.EntityId = reader.GetGuid(2); if (!reader.IsDBNull(3)) mh.EntityType = reader.GetString(3); if (!reader.IsDBNull(4)) mh.EntityName = reader.GetString(4); if (!reader.IsDBNull(5)) mh.EntityValues = reader.GetString(5); if (!reader.IsDBNull(6)) mh.Created = reader.GetDateTime(6); result.Add(mh); } reader.Close(); return result; } List IDatabaseEntity.LoadList(IDataReader reader) { throw new NotImplementedException(); } #endregion } }