public async Task <SharedActivities> RetrieveAsync(string shareKey, int activityTypeFilter) { var share = await shareRepository.GetByShareKeyAsync(shareKey); if (share == null || share.ValidFromTime > DateTime.Now || share.ValidUntilTime < DateTime.Now || !share.AllowActivities) { return(null); } var activitiesPerDay = (await activityRepository.GetByUserIdAsync(share.SharingUserId)) .Where(a => activityTypeFilter == -1 || (int)a.ActivityType == activityTypeFilter) .OrderByDescending(a => a.ActivityTime) .GroupBy(a => a.ActivityTime.Date); var documents = await documentRepository.GetByUserIdAsync(share.SharingUserId); return(new SharedActivities { User = await userRepository.GetByIdAsync(share.SharingUserId), ActivityFilter = activityTypeFilter, Days = activitiesPerDay.Select(dayGroup => new SharedActivities.SharedActivitiesPerDay { Date = dayGroup.Key, Activities = dayGroup.Select(a => new SharedActivities.SharedActivitiesPerDay.SharedActivity { Activity = a, Properties = new Dictionary <string, string>(), Documents = documents .Where(d => d.ActivityId == a.Id) .OrderByDescending(d => d.DocumentTime) }) }) }); }
public async Task<AllSharedData> RetrieveAsync(string shareKey) { var share = await shareRepository.GetByShareKeyAsync(shareKey); if (share == null || share.ValidFromTime > DateTime.Now || share.ValidUntilTime < DateTime.Now) { return null; } return new AllSharedData { Share = share, User = await userRepository.GetByIdAsync(share.SharingUserId), Activities = share.AllowActivities ? await activityRepository.GetByUserIdAsync(share.SharingUserId) : Enumerable.Empty<Activity>(), Documents = share.AllowDocuments ? await documentRepository.GetByUserIdAsync(share.SharingUserId) : Enumerable.Empty<Document>(), Diseases = share.AllowDiseases ? await diseaseRepository.GetByUserIdAsync(share.SharingUserId) : Enumerable.Empty<Disease>(), AcuteDiseases = share.AllowAcuteDiseases ? await acuteDiseaseRepository.GetByUserIdAsync(share.SharingUserId) : Enumerable.Empty<AcuteDisease>(), }; }
public async Task <ActionResult> DownloadDocumentById(string shareKey, Guid documentId) { var share = await shareRepository.GetByShareKeyAsync(shareKey); if (share == null) { return(BadRequest($"Share with share key {shareKey} not found!")); } var result = await documentsInteractor.GetDocumentByIdAsync(share.SharingUserId, documentId); if (result == null) { return(NotFound(documentId)); } return(File(result.Content, result.MimeType, result.FileName)); }
public async Task <SharedDocuments> GetDocuments(string sharedKey, int documentTypeFilter) { var share = await shareRepository.GetByShareKeyAsync(sharedKey); var documents = (await documentRepository.GetByUserIdAsync(share.SharingUserId)) .Where(d => documentTypeFilter == -1 || (int)d.DocumentType == documentTypeFilter) .OrderByDescending(d => d.DocumentTime) .Select(d => new DocumentEntry { Document = d, IsImage = d.Mimetype.StartsWith("image/") }); return(new SharedDocuments { ShareKey = sharedKey, DocumentTypeFilter = documentTypeFilter, User = await userRepository.GetByIdAsync(share.SharingUserId), Documents = documents, }); }
public async Task InsertActivityAsync( string shareKey, string title, string description, DateTime activityTime, ActivityType activityType) { var share = await shareRepository.GetByShareKeyAsync(shareKey); if (share == null) { throw new InvalidOperationException($"No share with share key {shareKey} found!"); } await activityInteractor.InsertAsync( share.SharingUserId, new Activity { Title = title, Description = description, ActivityTime = activityTime, ActivityType = activityType, }); }