Exemplo n.º 1
0
        public async Task <IEnumerable <INotification> > Create(RouteNode before, RouteNode after)
        {
            var notifications = new List <INotification>();

            if (before is null || after is null)
            {
                notifications.Add(
                    new DoNothing($"Before or after route node is null, cannot update info."));
                return(notifications);
            }

            var routeNodeShadowTable = await _geoDatabase.GetRouteNodeShadowTable(after.Mrid, true);

            if (routeNodeShadowTable is null)
            {
                notifications.Add(
                    new DoNothing($"Could not find {nameof(RouteNode)} in shadowtable with id '{after.Mrid}'"));
                return(notifications);
            }

            if (AlreadyUpdated(after, routeNodeShadowTable))
            {
                notifications.Add(
                    new DoNothing($"{nameof(RouteNode)} with id '{after.Mrid}' is already updated"));
                return(notifications);
            }

            if (routeNodeShadowTable.MarkAsDeleted)
            {
                notifications.Add(
                    new DoNothing($"Shadowtable {nameof(RouteNode)} with id '{after.Mrid}' is marked to be deleted, info cannot be updated."));
                return(notifications);
            }

            if (IsRouteNodeInfoUpdated(before, after))
            {
                notifications.Add(new RouteNodeInfoUpdated(after));
            }

            if (IsLifecycleInfoModified(before, after))
            {
                notifications.Add(new RouteNodeLifecycleInfoUpdated(after));
            }

            if (IsMappingInfoModified(before, after))
            {
                notifications.Add(new RouteNodeMappingInfoUpdated(after));
            }

            if (IsNamingInfoModified(before, after))
            {
                notifications.Add(new RouteNodeNamingInfoUpdated(after));
            }

            if (IsSafetyInfoModified(before, after))
            {
                notifications.Add(new RouteNodeSafetyInfoUpdated(after));
            }

            if (notifications.Any())
            {
                await _geoDatabase.UpdateRouteNodeInfosShadowTable(after);
            }

            return(notifications);
        }