/// <summary> /// Deletes the item. /// </summary> /// <param name="accessCode">The access code.</param> /// <param name="path">The path.</param> /// <param name="name">The name.</param> /// <returns></returns> public async Task DeleteItem(string accessCode, string path, string name) { var dashboard = await this.FindByAccessCode(accessCode); var decryptor = new DashboardDecryptor(dashboard); var decryptedItems = dashboard.DashboardItems.Select(item => decryptor.Decrypt(item)).ToList(); foreach (var item in decryptedItems) { if (item.Name.Trim('/') != name.Trim('/') || item.Path.Trim('/') != path.Trim('/')) { continue; } dashboard.DashboardItems.Remove(dashboard.DashboardItems.First(d => d.Id == item.Id)); if (!item.IsFolder) break; var subItems = decryptedItems.Where(i => i.Path.Trim('/').Replace('/', '\\').StartsWith(System.IO.Path.Combine(path, name))).ToList(); subItems.ForEach(i => dashboard.DashboardItems.Remove(dashboard.DashboardItems.First(it => it.Id == i.Id))); } await this.Update(dashboard); }
/// <summary> /// Gets the item. /// </summary> /// <param name="accessCode">The access code.</param> /// <param name="path">The path.</param> /// <param name="name">The name.</param> /// <returns></returns> public async Task<DashboardItem> GetItem(string accessCode, string path, string name) { var dashboard = await this.FindByAccessCode(accessCode); var decryptor = new DashboardDecryptor(dashboard); return dashboard.DashboardItems.Select(i => decryptor.Decrypt(i, true)).First(i => i.Path.Trim('/') == path.Trim('/') && i.Name.Trim('/') == name.Trim('/')); }
/// <summary> /// Gets the items by path. /// </summary> /// <param name="accessCode">The access code.</param> /// <param name="path">The path.</param> /// <returns></returns> public async Task<List<DashboardItem>> GetItemsByPath(string accessCode, string path) { var dashboard = await this.FindByAccessCode(accessCode); var decryptor = new DashboardDecryptor(dashboard); return dashboard.DashboardItems.Select(i => decryptor.Decrypt(i)).Where(i => i.Path.Trim('/') == path.Trim('/')).ToList(); }