Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 5a08541d

Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)

DocumentService now uses AutoMapper

Zobrazit rozdíly:

Backend/Core/Services/DocumentService/DocumentServiceEF.cs
9 9
using System.Text;
10 10
using System.Threading.Tasks;
11 11
using System.Web;
12
using AutoMapper;
13
using Models.Users;
12 14

  
13 15
namespace Core.Services.DocumentService
14 16
{
......
16 18
    {
17 19
        private readonly DatabaseContext databaseContext;
18 20
        private readonly ILogger logger;
21
        private readonly IMapper mapper;
19 22

  
20
        public DocumentServiceEF(DatabaseContext databaseContext, ILogger logger)
23
        public DocumentServiceEF(DatabaseContext databaseContext, ILogger logger, IMapper mapper)
21 24
        {
22 25
            this.databaseContext = databaseContext;
23 26
            this.logger = logger;
27
            this.mapper = mapper;
24 28
        }
25 29

  
26 30
        /// <summary>
......
118 122
            List<DocumentListInfo> documentInfos = new List<DocumentListInfo>();
119 123
            foreach (var document in documents.GetRange(firstIndex, request.PageSize))
120 124
            {
121
                documentInfos.Add(new DocumentListInfo()
122
                {
123
                    Id = document.Id,
124
                    Length = document.Length,
125
                    Name = document.Name,
126
                    RequiredAnnotations = document.RequiredAnnotations
127
                });
125
                var annotatingUsers = databaseContext.Annotations.Where(a => a.Document == document).Select(a => a.User).ToList();
126
                List<UserInfo> annotatingUsersDto = annotatingUsers.Select(a => mapper.Map<UserInfo>(a)).ToList();
127

  
128
                DocumentListInfo dai = mapper.Map<DocumentListInfo>(document);
129
                dai.AnnotatingUsers = annotatingUsersDto;
130
                documentInfos.Add(dai);             
128 131
            }
129 132

  
130 133
            return new DocumentListResponse()

Také k dispozici: Unified diff