Пример #1
0
        public async Task <ActionResult> NewReport(string reportName, string folderName, HttpPostedFileBase reportFile)
        {
            var bytes = new BinaryReader(reportFile.InputStream).ReadBytes(reportFile.ContentLength);
            await PowerBiOnPremClient.AddNewReport(reportName, reportFile.FileName, folderName, bytes);

            return(RedirectToAction("Index"));
        }
Пример #2
0
        public async Task <ActionResult> NewFolder(User user, string userfolderName)
        {
            var publicFolderId   = Guid.Parse(ConfigurationManager.AppSettings["PowerBI_Public_FolderId"]);
            var publicFolderName = ConfigurationManager.AppSettings["PowerBI_Public_FolderName"];
            var createdFolder    = await PowerBiOnPremClient.CreateFolder(userfolderName);

            user.FolderAccesses = new List <FolderAccess>
            {
                new FolderAccess
                {
                    FolderId   = publicFolderId,
                    FolderName = publicFolderName,
                    CanEdit    = user.IsAdmin? true: false
                },
                new FolderAccess
                {
                    FolderId   = createdFolder.Id,
                    FolderName = userfolderName,
                    CanEdit    = true
                },
            };
            context.Users.Add(user);
            context.SaveChanges();


            return(View());
        }
Пример #3
0
        public async Task <FileResult> Download(Guid id)
        {
            var report = (Session["MyReports"] as Dictionary <Guid, CatalogItemViewModel>)[id];
            var bytes  = await PowerBiOnPremClient.DownloadReport(id);

            return(File(bytes, System.Net.Mime.MediaTypeNames.Application.Octet, report.FileName));
        }
Пример #4
0
        public async Task <ActionResult> Move(Guid id, Guid moveToFolderId)
        {
            //TODO:check if it is
            var report   = (Session["MyReports"] as Dictionary <Guid, CatalogItemViewModel>)[id];
            var folder   = (Session["Folders"] as Dictionary <Guid, string>)[moveToFolderId];
            var hasMoved = await PowerBiOnPremClient.MoveReportToFolder($"/{folder}", report.Path);

            return(RedirectToAction("Index"));
        }
Пример #5
0
        public async Task <ActionResult> Clone(Guid id, Guid cloneToFolderId, string newReportName)
        {
            //TODO:check if it is
            var report = (Session["MyReports"] as Dictionary <Guid, CatalogItemViewModel>)[id];
            var folder = (Session["Folders"] as Dictionary <Guid, string>)[cloneToFolderId];
            var item   = await PowerBiOnPremClient.CopyReportToFolder(newReportName, $"{newReportName}.pbix", folder, id);


            return(RedirectToAction("Index"));
        }
Пример #6
0
        public async Task <ActionResult> Index()
        {
            var userInfo = (User as CustomPrincipal);
            var accesses = context.FolderAccesses.Where(a => a.UserId == userInfo.UserId).ToList();

            var tasks = accesses.Select(a => PowerBiOnPremClient.GetReportsInFolder(a.FolderId)).ToArray();

            await Task.WhenAll(tasks);

            var items = tasks.SelectMany(c => c.Result)
                        // .Where(c => !c.Hidden)
                        .Select(item =>
            {
                var vm = new CatalogItemViewModel
                {
                    Visible       = !item.Hidden,
                    CreatedDate   = item.CreatedDate,
                    Id            = item.Id,
                    IsSystemAdmin = userInfo.IsAdmin,
                    Name          = item.Name,
                    Path          = item.Path
                };
                vm.IsPersonalItem = accesses.Any(c => c.FolderName == vm.FolderName && c.CanEdit == true);
                return(vm);
            }).ToList();

            Session.Add("MyReports", items.ToDictionary(c => c.Id));
            var folders = accesses.ToDictionary(c => c.FolderId, c => c.FolderName);

            ViewBag.Folders = folders;
            Session.Add("Folders", folders);
            var ItemsDict = accesses.ToDictionary(a => a.FolderName,
                                                  a => items.Where(c => string.Equals(c.FolderName, a.FolderName, StringComparison.InvariantCultureIgnoreCase)).ToList());

            return(View(ItemsDict));
        }
Пример #7
0
        public async Task <ActionResult> Delete(Guid id)
        {
            await PowerBiOnPremClient.DeleteReport(id);

            return(RedirectToAction("Index"));
        }