Ejemplo n.º 1
0
        public async Task <IActionResult> ImportGhostOrganizationFixes()
        {
            try
            {
                var file       = Request.Form.Files[0];
                var folderName = Path.Combine("wwwroot", "DataImportFiles");
                var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName);
                Directory.CreateDirectory(pathToSave);
                if (file.Length > 0)
                {
                    var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    var filePath = Path.Combine(pathToSave, fileName);
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }
                    var ghostOrganizations = service.FixGhostOrganizationMembershipFix(filePath, file);
                    if (ghostOrganizations.Count > 0)
                    {
                        var response = await projectMembershipService.FixGhostOrganizationsAsync(ghostOrganizations.ToList());

                        if (!response.Success)
                        {
                            return(BadRequest(response.Message));
                        }
                    }
                    return(Ok(ghostOrganizations));
                }
                else
                {
                    return(BadRequest("Invalid data file provided"));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }