public IActionResult ExportContributors(Guid projectId, ExportContributorsType type) { OperationResultVo result = translationAppService.GetContributorsFile(CurrentUserId, projectId, type); if (result.Success) { OperationResultVo <List <KeyValuePair <Guid, string> > > castRestult = result as OperationResultVo <List <KeyValuePair <Guid, string> > >; List <KeyValuePair <Guid, string> > model = castRestult.Value; StringBuilder sb = new StringBuilder(); sb.AppendLine("UserId;User Name;Profile URL"); foreach (KeyValuePair <Guid, string> item in model) { string url = Url.Action("details", "profile", new { area = string.Empty, id = item.Key }, "https", Request.Host.Value); string newLine = String.Format("{0};{1};{2}", item.Key, item.Value, url); sb.AppendLine(newLine); } InMemoryFileVo file = new InMemoryFileVo { FileName = String.Format("contributors_{0}.csv", type.ToString().ToLower()), Contents = Encoding.UTF8.GetBytes(sb.ToString()) }; return(File(file.Contents, "text/csv", file.FileName)); } else { return(null); } }
public OperationResultVo GetContributorsFile(Guid currentUserId, Guid projectId, ExportContributorsType type) { try { Task <List <Guid> > task = translationDomainService.GetContributors(projectId, type); task.Wait(); List <Guid> contributorsIds = task.Result; List <KeyValuePair <Guid, string> > dict = new List <KeyValuePair <Guid, string> >(); foreach (Guid contributorId in contributorsIds) { UserProfile profile = GetCachedProfileByUserId(contributorId); dict.Add(new KeyValuePair <Guid, string>(contributorId, profile.Name)); } return(new OperationResultVo <List <KeyValuePair <Guid, string> > >(dict)); } catch (Exception ex) { return(new OperationResultVo(ex.Message)); } }
public async Task <List <Guid> > GetContributors(Guid projectId, ExportContributorsType type) { List <Guid> contributorsIds = repository.GetEntries(projectId).Select(x => x.UserId).Distinct().ToList(); return(contributorsIds); }