void MessageRead(ulong id)
        {
            if (username == null)
                return;

            MessageEntity entity = new MessageEntity(username, id);
            dataSource.Insert(entity);
        }
        public void Delete(MessageEntity itemToDelete)
        {
            try
            {
                serviceContext.AttachTo(MessageDataServiceContext.MessagesTableName, itemToDelete, "*");
            }
            catch (InvalidOperationException)
            {
                // May already be tracking the entity from previous operations
            }

            serviceContext.DeleteObject(itemToDelete);
            serviceContext.SaveChanges();
        }
        public void TestMethod1()
        {
            MessageDataSource dataSource = new MessageDataSource();

            string username = "******";
            ulong messageId = (ulong)DateTime.Now.Ticks;
            MessageEntity entity = new MessageEntity(username, messageId);

            Assert.IsFalse(dataSource.WasReadElsewhere(entity));

            dataSource.Insert(entity);

            Assert.IsTrue(dataSource.WasReadElsewhere(entity));

            dataSource.Delete(entity);

            Assert.IsFalse(dataSource.WasReadElsewhere(entity));
        }
 public void Insert(MessageEntity newItem)
 {
     serviceContext.AddObject(MessageDataServiceContext.MessagesTableName, newItem);
     serviceContext.SaveChanges();
 }
        public bool WasReadElsewhere(MessageEntity item)
        {
            var query = (from c in serviceContext.Messages
                        where c.PartitionKey == item.PartitionKey && c.RowKey == item.RowKey
                         select c).AsTableServiceQuery();

            return query.ToList().Count() > 0;
        }