public async Task AddCollection(string name, bool locked = false) { var count = await Collections.CountAsync(); var maxIndex = count > 0 ? await Collections.MaxAsync(k => k.Index) : -1; var collection = new Collection { Id = Guid.NewGuid(), Name = name, IsDefault = locked, Index = maxIndex + 1 }; Collections.Add(collection); await SaveChangesAsync(); }