Börjat på RoundBuilding avsnittet , skall ändra save-svar från bool till int
This commit is contained in:
@ -13,9 +13,10 @@ public class ParticipantViewModel : ViewModelBase
|
||||
|
||||
}
|
||||
|
||||
public ParticipantViewModel(IRepository<Participant> repo) : base()
|
||||
public ParticipantViewModel(IRepository<Participant> repo, IMethodSharingService<Participant> sharingService) : base()
|
||||
{
|
||||
Repository = repo;
|
||||
_Repository = repo;
|
||||
_sharingService = sharingService;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -23,7 +24,8 @@ public class ParticipantViewModel : ViewModelBase
|
||||
#region Private Variables
|
||||
private Participant? _ParticipantObject = new();
|
||||
private ObservableCollection<Participant> _ParticipantList = new();
|
||||
private readonly IRepository<Participant>? Repository;
|
||||
private readonly IRepository<Participant>? _Repository;
|
||||
private readonly IMethodSharingService<Participant> _sharingService;
|
||||
#endregion
|
||||
|
||||
#region public Properties
|
||||
@ -53,23 +55,12 @@ public class ParticipantViewModel : ViewModelBase
|
||||
#region Get Method
|
||||
public ObservableCollection<Participant> Get()
|
||||
{
|
||||
if (Repository != null)
|
||||
{
|
||||
var participantsTask = Repository.Get();
|
||||
var participants = participantsTask is Task<IEnumerable<Participant>> task
|
||||
? task.GetAwaiter().GetResult()
|
||||
: (IEnumerable<Participant>)participantsTask;
|
||||
foreach (var participant in participants)
|
||||
{
|
||||
if (!_ParticipantList.Any(p => p.ParticipantId == participant.ParticipantId))
|
||||
{
|
||||
ParticipantList.Add(participant);
|
||||
}
|
||||
}
|
||||
}
|
||||
ParticipantList = _sharingService.Get();
|
||||
return ParticipantList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Get(id) Method
|
||||
@ -77,7 +68,7 @@ public class ParticipantViewModel : ViewModelBase
|
||||
{
|
||||
try
|
||||
{
|
||||
ParticipantObject = Repository?.Get(id).GetAwaiter().GetResult();
|
||||
ParticipantObject = _Repository?.Get(id).GetAwaiter().GetResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -88,11 +79,11 @@ public class ParticipantViewModel : ViewModelBase
|
||||
}
|
||||
public virtual bool Save()
|
||||
{
|
||||
if (Repository == null || ParticipantObject == null)
|
||||
if (_Repository == null || ParticipantObject == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var tmpTask = Repository.Save(ParticipantObject);
|
||||
var tmpTask = _Repository.Save(ParticipantObject);
|
||||
bool tmp = tmpTask.GetAwaiter().GetResult();
|
||||
if (tmp)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user