public void Add(HistoryItem historyItem)
 {
     if (historyItem.Id == null)
     {
         historyItem.Id = Guid.NewGuid().ToString("B");
     }
     historyItem.CreationDate = DateTime.UtcNow;
     using (var dbContext = new MedialynxDbHistoryContext()) {
         dbContext.HistoryItems.Add(historyItem);
         dbContext.SaveChanges();
     }
 }
        public List <HistoryItem> GetByUser(string userId)
        {
            Guid id = Utils.ToGuid(userId);

            using (var dbContext = new MedialynxDbHistoryContext()) {
                if (id != Guid.Empty)
                {
                    string sid = id.ToString("B");
                    return(dbContext.HistoryItems.Where(item => item != null && item.UserId == sid).ToList());
                }
            }
            return(null);
        }
        public List <HistoryItem> Get(string historyId = "{00000000-0000-0000-0000-000000000000}")
        {
            Guid id = Utils.ToGuid(historyId);
            List <HistoryItem> historyItems = new List <HistoryItem>();

            using (var dbContext = new MedialynxDbHistoryContext()) {
                if (id != Guid.Empty)
                {
                    string sid = id.ToString("B");
                    historyItems.Add(dbContext.HistoryItems.FirstOrDefault(item => item != null && item.Id == sid));
                }
                else
                {
                    // Add all history
                    historyItems.AddRange(dbContext.HistoryItems);
                }
            }
            return(historyItems);
        }