-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathSortOrderCalculator.cs
More file actions
25 lines (20 loc) · 750 Bytes
/
Copy pathSortOrderCalculator.cs
File metadata and controls
25 lines (20 loc) · 750 Bytes
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
using System;
using System.Collections.Generic;
using LinkDotNet.Blog.Domain;
namespace LinkDotNet.Blog.Web.Features.Services;
public sealed class SortOrderCalculator : ISortOrderCalculator
{
public int GetSortOrder(ProfileInformationEntry target, IEnumerable<ProfileInformationEntry> all)
{
ArgumentNullException.ThrowIfNull(target);
var linkedEntries = new LinkedList<ProfileInformationEntry>(all);
var targetNode = linkedEntries.Find(target);
var next = targetNode!.Next;
if (next is null)
{
var prev = targetNode.Previous;
return (target.SortOrder + prev!.Value.SortOrder) / 2;
}
return (target.SortOrder + next.Value.SortOrder) / 2;
}
}