public bool Remove(int ID) { try { using (var con = GetConnection) { T entity = con.Get <T>(ID); Entity.AuditTracing at = new Entity.AuditTracing(); Type type = typeof(T); at.Object = type.Name; at.AuditType = Entity.AuditType.Remove; at.UserID = Convert.ToInt32(entity.GetType().GetProperty("UserIDModified").GetValue(entity)); at.Date = DateTime.Now; at.Object = entity.GetType().ToString(); at.ReferanceID = Convert.ToInt32(entity.GetType().GetProperty("ID").GetValue(entity)); at.OldValue = Helper.Object.Serialize(entity); at.NewValue = null; int AuditID = AuditRepository.CreateAuditTracing(at); return(con.Delete(entity)); } } catch (Exception ex) { LogRepository.CreateLog(ex); return(false); } }
public bool Update(T entityOld, T entityNews) { try { using (var con = GetConnection) { Entity.AuditTracing at = new Entity.AuditTracing(); Type type = typeof(T); at.Object = type.Name; at.AuditType = Entity.AuditType.Update; at.UserID = Convert.ToInt32(entityNews.GetType().GetProperty("UserIDModified").GetValue(entityNews)); at.Date = DateTime.Now; at.Object = entityNews.GetType().ToString(); at.ReferanceID = Convert.ToInt32(entityNews.GetType().GetProperty("ID").GetValue(entityNews)); at.OldValue = Helper.Object.Serialize(entityOld); at.NewValue = Helper.Object.Serialize(entityNews); int AuditID = AuditRepository.CreateAuditTracing(at); entityNews.GetType().GetProperty("AuditID").SetValue(entityNews, AuditID); return(con.Update(entityNews)); } } catch (Exception ex) { LogRepository.CreateLog(ex); return(false); } }
public bool DeleteAll() { try { using (var con = GetConnection) { IEnumerable <T> entities = con.GetAll <T>(); foreach (T entity in entities) { T entityOld = Helper.Object.Clone <T>(entity); Entity.AuditTracing at = new Entity.AuditTracing(); Type type = typeof(T); at.Object = type.Name; at.AuditType = Entity.AuditType.Delete; at.UserID = Convert.ToInt32(entity.GetType().GetProperty("UserIDModified").GetValue(entity)); at.Date = DateTime.Now; at.Object = entity.GetType().ToString(); at.ReferanceID = Convert.ToInt32(entity.GetType().GetProperty("ID").GetValue(entity)); at.OldValue = Helper.Object.Serialize(entityOld); at.NewValue = Helper.Object.Serialize(entity); int AuditID = AuditRepository.CreateAuditTracing(at); entity.GetType().GetProperty("AuditID").SetValue(entity, AuditID); entity.GetType().GetProperty("IsActive").SetValue(entity, false); } return(con.Update(entities)); } } catch (Exception ex) { LogRepository.CreateLog(ex); return(false); } }