public ApiResponse SendNotify(NotificationMessageRequest data) { ApiResponse res = new ApiResponse(); try { var client = new RestClient(Notify_Api_Url); var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddParameter("application/json", JsonConvert.SerializeObject(data), ParameterType.RequestBody); IRestResponse response = client.Execute(request); res.Code = response.StatusCode; if (response.StatusCode != System.Net.HttpStatusCode.OK) { res.Code = response.StatusCode; res.Message = "Thông báo chưa được gửi đi, vui lòng thử lại"; _log.Error(response); } } catch (Exception ex) { _log.Error(ex.Message, ex); } return(res); }
public void SendNotifyUser(NotificationMessageRequest data) { var res = new NotificationService().SendNotify(data); if (res.Code != System.Net.HttpStatusCode.OK) { throw new BusinessException(res.Message); } }
public IHttpActionResult Post(NotificationMessageRequest data) { try { _uow.Notification.SendNotifyUser(data); return(Ok()); } catch (BusinessException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { _log.Error(ex); return(BadRequest(this.General_Err)); } }
public async Task <IHttpActionResult> NotifyUser(NotificationMessageRequest data) { try { if (string.IsNullOrEmpty(data.Content)) { return(BadRequest()); } var res = _uow.Notification.IU_Alert(new Core.Entities.Notification.Alert() { Link = data.Url, Title = data.Title, Content = data.Content, Type = (int)NotificationType.SystemAlert, IsBroadCast = data.IsBroadCast, UserId = data.UserId }); var context = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>(); if (string.IsNullOrEmpty(data.UserId) && data.IsBroadCast == true) { context.Clients.All.notifyuser_receive(Newtonsoft.Json.JsonConvert.SerializeObject(res)); } else { context.Clients.User(data.UserId).notifyuser_receive(Newtonsoft.Json.JsonConvert.SerializeObject(res)); } return(Ok()); } catch (BusinessException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { _log.Error(ex.Message); return(BadRequest(this.General_Err)); } }