-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCooperationChoicesService.cs
More file actions
51 lines (44 loc) · 2.01 KB
/
CooperationChoicesService.cs
File metadata and controls
51 lines (44 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using api.Models.Common;
using api.Models.ProfileEditor;
using api.Models.Ttv;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace api.Services
{
public class CooperationChoicesService : ICooperationChoicesService
{
private readonly TtvContext _ttvContext;
private readonly ILogger<CooperationChoicesService> _logger;
public CooperationChoicesService(TtvContext ttvContext, ILogger<CooperationChoicesService> logger)
{
_ttvContext = ttvContext;
_logger = logger;
}
public async Task<List<ProfileEditorCooperationItem>> GetCooperationChoices(int userprofileId, bool forElasticsearch = false)
{
var stopwatch = Stopwatch.StartNew();
List<ProfileEditorCooperationItem> cooperationItems = await _ttvContext.DimUserChoices
.Where(c => c.DimUserProfileId == userprofileId && (!forElasticsearch || c.UserChoiceValue))
.Select(c => new ProfileEditorCooperationItem
{
Id = c.Id,
NameFi = c.DimReferencedataIdAsUserChoiceLabelNavigation.NameFi,
NameEn = c.DimReferencedataIdAsUserChoiceLabelNavigation.NameEn,
NameSv = c.DimReferencedataIdAsUserChoiceLabelNavigation.NameSv,
Selected = c.UserChoiceValue,
Order = c.DimReferencedataIdAsUserChoiceLabelNavigation.Order
}).AsNoTracking().ToListAsync();
stopwatch.Stop();
if (stopwatch.ElapsedMilliseconds > Constants.LoggingParameters.SLOW_OPERATION_MS_THRESHOLD)
{
_logger.LogWarning($"GetCooperationChoices is slow. userprofileId={userprofileId}, forElasticsearch={forElasticsearch} in {stopwatch.ElapsedMilliseconds}ms.");
}
return cooperationItems;
}
}
}