public Account Get() { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); TableServiceContext serviceContext = tableClient.GetDataServiceContext(); serviceContext.ResolveType = (unused) => typeof(Account); var existingAccount = serviceContext.CreateQuery<Account>("account").SingleOrDefault(); if (existingAccount == null) { existingAccount = new Account("1"); serviceContext.AddObject("account", existingAccount); serviceContext.SaveChanges(); } return existingAccount; }
public void Set(Guid authorizationCode) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); TableServiceContext serviceContext = tableClient.GetDataServiceContext(); serviceContext.ResolveType = (unused) => typeof(Account); var existingAccount = serviceContext.CreateQuery<Account>("account").SingleOrDefault(); if (existingAccount == null) { existingAccount = new Account("1"); serviceContext.AddObject("account", existingAccount); } existingAccount.AuthorizationCode = authorizationCode; existingAccount.Generated = DateTime.UtcNow; serviceContext.UpdateObject(existingAccount); serviceContext.SaveChanges(); }