public static async Task <MobileNotification> DeleteNotification(MobileNotification notification) { if (ProgenyService.Online()) { var client = new HttpClient(); client.BaseAddress = new Uri(Constants.ProgenyApiUrl); string accessToken = await UserService.GetAuthAccessToken(); client.SetBearerToken(accessToken); try { var result = await client.DeleteAsync("api/notifications/" + notification.NotificationId).ConfigureAwait(false); if (result.IsSuccessStatusCode) { MobileNotification deleteNotification = new MobileNotification(); deleteNotification.NotificationId = 0; return(deleteNotification); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(notification); } } return(notification); }
public static async Task <MobileNotification> UpdateNotification(MobileNotification notification) { if (ProgenyService.Online()) { var client = new HttpClient(); client.BaseAddress = new Uri(Constants.ProgenyApiUrl); string accessToken = await UserService.GetAuthAccessToken(); client.SetBearerToken(accessToken); try { var result = await client.PutAsync("api/notifications/" + notification.NotificationId, new StringContent(JsonConvert.SerializeObject(notification), Encoding.UTF8, "application/json")).ConfigureAwait(false); if (result.IsSuccessStatusCode) { string resultString = await result.Content.ReadAsStringAsync(); MobileNotification resultItem = JsonConvert.DeserializeObject <MobileNotification>(resultString); return(resultItem); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(notification); } } return(notification); }
public async Task <bool> MobileNotificationTest([FromBody] MobileNotificationTestViewModel settings) { try { await MobileNotification.NotifyAsync(new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1, UserId = settings.UserId }, settings.Settings); return(true); } catch (Exception e) { Log.LogError(LoggingEvents.Api, e, "Could not test Mobile Notifications"); return(false); } }
public async Task <IActionResult> Delete(int id) { MobileNotification mobileNotification = await _context.MobileNotificationsDb.SingleOrDefaultAsync(m => m.NotificationId == id); if (mobileNotification != null) { string userEmail = User.GetEmail(); if (mobileNotification.UserId == User.GetUserId()) { _context.MobileNotificationsDb.Remove(mobileNotification); await _context.SaveChangesAsync(); } return(NoContent()); } else { return(NotFound()); } }
public async Task <IActionResult> Put(int id, [FromBody] MobileNotification value) { string userId = User.GetUserId(); if (string.IsNullOrEmpty(userId)) { return(Unauthorized()); } MobileNotification mobileNotification = _context.MobileNotificationsDb.SingleOrDefault(m => m.NotificationId == id); if (mobileNotification != null && mobileNotification.UserId == userId) { mobileNotification.Read = value.Read; _context.MobileNotificationsDb.Update(mobileNotification); await _context.SaveChangesAsync(); return(Ok(mobileNotification)); } return(Ok(value)); }
public async Task ProgenyUpdateNotification(string title, string message, TimeLineItem timeLineItem, string iconLink = "") { var payload = new JObject( new JProperty("data", new JObject(new JProperty("title", title), new JProperty("message", message))), new JProperty("notData", timeLineItem.TimeLineId)); List <UserAccess> userList = await _dataService.GetProgenyUserAccessList(timeLineItem.ProgenyId); foreach (UserAccess userAcces in userList) { if (userAcces.AccessLevel <= timeLineItem.AccessLevel) { UserInfo userInfo = await _dataService.GetUserInfoByEmail(userAcces.UserId); if (userInfo != null) { MobileNotification notification = new MobileNotification(); notification.UserId = userInfo.UserId; notification.IconLink = iconLink; notification.ItemId = timeLineItem.ItemId; notification.ItemType = timeLineItem.ItemType; notification.Language = "EN"; notification.Message = message; notification.Title = title; notification.Time = DateTime.UtcNow; notification.Read = false; _context.MobileNotificationsDb.Add(notification); await _context.SaveChangesAsync(); string userTag = "userEmail:" + userAcces.UserId.ToUpper(); await Hub.SendFcmNativeNotificationAsync(payload.ToString(Newtonsoft.Json.Formatting.None), userTag); } } } // Android }