public async Task SaveLocationActionEvent(LocationActionEvent locationActionEvent)
        {
            using (DataContext = new SimplySecureDataContext())
            {
                DataContext.LocationActionEvents.Add(locationActionEvent);

                await DataContext.SaveChangesAsync();
            }
        }
        public static async Task <ModuleResponse> DetermineIfTriggering(
            ILocationRepository locationRepository,
            ILocationActionEventsRepository locationActionEventsRepository,
            IMessagingService messagingService,
            Module module)
        {
            var location = module.Location;

            var triggeredFlag = false;

            if (location.Armed && location.IsNotTriggered)
            {
                await locationRepository.TriggerLocation(location);

                await messagingService.SendModuleTriggeredMessage(module);

                var locationActionEvent = new LocationActionEvent
                {
                    LocationId = location.Id,

                    Action = LocationActionEnum.Triggered
                };

                await locationActionEventsRepository.SaveLocationActionEvent(locationActionEvent);

                triggeredFlag = true;
            }

            var moduleResponse = new ModuleResponse
            {
                Armed = location.Armed,

                Triggered = triggeredFlag && !location.IsSilentAlarm
            };

            return(moduleResponse);
        }
        public async Task DisarmLocation(Location location, ApplicationUser user, ILocationActionEventsRepository locationActionEventsRepository)
        {
            using (DataContext = new SimplySecureDataContext())
            {
                location.Armed = false;

                location.Triggered = false;

                DataContext.Locations.Update(location);

                await DataContext.SaveChangesAsync();

                var locationAction = new LocationActionEvent
                {
                    ApplicationUserId = user.Id,

                    Action = LocationActionEnum.Disarmed,

                    LocationId = location.Id
                };

                await locationActionEventsRepository.SaveLocationActionEvent(locationAction);
            }
        }
Exemple #4
0
        public static async Task SendPanicAlarm(
            ILocationActionEventsRepository locationActionEventsRepository,
            IMessagingService messagingService,
            ILocationRepository locationRepository,
            ApplicationUser user)
        {
            var locations = await locationRepository.GetLocationsForUser(user);

            foreach (var location in locations)
            {
                var locationActionEvent = new LocationActionEvent
                {
                    LocationId = location.Id,

                    Action = LocationActionEnum.Panic,

                    ApplicationUserId = user.Id
                };

                await locationActionEventsRepository.SaveLocationActionEvent(locationActionEvent);

                await messagingService.SendPanicAlarm(location, user);
            }
        }