public async Task <IActionResult> Post([FromBody] NotificationSubscription notificationSubscription) { var settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }; var locationsFile = await IoFile.ReadAllTextAsync(_locationsPath); var locations = JsonConvert.DeserializeObject <IEnumerable <VariableMessageSignPortal> >(locationsFile, settings).ToList(); var roadWay = locations.SelectMany(l => l.RoadWays).FirstOrDefault(r => r.HmLocation == notificationSubscription.HmLocation); var chosenRoadWay = new PushRoadWay { Coordinates = locations.FirstOrDefault(l => l.RoadWays.Contains(roadWay)).Coordinates, HmLocation = roadWay.HmLocation, VariableMessageSigns = roadWay.VariableMessageSigns }; var userSubscriptions = await GetPushUserSubscriptionsFromFile(); var subscription = userSubscriptions.FirstOrDefault(u => JsonConvert.SerializeObject(u.PushSubscription) == JsonConvert.SerializeObject(notificationSubscription.PushSubscription)); if (subscription == null) { subscription = new PushUser { PushSubscription = notificationSubscription.PushSubscription }; userSubscriptions.Add(subscription); } if (subscription.RoadWays.All(r => r.HmLocation != chosenRoadWay.HmLocation)) { subscription.RoadWays.Add(chosenRoadWay); } else { return(Conflict()); } await WritePushUserSubscriptionsToFile(userSubscriptions); return(Created(new Uri("http://place.holder"), chosenRoadWay.HmLocation)); }
public void SavePushMsg(HttpContext context) { try { string id = context.Request.Form["ctl00$cphMain$hId"].Trim(); string sTitle = context.Request.Form["ctl00$cphMain$txtTitle"].Trim(); string sPushContent = context.Request.Form["ctl00$cphMain$txtPushContent"].Trim(); string sSendRange = context.Request.Form["ctl00$cphMain$txtSendRange"].Trim(); string sckAll = context.Request.Form["ctl00$cphMain$ckAll"]; Guid gId = Guid.Empty; PushMsgInfo model = new PushMsgInfo(); model.LastUpdatedDate = DateTime.Now; model.Id = gId; model.Title = sTitle; model.PushContent = sPushContent; string PushParam = "1"; if (null != sckAll) { model.SendRange = "全部"; } else { model.SendRange = "个人"; if (-1 == sSendRange.IndexOf(',')) { PushParam = "2@@" + sSendRange; } else { PushParam = "3@@" + sSendRange; } } model.PushType = "zdy"; if (string.IsNullOrWhiteSpace(model.Title) || string.IsNullOrWhiteSpace(model.PushContent)) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Params_InvalidError + "\"}"); return; } PushMsg bll = new PushMsg(); int effect = -1; model.LastUpdatedDate = DateTime.Now; Guid pushMsgId = bll.InsertByOutput(model); if (!pushMsgId.Equals(Guid.Empty)) { effect = 1; if (!PushParam.Equals("1")) { PushUser bllPushUser = new PushUser(); PushUserInfo pushUserInfo = new PushUserInfo(); pushUserInfo.PushId = pushMsgId; pushUserInfo.PushUser = sSendRange; bllPushUser.InsertOW(pushUserInfo); } } if (effect == 110) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Exist + "\"}"); return; } if (effect < 1) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Error + "\"}"); return; } #region 推送信息到推送服务系统 try { PushContentService pushProxy = new PushContentService(); if (System.Configuration.ConfigurationManager.AppSettings["PushServiceUrl"] != null) { pushProxy.Url = System.Configuration.ConfigurationManager.AppSettings["PushServiceUrl"].ToString(); } string sxml = ""; sxml = string.Format(@"<XmlParameters><ReceivePushContent><PushType>{0}</PushType><PushContent>{1}</PushContent><Title>{2}</Title><PushParam>{3}</PushParam></ReceivePushContent></XmlParameters>", "zdy", model.PushContent, model.Title, PushParam); pushProxy.ReceivePushContentAsync(sxml); } catch { } #endregion context.Response.Write("{\"success\": true,\"message\": \"" + MessageContent.Submit_Success + "\"}"); } catch (Exception ex) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.AlertTitle_Ex_Error + ":" + ex.Message + "\"}"); } }
/// <summary> /// get audiance user counted /// </summary> /// <param name="user"></param> /// <returns></returns> public Task <int> GetUser(PushUser user) { throw new NotImplementedException(); }