示例#1
0
        public async Task <IActionResult> UploadFile(int projectNumber, int activityListNumber, IFormFile file)
        {
            var fileSize = 60 * 1024 * 1024;

            if (file.Length > fileSize || projectNumber < 1 || activityListNumber < 1)
            {
                return(BadRequest());
            }

            Result refreshUserToken = await _mediatorFactory.Execute(new RefreshCurrentUserTokenCommand { ExternalProvider = ExternalProviders.OneDrive });

            if (!refreshUserToken.IsSuccess)
            {
                return(BadRequest());
            }

            HttpResponseMessage uploadFileResult = await Mediator.Send(new UploadFileCommand
            {
                ExternalProvider = ExternalProviders.OneDrive,
                Filepath         = $"drive/special/approot:/PM/Projects/P{projectNumber.ToString().PadLeft(8, '0')}/ActivityLists/AL{activityListNumber.ToString().PadLeft(8, '0')}",
                FormFile         = file
            });

            if (uploadFileResult.IsSuccessStatusCode)
            {
                return(Ok());
            }

            return(BadRequest());
        }
示例#2
0
        public async Task <ActionResult> Create(CreateApplicationUserCommand command)
        {
            Result createEmployeeCommand = await _mediatorFactory.Execute(command);

            if (createEmployeeCommand.IsSuccess)
            {
                return(RedirectToAction("Index"));
            }
            return(BadRequest(createEmployeeCommand.Error));
        }
示例#3
0
        /// <summary>
        /// Invoke ViewComponent
        /// </summary>
        /// <returns></returns>
        public async Task <IViewComponentResult> InvokeAsync(OneDriveTabDto dto)
        {
            Result refreshUserToken = await _mediatorFactory.Execute(new RefreshCurrentUserTokenCommand()
            {
                ExternalProvider = ExternalProviders.OneDrive
            });

            if (refreshUserToken.IsSuccess)
            {
                var model = new OneDriveListViewModel()
                {
                    Paths      = dto.Paths,
                    FolderName = dto.FolderName,
                    MetaData   = new List <CloudMetaData>()
                };
                try
                {
                    model.MetaData = await _mediatR.Send(new GetChildrenQuery()
                    {
                        ExternalProvider = dto.ExternalProvider, FilePath = dto.Paths[0]
                    });
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("Catch this" + e.Message);
                }

                return(View("OneDriveTab", model));
            }

            throw new InvalidOperationException("Catch this");
        }
示例#4
0
        public async Task <IActionResult> GetFiles(string projectName, Guid?projectId, string changeRequestName, Guid entityId,
                                                   int projectNumber, int changeRequestNumber)
        {
            if (!projectId.HasValue || projectId.Value == Guid.Empty)
            {
                return(BadRequest());
            }

            Result refreshUserToken = await _mediatorFactory.Execute(new RefreshCurrentUserTokenCommand()
            {
                ExternalProvider = ExternalProviders.OneDrive
            });

            var dto = new OneDriveTabDto()
            {
                ExternalProvider = ExternalProviders.OneDrive,
                Paths            = new List <string>
                {
                    "drive/special/approot:/PM/" + "Projects/" + projectName + projectId.Value + "/"
                    + "Requests/" + (changeRequestName?.ReplaceSpecialCharacters('_') ?? string.Empty) + entityId,
                    "drive/special/approot:/PM/" + "Projects/" + $"P{projectNumber.ToString().PadLeft(8, '0')}" + "/"
                    + "Requests/" + $"R{changeRequestNumber.ToString().PadLeft(8, '0')}"
                },
                FolderName = "   "
            };

            if (refreshUserToken.IsSuccess)
            {
                var model = new OneDriveListViewModel()
                {
                    Paths      = dto.Paths,
                    FolderName = dto.FolderName,
                    MetaData   = new List <CloudMetaData>()
                };

                try
                {
                    foreach (var path in model.Paths)
                    {
                        model.MetaData.AddRange(await Mediator.Send(new GetChildrenQuery()
                        {
                            ExternalProvider = dto.ExternalProvider, FilePath = path
                        }));
                    }
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("Catch this: " + e.Message);
                }

                ViewBag.Name = "Projects/" + projectName + projectId.Value + "/Requests/" +
                               (changeRequestName?.ReplaceSpecialCharacters('_') ?? string.Empty) + entityId;
                return(PartialView("_OneDriveFilesForChangeRequest", model));
            }

            throw new InvalidOperationException("Catch this: ");
        }
示例#5
0
        public async Task <IActionResult> GetFiles(string name, Guid?id)
        {
            if (!id.HasValue || id.Value == Guid.Empty)
            {
                return(BadRequest());
            }

            Result refreshUserToken = await _mediatorFactory.Execute(new RefreshCurrentUserTokenCommand()
            {
                ExternalProvider = ExternalProviders.OneDrive
            });

            var dto = new OneDriveTabDto()
            {
                ExternalProvider = ExternalProviders.OneDrive,
                Paths            = new List <string>
                {
                    "drive/special/approot:/PM/" + "Projects/" + name + id.Value
                },
                FolderName = "   "
            };

            if (refreshUserToken.IsSuccess)
            {
                var model = new OneDriveListViewModel()
                {
                    Paths      = dto.Paths,
                    FolderName = dto.FolderName,
                    MetaData   = new List <CloudMetaData>()
                };

                try
                {
                    foreach (var path in model.Paths)
                    {
                        model.MetaData.AddRange(await Mediator.Send(new GetChildrenQuery()
                        {
                            ExternalProvider = dto.ExternalProvider, FilePath = path
                        }));
                    }
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("Catch this: " + e.Message);
                }

                ViewBag.Name = "Projects/" + name;
                return(PartialView("_OneDriveTab", model));
            }

            throw new InvalidOperationException("Catch this: ");
        }