public void SaveAccount(UserAccount account) { var data = account.ToData(); var allData = GetData <AccountData>(); var newDataList = allData.Where(d => d.Id != data.Id).Concat(new[] { data }).ToArray(); CachedDataAccess.Save(WebCache, newDataList); }
public void SaveNote(Note note) { var data = note.ToData(); var allNotes = GetData <NoteData>(); var newAllNotes = allNotes.Where(n => n.Id != data.Id).Concat(new[] { data }); CachedDataAccess.Save(WebCache, newAllNotes.ToArray()); }
//updates or creates the new item public void Save(T item) { Delete(item.Id); var allData = RetreiveAll(); var newData = allData.Concat(new T[] { item }); var cache = HttpContext.Current.Cache; CachedDataAccess.Save(cache, newData); }
//removes entry from file table public void Delete(Guid id) { var allData = RetreiveAll(); var newData = allData.Where(d => d.Id != id).ToArray(); if (newData.Length != allData.Length) { var cache = HttpContext.Current.Cache; CachedDataAccess.Save(cache, newData); } }
private T[] GetData <T>() where T : class { var allData = CachedDataAccess.Get <T[]>(WebCache); if (allData == null) { allData = new T[] { }; CachedDataAccess.Save(WebCache, allData); } return(allData); }
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); GlobalFilters.Filters.Add(new MvcCookieAuthorizeAttribute()); var config = new SiteConfiguration(); CachedDataAccess.Initialize(config.TypecacheStorageDirectory); }
//gets all data of type, creates file table if missing public T[] RetreiveAll() { var cache = HttpContext.Current.Cache; var allData = CachedDataAccess.Get <T[]>(cache); if (allData == null) { allData = new T[] { }; CachedDataAccess.Save(cache, allData); } return(allData); }
public UserAccount CreateNewUser(string email, string password) { var salt = Guid.NewGuid().ToString(); var accountData = new AccountData() { Email = email, PasswordHash = AuthorizationHelper.HashPassword(password, salt), PasswordSalt = salt, AuthToken = null, DisplayUsername = string.Empty, Id = Guid.NewGuid(), NoteIds = new Guid[] { } }; var allAccounts = GetData <AccountData>().Concat(new[] { accountData }).ToArray(); CachedDataAccess.Save(WebCache, allAccounts); return(GetAccountById(accountData.Id)); }