Exemple #1
0
        public async Task <IActionResult> SignalArrived(SignalInputModel inputModel)
        {
            //you can validate input here
            //then if the inputmodel is valid then you can save the signal
            var saveResult = await _signalService.SaveSignalAsync(inputModel);

            //if you can save the signal you can notify all clients by using SignalHub
            if (saveResult)
            {
                //you might think use a mapping tool?
                SignalViewModel signalViewModel = new SignalViewModel
                {
                    Description  = inputModel.Description,
                    CustomerName = inputModel.CustomerName,
                    Area         = inputModel.Area,
                    Zone         = inputModel.Zone,
                    SignalStamp  = Guid.NewGuid().ToString()
                };

                var user    = signalViewModel.CustomerName;
                var message = signalViewModel.Description;
                var date    = signalViewModel.SignalStamp;
                var zone    = signalViewModel.Zone;

                await _hubContext.Clients.All.SendAsync("SignalMessageReceived", user, message, date, zone);

                // await _hubContext.Clients.All.SendAsync("SignalMessageReceived", signalViewModel);
            }

            return(StatusCode(200, saveResult));
        }
Exemple #2
0
        public async Task <IActionResult> SignalArrived(SignalInputModel inputModel)
        {
            //you can validate input here
            //then if the inputModel is valid then you can save the signal
            var saveResult = await _signalService.SaveSignalAsync(inputModel);

            if (saveResult)
            {
                SignalViewModel signalViewModel = new SignalViewModel {
                    Description  = inputModel.Description,
                    CustomerName = inputModel.CustomerName,
                    Area         = inputModel.Area,
                    Zone         = inputModel.Zone,
                    SignalStamp  = Guid.NewGuid().ToString(),
                };

                //notify all clients by using SignalHub
                await _hubContext.Clients.All.SendAsync("SignalMessageReceived", signalViewModel);
            }

            return(StatusCode(200, saveResult));
        }