Updated code to filter out subscriptions that have been removed from the profile, and insert new ones into the list in the Update() fucntion.
36 lines
No EOL
1.2 KiB
C#
36 lines
No EOL
1.2 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace FreeTubeSync.Model;
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public class Profile
|
|
{
|
|
[Key]
|
|
public string _id { get; set; } = string.Empty;
|
|
public string name { get; set; } = string.Empty;
|
|
public string bgColor { get; set; } = string.Empty;
|
|
public string textColor { get; set; } = string.Empty;
|
|
public List<Subscription> subscriptions { get; set; } = [];
|
|
|
|
public void Update(Profile other)
|
|
{
|
|
if (other.name != name) name = other.name;
|
|
if (other.bgColor != bgColor) bgColor = other.bgColor;
|
|
if (other.textColor != textColor) textColor = other.textColor;
|
|
var remove = new List<Subscription>();
|
|
foreach (var sub in subscriptions)
|
|
{
|
|
if (other.subscriptions.Any(x => x.id == sub.id)) continue;
|
|
remove.Add(sub);
|
|
}
|
|
subscriptions.RemoveAll(x => remove.Contains(x));
|
|
remove.Clear();
|
|
foreach (var sub in other.subscriptions)
|
|
{
|
|
if (subscriptions.Any(x => x.id == sub.id)) continue;
|
|
remove.Add(sub);
|
|
}
|
|
subscriptions.AddRange(remove);
|
|
}
|
|
} |