public object Post(PushNotificationAdministrationRequest request) { var account = _dao.FindByEmail(request.EmailAddress); if (account == null) { throw new HttpError(HttpStatusCode.InternalServerError, "sendPushNotificationErrorNoAccount"); } var devices = _daoDevice.FindByAccountId(account.Id); var deviceDetails = devices as DeviceDetail[] ?? devices.ToArray(); if (devices == null || !deviceDetails.Any()) { throw new HttpError(HttpStatusCode.InternalServerError, "sendPushNotificationErrorNoDevice"); } // We create a new instance each time as we need to start from a clean state to get meaningful error messages var pushNotificationService = new PushNotificationService(_serverSettings, _logger); foreach (var device in deviceDetails) { try { pushNotificationService.Send(request.Message, new Dictionary <string, object>(), device.DeviceToken, device.Platform); } catch (Exception e) { _logger.LogError(e); throw new HttpError(HttpStatusCode.InternalServerError, device.Platform + "-" + e.Message); } } return(new HttpResult(HttpStatusCode.OK)); }