Skip to content

Commit

Permalink
Fixed two display issues
Browse files Browse the repository at this point in the history
Timetable: service instance count update
Servicesview: Calculated duration is not updated
  • Loading branch information
RudolfJan committed Apr 29, 2020
1 parent b863e6f commit 171f350
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
48 changes: 24 additions & 24 deletions TimeTableTool.Desktop/ViewModels/ServiceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public ServiceModel SelectedService
ServiceSelectedEvent serviceSelectedEvent = new ServiceSelectedEvent();
serviceSelectedEvent.SelectedService = _selectedService;
_events.PublishOnUIThreadAsync(serviceSelectedEvent);
if(SelectedService!=null)
if (SelectedService != null)
{
FullTimeEventsList= new BindableCollection<FullTimeEventModel>(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id));
FullTimeEventsList = new BindableCollection<FullTimeEventModel>(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id));
}
else
{
FullTimeEventsList=null;
FullTimeEventsList = null;
}
NotifyOfPropertyChange(() => CanLoadTimeEvents);
NotifyOfPropertyChange(() => SelectedService);
Expand Down Expand Up @@ -221,7 +221,7 @@ public void EditService()
SelectedServiceDirection = ServiceDirectionDataAccess.GetServiceDirectionById(ServiceDirectionId);
ServiceDirectionName = SelectedServiceDirection.ServiceDirectionName;
ServiceId = SelectedService.Id;
FullTimeEventsList= new BindableCollection<FullTimeEventModel>(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id));
FullTimeEventsList = new BindableCollection<FullTimeEventModel>(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id));
NotifyOfPropertyChange(() => CanLoadTimeEvents);
NotifyOfPropertyChange(() => CanEditService);
NotifyOfPropertyChange(() => CanDeleteService);
Expand Down Expand Up @@ -295,15 +295,15 @@ public void ClearService()
ServiceDirectionName = "";
ServiceId = 0;
NotifyOfPropertyChange(() => ServicesUI);
NotifyOfPropertyChange(()=>CanLoadTimeEvents);
NotifyOfPropertyChange(() => CanLoadTimeEvents);
NotifyOfPropertyChange(() => CanEditService);
}

public bool CanLoadTimeEvents
{
get
{
return SelectedService != null && (FullTimeEventsList==null ||
return SelectedService != null && (FullTimeEventsList == null ||
FullTimeEventsList.Count == 0);
}
}
Expand All @@ -317,34 +317,34 @@ public void LoadTimeEvents()

public void SaveTimeEvents()
{
foreach (var item in FullTimeEventsList)
foreach (var item in FullTimeEventsList)
{
if (item.EventType?.Length > 0)
{
if (item.EventType?.Length > 0)
var timeEvent = new TimeEventModel();
timeEvent.Id = item.Id;
timeEvent.EventType = item.EventType;
timeEvent.ArrivalTime = item.ArrivalTime;
timeEvent.WaitTime = item.WaitTime;
timeEvent.LocationId = item.LocationId;
timeEvent.ServiceId = item.ServiceId;
timeEvent.Order = item.Order;
if (item.Id > 0)
{
var timeEvent = new TimeEventModel();
timeEvent.Id = item.Id;
timeEvent.EventType = item.EventType;
timeEvent.ArrivalTime = item.ArrivalTime;
timeEvent.WaitTime = item.WaitTime;
timeEvent.LocationId = item.LocationId;
timeEvent.ServiceId = item.ServiceId;
timeEvent.Order = item.Order;
if(item.Id>0)
{
timeEvent.Id=item.Id;
TimeEventDataAccess.UpdateTimeEvent(timeEvent);
}
else
{
{
TimeEventDataAccess.InsertTimeEventForService(timeEvent);
}
}
}
int duration = FullTimeEventsList.Sum(x => x.ArrivalTime+x.WaitTime);
SelectedService.CalculatedDuration= duration;
ServiceDataAccess.UpdateServiceCalculatedDuration(duration,SelectedService.Id);
NotifyOfPropertyChange(()=>ServicesUI.ServiceList);
FullTimeEventsList= new BindableCollection<FullTimeEventModel>(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id));
int duration = FullTimeEventsList.Sum(x => x.ArrivalTime + x.WaitTime);
SelectedService.CalculatedDuration = duration;
ServiceDataAccess.UpdateServiceCalculatedDuration(duration, SelectedService.Id);
ServicesUI.ServiceList.Refresh();
FullTimeEventsList = new BindableCollection<FullTimeEventModel>(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id));
Log.Trace($"Time events for service {SelectedService.ServiceAbbreviation} saved", LogEventType.Event);
}
}
Expand Down
6 changes: 4 additions & 2 deletions TimeTableTool.Desktop/ViewModels/TimeTableViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ protected override async void OnViewLoaded(object view)
RouteId = rm.Id;
TimetablesUI.TimetableList = new BindableCollection<TimetableModel>(TimetableDataAccess.GetAllTimetablesPerRoute(RouteId));
ServiceDirectionList = new BindableCollection<ServiceDirectionModel>(ServiceDirectionDataAccess.GetAllServiceDirectionsPerRoute(RouteId));


NotifyOfPropertyChange(() => TimetablesUI);
}
#endregion
Expand Down Expand Up @@ -384,6 +382,7 @@ public void AddServiceInstance()
ServiceInstancesDestinationList.Add(SelectedServiceInstanceSource);
ConnectTtSiDataAccess.InsertConnection(SelectedServiceInstanceSource.Id, SelectedTimetable.Id);
NotifyOfPropertyChange(() => ServiceInstancesDestinationList);
NotifyOfPropertyChange(()=>CopyStatus);
}

public bool CanRemoveServiceInstance
Expand All @@ -398,6 +397,8 @@ public void RemoveServiceInstance()
{
ConnectTtSiDataAccess.DeleteConnection(SelectedServiceInstanceDestination.Id, SelectedTimetable.Id);
ServiceInstancesDestinationList.Remove(SelectedServiceInstanceDestination);
NotifyOfPropertyChange(() => ServiceInstancesDestinationList);
NotifyOfPropertyChange(()=>CopyStatus);
}


Expand All @@ -415,6 +416,7 @@ public void CopyAllServiceInstances()
ServiceInstancesDestinationList.Add(item);
ConnectTtSiDataAccess.InsertConnection(item.Id, SelectedTimetable.Id);
NotifyOfPropertyChange(() => ServiceInstancesDestinationList);
NotifyOfPropertyChange(()=>CopyStatus);
}
}
}
Expand Down

0 comments on commit 171f350

Please sign in to comment.