コード例 #1
0
 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();
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }