public async Task <HttpResponseMessage> Select(MT_Notifications NSMD) { Db = con.SurgeryCenterDb(NSMD.Slug); NotificationsResponse Response = new NotificationsResponse(); try { MT_Notifications notification = new MT_Notifications(); Query ObjQuery = Db.Collection("MT_Notifications").WhereEqualTo("NFT_Is_Deleted", false).WhereEqualTo("NFT_Is_Active", true).WhereEqualTo("NFT_Unique_ID", NSMD.NFT_Unique_ID); QuerySnapshot ObjQuerySnap = await ObjQuery.GetSnapshotAsync(); if (ObjQuerySnap != null) { notification = ObjQuerySnap.Documents[0].ConvertTo <MT_Notifications>(); Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = notification; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public async Task <HttpResponseMessage> GetNotiListFilterWithPO(MT_Notifications NSMD) { Db = con.SurgeryCenterDb(NSMD.Slug); NotificationsResponse Response = new NotificationsResponse(); try { List <MT_Notifications> NotiList = new List <MT_Notifications>(); Query ObjQuery = Db.Collection("MT_Notifications").WhereEqualTo("NFT_Is_Deleted", false).WhereEqualTo("NFT_Is_Active", true).WhereEqualTo("NFT_Surgery_Physician_Id", NSMD.NFT_Surgery_Physician_Id).OrderByDescending("NFT_Create_Date"); QuerySnapshot ObjQuerySnap = await ObjQuery.GetSnapshotAsync(); if (ObjQuerySnap != null) { foreach (DocumentSnapshot Docsnap in ObjQuerySnap.Documents) { NotiList.Add(Docsnap.ConvertTo <MT_Notifications>()); } Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.DataList = NotiList; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public NotificationsResponse CreateNotificationsResponse(List <CampaignEN> pNotifications) { NotificationsResponse response = new NotificationsResponse(); NotificationMessages messages = new NotificationMessages(); messages.userNotifications = new List <NotificationItem>(); try { foreach (var item in pNotifications) { NotificationItem notif = new NotificationItem(); notif.trackingID = item.NotificationID; notif.notificationID = item.CampaignID; notif.title = item.NotificationTitle; notif.message = item.NotificationMessage; notif.seen = item.Read; messages.userNotifications.Add(notif); } response.notifications = messages; response.count = messages.userNotifications.Count; } catch (Exception ex) { Console.WriteLine(ex.InnerException); } return(response); }
public async Task GetNotificationEventsAsync_ReturnsExpectedResult() { // Arrange var client = GetMockSqClientWithCredentialAndVersion("5.6"); var expectedEvent = new NotificationsResponse { Category = "QUALITY_GATE", Link = new Uri("http://foo.com"), Date = new DateTimeOffset(2010, 1, 1, 14, 59, 59, TimeSpan.FromHours(2)), Message = "foo", Project = "test" }; client .Setup(x => x.GetNotificationEventsAsync(It.IsAny <NotificationsRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(Result.Ok(new[] { expectedEvent })); var service = new SonarQubeService(WrapInMockFactory(client)); await service.ConnectAsync(new ConnectionInformation(new Uri("http://mysq.com")), CancellationToken.None); // Act var result = await service.GetNotificationEventsAsync("test", DateTimeOffset.Now, CancellationToken.None); // Assert client.VerifyAll(); result.Should().NotBeNull(); result.Should().HaveCount(1); result[0].Category.Should().Be(expectedEvent.Category); result[0].Link.Should().Be(expectedEvent.Link); result[0].Date.Should().Be(expectedEvent.Date); result[0].Message.Should().Be(expectedEvent.Message); }
private void AssertEqual(NotificationsResponse x, NotificationsResponse y, int itemIndex) { Assert.AreEqual(x.Category, y.Category, string.Format("Category, item {0}", itemIndex)); Assert.AreEqual(x.Date, y.Date, string.Format("Date, item {0}", itemIndex)); Assert.AreEqual(x.Link, y.Link, string.Format("Link, item {0}", itemIndex)); Assert.AreEqual(x.Message, y.Message, string.Format("Message, item {0}", itemIndex)); Assert.AreEqual(x.Project, y.Project, string.Format("Project, item {0}", itemIndex)); }
public async Task <HttpResponseMessage> DeleteAction(MT_Notifications NSMD) { Db = con.SurgeryCenterDb(NSMD.Slug); NotificationsResponse Response = new NotificationsResponse(); try { List <Notification_Action> ActionList = new List <Notification_Action>(); Query ObjQuery = Db.Collection("MT_Notifications").WhereEqualTo("NFT_Is_Deleted", false).WhereEqualTo("NFT_Is_Active", true).WhereEqualTo("NFT_Unique_ID", NSMD.NFT_Unique_ID); QuerySnapshot ObjQuerySnap = await ObjQuery.GetSnapshotAsync(); if (ObjQuerySnap != null) { MT_Notifications noti = ObjQuerySnap.Documents[0].ConvertTo <MT_Notifications>(); if (noti.NFT_Actions != null) { foreach (Notification_Action action in noti.NFT_Actions) { if (action.NFA_Unique_ID != NSMD.NFT_Actions[0].NFA_Unique_ID) { ActionList.Add(action); } } } } Dictionary <string, object> initialData = new Dictionary <string, object> { { "NFT_Actions", ActionList }, }; DocumentReference docRef = Db.Collection("MT_Notifications").Document(NSMD.NFT_Unique_ID); WriteResult Result = await docRef.UpdateAsync(initialData); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = NSMD; } else { Response.Status = con.StatusNotInsert; Response.Message = con.MessageNotInsert; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public HttpResponseMessage Post([FromBody] NotificationsRequest request) { HttpResponseMessage response; try { NotificationsResponse notificationsResponse = new NotificationsResponse(); notificationsResponse.UserNotifications = new ObservableCollection <TechReady.Common.Models.Notification>(); using (DbModel.TechReadyDbContext ctx = new DbModel.TechReadyDbContext()) { var appUserId = Convert.ToInt32(request.AppUserId); var appUser = (from c in ctx.AppUsers where c.AppUserID == appUserId select c).FirstOrDefault(); if (appUser != null) { foreach (var not in appUser.NotificationsRecieved) { Notification n = new Notification() { NotificationID = not.NotificationID, Read = not.Read, Removed = not.Removed }; if (not.Notification != null) { n.Title = not.Notification.NotificationTitle; n.Message = not.Notification.NotificationMessage; n.PushDateTime = not.Notification.PushDateTime; n.ActionLink = not.Notification.ActionLink; n.NotificationType = (int)not.Notification.TypeOfNotification; n.ResourceId = not.Notification.ResourceId; } notificationsResponse.UserNotifications.Add(n); } } } response = this.Request.CreateResponse(HttpStatusCode.OK, notificationsResponse); response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300)); } catch (Exception ex) { HttpError myCustomError = new HttpError(ex.Message) { { "IsSuccess", false } }; return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError)); } return(response); }
public async Task <HttpResponseMessage> Update(MT_Notifications NSMD) { Db = con.SurgeryCenterDb(NSMD.Slug); NotificationsResponse Response = new NotificationsResponse(); try { List <Notification_Action> ActionList = new List <Notification_Action>(); Dictionary <string, object> initialData = new Dictionary <string, object> { { "NFT_Category_ID", NSMD.NFT_Category_ID }, { "NFT_Category_Name", NSMD.NFT_Category_Name }, { "NFT_Category_Type_ID", NSMD.NFT_Category_Type_ID }, { "NFT_Category_Type_Name", NSMD.NFT_Category_Type_Name }, { "NFT_Name", NSMD.NFT_Name }, { "NFT_Description", NSMD.NFT_Description }, { "NFT_Modify_Date", con.ConvertTimeZone(NSMD.NFT_TimeZone, Convert.ToDateTime(NSMD.NFT_Modify_Date)) }, { "NFT_TimeZone", NSMD.NFT_TimeZone } }; DocumentReference docRef = Db.Collection("MT_Notifications").Document(NSMD.NFT_Unique_ID); WriteResult Result = await docRef.UpdateAsync(initialData); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = NSMD; } else { Response.Status = con.StatusNotInsert; Response.Message = con.MessageNotInsert; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public async Task <NotificationsResponse> GetOne(string id, string lotId) { try { ServicePointManager.Expect100Continue = false; string token = await this.securityService.getToken(); if (token != null) { HttpClient myHttpClient = new HttpClient(); myHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Constants.AUTHORIZATION_BEARER, token); string values = string.Concat(this.config.eaddressServiceUri, "/api/v1.0/notification/", id, "/", lotId); HttpResponseMessage response = await myHttpClient.GetAsync(string.Concat(this.config.eaddressServiceUri, "/api/v1.0/notification/", id, "/", lotId)); if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); NotificationsResponse notificationResponse = JsonConvert.DeserializeObject <NotificationsResponse>(content); return(notificationResponse); } else { Debug.WriteLine(response.RequestMessage.ToString()); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } return(null); }
public async Task GetNotificationEventsAsync_GetEventsFromTheServer() { // Arrange var client = SetupClientWithHttpResponse(HttpStatusCode.OK, @"{""events"": [{""category"":""QUALITY_GATE"", ""message"":""Quality Gate of project 'test' is now Red (was Green)"", ""link"":""http://localhost:9000/dashboard?id=test"", ""project"":""test"", ""date"":""2017-09-14T10:55:19+0200""}]}"); var request = new NotificationsRequest { ProjectKey = "test", EventsSince = DateTimeOffset.Parse("2017-09-14T10:00:00+0200", CultureInfo.InvariantCulture) }; var expected = new NotificationsResponse[] { new NotificationsResponse { Category = "QUALITY_GATE", Message = "Quality Gate of project 'test' is now Red (was Green)", Link = new Uri("http://localhost:9000/dashboard?id=test"), Date = new DateTimeOffset(2017, 9, 14, 10, 55, 19, 0, TimeSpan.FromHours(2)), Project = "test" } }; // Act var result = await client .GetNotificationEventsAsync(request, CancellationToken.None); // Assert result.IsSuccess.Should().BeTrue(); AssertEqual(expected, result.Value); }
public async Task <HttpResponseMessage> SelectAction(MT_Notifications NSMD) { Db = con.SurgeryCenterDb(NSMD.Slug); NotificationsResponse Response = new NotificationsResponse(); try { List <Notification_Action> ActionList = new List <Notification_Action>(); Query ObjQuery = Db.Collection("MT_Notifications").WhereEqualTo("NFT_Is_Deleted", false).WhereEqualTo("NFT_Is_Active", true).WhereEqualTo("NFT_Unique_ID", NSMD.NFT_Unique_ID); QuerySnapshot ObjQuerySnap = await ObjQuery.GetSnapshotAsync(); if (ObjQuerySnap != null) { MT_Notifications noti = ObjQuerySnap.Documents[0].ConvertTo <MT_Notifications>(); if (noti.NFT_Actions != null) { foreach (Notification_Action action in noti.NFT_Actions) { if (action.NFA_Unique_ID == NSMD.NFT_Actions[0].NFA_Unique_ID) { ActionList.Add(action); } } } noti.NFT_Actions = ActionList; Response.Data = noti; Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public async Task <HttpResponseMessage> CreateAsync(MT_Notifications NSMD) { Db = con.SurgeryCenterDb(NSMD.Slug); NotificationsResponse Response = new NotificationsResponse(); try { List <Notification_Action> ActionList = new List <Notification_Action>(); UniqueID = con.GetUniqueKey(); NSMD.NFT_Unique_ID = UniqueID; NSMD.NFT_Create_Date = con.ConvertTimeZone(NSMD.NFT_TimeZone, Convert.ToDateTime(NSMD.NFT_Create_Date)); NSMD.NFT_Modify_Date = con.ConvertTimeZone(NSMD.NFT_TimeZone, Convert.ToDateTime(NSMD.NFT_Modify_Date)); NSMD.NFT_Actions = ActionList; DocumentReference docRef = Db.Collection("MT_Notifications").Document(UniqueID); WriteResult Result = await docRef.SetAsync(NSMD); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = NSMD; } else { Response.Status = con.StatusNotInsert; Response.Message = con.MessageNotInsert; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public NotificationsResponse GetNotificationsByUser(int userId) { var response = new NotificationsResponse(); try { var notificationRepository = new NotificationRepository(); var notifications = notificationRepository.Query().Where(x => x.CreateBy == userId).OrderByDescending(x => x.CreatedDate).ToList(); var newNotificationsCount = 0; foreach (var notification in notifications) { bool wasViewed = (notification.WasViewed.HasValue) ? notification.WasViewed.Value : false; if (!wasViewed) { newNotificationsCount++; } response.NotificationsList.Add(new NotificationDto() { idNotification = notification.idNotification, CreatedDate = notification.CreatedDate.Value, Text = notification.Text, WasViewed = notification.WasViewed }); } response.NotificationsCount = newNotificationsCount; notificationRepository.Dispose(); response.Acknowledgment = true; response.Message = "Success"; } catch (Exception ex) { response.Acknowledgment = false; response.Message = ex.Message; } return(response); }
private SonarQubeNotification ToNotification(NotificationsResponse response) => new SonarQubeNotification(response.Category, response.Message, response.Link, response.Date);
public static SonarQubeNotification FromResponse(NotificationsResponse response) { return(new SonarQubeNotification(response.Category, response.Message, response.Link, response.Date)); }
public async Task GetNotifications() { this.OperationInProgress = true; try { ObservableCollection <Notification> model = null; if (NetworkHelper.IsNetworkAvailable() == false) { model = await LocalStorage.ReadJsonFromFile <ObservableCollection <Notification> >("allNotifications"); this.AllNotifications = model; //await MessageHelper.ShowMessage("Please connect to internet to download latest events"); return; } else { // Fetch data about the user //saves and updates data on server var userModel = await LocalStorage.ReadJsonFromFile <UserRegistrationPageViewModel>("registration"); if (userModel != null) { //TODO SHIV: API Check var result = await ServiceProxy.CallService("api/Notifications", JsonConvert.SerializeObject( new NotificationsRequest() { AppUserId = userModel.UserId })); if (result.IsSuccess) { NotificationsResponse response = JsonConvert.DeserializeObject <NotificationsResponse>(result.response); model = await LocalStorage.ReadJsonFromFile <ObservableCollection <Notification> >("allNotifications"); if (model != null) { foreach (var notif in model) { //response.UserNotifications.FirstOrDefault(n => (n.NotificationID == notif.NotificationID && notif.Read)); if (notif.Read) { if (response.UserNotifications.FirstOrDefault(n => (n.NotificationID == notif.NotificationID)) != null) { response.UserNotifications.FirstOrDefault(n => (n.NotificationID == notif.NotificationID)).Read = true; this.Notification_Tapped(response.UserNotifications.FirstOrDefault(n => (n.NotificationID == notif.NotificationID))); } } if (notif.Removed) { if (response.UserNotifications.FirstOrDefault(n => (n.NotificationID == notif.NotificationID)) != null) { response.UserNotifications.FirstOrDefault(n => (n.NotificationID == notif.NotificationID)).Removed = true; this.RemoveNotification_Click(response.UserNotifications.FirstOrDefault(n => (n.NotificationID == notif.NotificationID))); } } } } this.AllNotifications = new ObservableCollection <Notification>(response.UserNotifications.Where(x => x.Removed == false).ToList().OrderByDescending(x => x.PushDateTime)); await LocalStorage.SaveJsonToFile(this.AllNotifications, "allNotifications"); } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { this.OperationInProgress = false; } }
public JsonResult UrlAsPDF(int reportId, bool withInsights, bool withChartInsights, bool withComments, string reportName, string from, string to) { var response = new NotificationsResponse(); try { var pdf = new Rotativa.ActionAsPdf("MainToPdf", new { reportId = reportId, withComments = withComments, withInsights = withInsights, withChartInsights = withChartInsights, chartId = 0, from = from, to = to }) { FileName = reportName + ".pdf", IsJavaScriptDisabled = false, PageMargins = { Left = 10, Right = 10 } }; _log.Warn("Started"); byte[] applicationPDFData = pdf.BuildPdf(ControllerContext); var path = Server.MapPath("~/Reports/Pdf"); var fileName = reportName + WebSecurity.CurrentUserId + ".pdf"; if (!System.IO.Directory.Exists(path + "/" + WebSecurity.CurrentUserId.ToString())) { System.IO.Directory.CreateDirectory(path + "/" + WebSecurity.CurrentUserId.ToString()); } var directory = new DirectoryInfo(path + "/" + WebSecurity.CurrentUserId.ToString()); path = System.IO.Path.Combine(path, WebSecurity.CurrentUserId.ToString(), fileName); System.IO.File.WriteAllBytes(path, applicationPDFData); var fileUrl = Request.Url.GetLeftPart(UriPartial.Authority) + Url.Content("~") + "/Reports/Pdf/" + WebSecurity.CurrentUserId.ToString() + "/" + fileName; var filesOrdered = directory.GetFiles().OrderByDescending(x => x.LastWriteTime); if (filesOrdered.Count() > 10) { var files = filesOrdered.Skip(10).ToList(); foreach (var file in files) { file.Delete(); } } var notificationDto = new NotificationDto() { CreateBy = WebSecurity.CurrentUserId, Text = "Your \"" + reportName + "\" PDF is ready <a href='" + fileUrl + "' target='_blank'>here</a>", WasViewed = false, CreatedDate = DateTime.Now }; if (_notificationService.AddNotification(notificationDto).Acknowledgment) { response.Notification = notificationDto; response.Acknowledgment = true; response.Message = "Success"; } else { response.Acknowledgment = false; response.Message = "Error"; } _notificationService.DeleteNotifications(WebSecurity.CurrentUserId); } catch (Exception ex) { ViewBag.myData = "error: " + ex.Message; _log.Error("---- Exception Creating PDF: " + ex.Message + " ----");//("Exception Creating PDF", ex.Message); response.Acknowledgment = false; response.Message = "Error"; } return(Json(response, JsonRequestBehavior.AllowGet)); //return RedirectToAction("MainToPdf", new { reportId = reportId });; }