public async Task <IEnumerable <ScientificWorkDto> > GetApprovedWorksAsync() { var listOfScientificWorks = await _scientificWorkRepository.GetApprovedWorksAsync(); var listOfScientificWorksDto = new List <ScientificWorkDto>(); foreach (var scientificWork in listOfScientificWorks) { var authors = $"{scientificWork.MainAuthor.Name} {scientificWork.MainAuthor.Surname}"; // Sometimes the work doesn't include other authors except main one if (!(scientificWork.OtherAuthors is null)) { authors += $", {scientificWork.OtherAuthors}"; } var scientificWorkDto = new ScientificWorkDto() { Id = scientificWork.Id, Authors = authors, Title = scientificWork.Name, Description = scientificWork.Description, CreationDate = scientificWork.CreationDate.ToString("g"), // Get date of latest update of work UpdateDate = scientificWork.Versions.OrderBy(x => x.Version).Last().DateAdd.ToString("g"), Specialization = scientificWork.Specialization }; listOfScientificWorksDto.Add(scientificWorkDto); } return(listOfScientificWorksDto); }
public async Task <ScientificWorkWithReviewDto> GetWorkByIdAsync(uint userId, uint scientificWorkId) { var scientificWork = await _scientificWorkRepository.GetWorkByIdAsync(scientificWorkId); if (scientificWork is null) { return(null); } var mode = ""; if (scientificWork.MainAuthor.Id == userId) { mode = "Author"; } else if (await _reviewRepository.IsReviewerAsync(scientificWorkId, userId)) { mode = "Reviewer"; } else { mode = "Participant"; } // participant can see this work only when it's approved if (scientificWork.Status != StatusEnum.Accepted && mode == "Participant") { throw new AuthenticationException(); } var scientificWorkDto = new ScientificWorkDto() { Id = scientificWork.Id, Title = scientificWork.Name, Description = scientificWork.Description, Specialization = scientificWork.Specialization, CreationDate = scientificWork.CreationDate.ToString("g"), UpdateDate = scientificWork.Versions.OrderBy(x => x.Version).Last().DateAdd.ToString("g"), Authors = scientificWork.OtherAuthors, }; string base64Photo = null; if (scientificWork.MainAuthor.Photo != null) { var authorPhoto = await _fileManager.GetBase64FileAsync(scientificWork.MainAuthor.Photo); var photoExtension = scientificWork.MainAuthor.Photo.Split(".")[^ 1];
public void MapScientificWorkToScientificWorkDto() { var expected = new ScientificWorkDto() { Id = _scientificWork.Id, Title = _scientificWork.Name, Authors = ScientificWorkHelper.GetAuthors(_scientificWork.MainAuthor, _scientificWork.OtherAuthors), CreationDate = _dateTimeFormatter.Convert(_scientificWork.CreationDate, null), Description = _scientificWork.Description, Specialization = _scientificWork.Specialization, UpdateDate = _dateTimeFormatter.Convert(_scientificWork.Versions.Last().DateAdd, null) }; var returned = _mapper.Map <ScientificWorkDto>(_scientificWork); returned.Should().BeEquivalentTo(expected); }