public static Log Add(Log log, Log parent = null) { if (log.ID > 0) { throw new Exception("log.ID should be zero"); } if (String.IsNullOrEmpty(log.Application)) { throw new Exception("log.Application should be defined"); } if (String.IsNullOrEmpty(log.Title)) { throw new Exception("log.Title should be defined"); } if (parent != null) { log.Parent = parent.ID; } using (MLogDataContext db = new MLogDataContext()) { db.tblLogs.InsertOnSubmit(log.Map()); db.SubmitChanges(); } using (MLogDataContext db = new MLogDataContext()) { log.ID = (from pp in db.tblLogs where pp.Title == log.Title orderby pp.ID descending select pp.ID).ToList().FirstOrDefault(); } return(log); }
public static List <Log> GetLogs(Log log) { using (MLogDataContext db = new MLogDataContext()) { if (log == null) { return(db.tblLogs.Take(500).ToList().Select((tlog) => Log.Map(tlog)).ToList()); } else { bool applicationValid = !String.IsNullOrEmpty(log.Application); bool idValid = log.ID > 0; bool parentValid = log.Parent > 0; bool titleValid = !String.IsNullOrEmpty(log.Title); return((from pp in db.tblLogs where (idValid && pp.ID.Equals(log.ID)) || (applicationValid && pp.Application.Equals(log.Application)) || (parentValid && pp.Parent.Equals(log.Parent)) || (titleValid) && pp.Title.ToLower().Equals(log.Title) select pp).ToList().Select((tlog) => Log.Map(tlog)).ToList()); } } }