Prompt Title: improve method

Created 1 year ago
Votes 0
Views 99 times
0

Prompt Detail:

how can i make this method more efficient public async Task<TaskPatternDto[]> Handle(GetTaskPatternQuery query, CancellationToken cancellationToken) { var filteredPatterns = new List<List<TaskPatternDto>>(); query.MachineIds = query.MachineIds.Distinct().ToArray(); _validator.ValidateAndThrow(query); try { var entities = _context.Pattern .WhereIf(query.PatternId.HasValue, x => x.PatternId == query.PatternId) .WhereIf(query.IstStatic.HasValue, x => x.isStatic == query.IstStatic); var dto = (await Task.FromResult(_mapper.Map<TaskPatternDto[]>(entities))).ToList(); query.MachineIds.ToList().ForEach( x => { var filtered = dto.Where(p => p.MachineId == x).ToList(); filteredPatterns.Add(filtered); }); var flatterned = filteredPatterns.SelectMany(i => i); flatterned.ToList().ForEach(x => { if (_context.ScheduledTask.Where(e => e.PatternId == x.PatternId).Any()) x.PatternType = 1; else x.PatternType = 2; }); return flatterned.ToArray(); } catch (Exception ex) { throw new Exception(GetType().Name, ex); } }
avatar
Yulian
Shared 1 prompt
Created 1 year ago

Leave a Comment

Related Tag Prompts

94
0
151
0
Docker Pro
1 year ago 2023-01-29 06:08:59 AIPRM
308
0
MySQL Marvel
1 year ago 2023-02-13 00:05:32 AIPRM
260
0
Ansible Expert
1 year ago 2023-02-01 09:23:50 AIPRM
193
0
PostgreSQL Pro
1 year ago 2023-02-07 03:45:19 AIPRM
114
0
270
1
Dockerize me
1 year ago 2023-02-17 08:27:58 Chad Thompson-Smith