/// <summary> /// Gets all notifications stored in a collection as an 'object'. /// These notifications must NOT be mistaken as the Model class Notification. /// The objects can be of either Job or Project /// /// Examples on how to use this list: /// List<object> notifications = GetNotificationList(); /// for (n in notifications) { /// if (n is Job) { /// // DO spesific Job code /// Job job = (Job)n; /// string date = job.expiryDate; // Will work /// } /// else if (n is Project) { /// // Do spesific Project code. /// Project p = (Project)n; /// } /// } /// </summary> /// <returns>A list of objects suitable for to be dislayed to the user as notifications</returns> public List<Advert> GetNotificationList() { DbJob dbJob = new DbJob(); DbNotification db = new DbNotification(); JobsController jc = new JobsController(); DbProject dbProject = new DbProject(); IEnumerable<Notification> notifications = db.GetNotifications(); List<Advert> notificationList = new List<Advert>(); foreach (var n in notifications) { System.Diagnostics.Debug.WriteLine("GetNotificationList: var n.id = " + n.id); System.Diagnostics.Debug.WriteLine("GetNotificationList: var n.jobUuid = " + n.jobUuid); System.Diagnostics.Debug.WriteLine("GetNotificationList: var n.projectUuid = " + n.projectUuid); if (!string.IsNullOrWhiteSpace(n.jobUuid)) { Job job = dbJob.GetJobByUuid(n.jobUuid); job.companies = dbJob.GetAllCompaniesRelatedToJob(job); notificationList.Add(job); } else { Project project = dbProject.GetProjectByUuid(n.projectUuid); project.companies = dbProject.GetAllCompaniesRelatedToProject(project); notificationList.Add(project); } } return notificationList.OrderByDescending(a => a.published).ToList(); }
/// <summary> /// Receives a Message from GCM. The method exctracts a message from the Bundle data, /// and calls SendNotification. /// /// If the students have enabled receiveNotifications, but /// disabled receiveProjectNotifications and receiveJobNotifications /// The student can still receive more general messages sent as push notifications /// however these notifications will only be displayed once and won't be displayed in the /// notification list. /// </summary> public override async void OnMessageReceived(string from, Bundle data) { DbStudent dbStudent = new DbStudent(); var message = data.GetString("message"); Log.Debug("MyGcmListenerService", "From: " + from); Log.Debug("MyGcmListenerService", "Message: " + message); var type = data.GetString("type"); var uuid = data.GetString("uuid"); Student student = dbStudent.GetStudent(); if (student != null && student.receiveNotifications) { DbNotification dbNotification = new DbNotification(); if (type == "project") { if (student.receiveProjectNotifications) { SendNotification(message); Log.Debug("MyGcmListenerService", "type: " + type); Log.Debug("MyGcmListenerService", "uuid: " + uuid); // type = job or project Log.Debug("MyGcmListenerService", "After New NotificationController, but before use of method."); dbNotification.InsertNotification(type, uuid); } } else if (type == "job") { if (student.receiveJobNotifications) { SendNotification(message); Log.Debug("MyGcmListenerService", "type: " + type); Log.Debug("MyGcmListenerService", "uuid: " + uuid); // type = job or project Log.Debug("MyGcmListenerService", "After New NotificationController, but before use of method."); dbNotification.InsertNotification(type, uuid); } } else { SendNotification(message); } } }
public List<object> GetNotificationListJobOnly() { DbJob dbJob = new DbJob(); DbNotification db = new DbNotification(); IEnumerable<Notification> notifications = db.GetNotifications(); List<object> notificationList = new List<object>(); foreach (var n in notifications) { System.Diagnostics.Debug.WriteLine("GetNotificationList: var n.id = " + n.id); System.Diagnostics.Debug.WriteLine("GetNotificationList: var n.jobUuid = " + n.jobUuid); if (!string.IsNullOrWhiteSpace(n.jobUuid)) { Job job = dbJob.GetJobByUuid(n.jobUuid); job.companies = dbJob.GetAllCompaniesRelatedToJob(job); notificationList.Add(job); } } return notificationList; }
public List<object> GetNotificationListProjectOnly() { DbNotification db = new DbNotification(); DbProject dbProject = new DbProject(); IEnumerable<Notification> notifications = db.GetNotifications(); List<object> notificationList = new List<object>(); foreach (var n in notifications) { System.Diagnostics.Debug.WriteLine("GetNotificationList: var n.id = " + n.id); System.Diagnostics.Debug.WriteLine("GetNotificationList: var n.jobUuid = " + n.jobUuid); System.Diagnostics.Debug.WriteLine("GetNotificationList: var n.projectUuid = " + n.projectUuid); if (!string.IsNullOrWhiteSpace(n.projectUuid)) { Project project = dbProject.GetProjectByUuid(n.projectUuid); project.companies = dbProject.GetAllCompaniesRelatedToProject(project); notificationList.Add(project); } } return notificationList; }
private void DeleteNotification(Varsel varsel) { varsler.Remove(varsel); DbNotification dbNotification = new DbNotification(); if (varsel.Type == "job") { dbNotification.DeleteNotificationBasedOnJob(varsel.Uuid); } else { dbNotification.DeleteNotificationBasedOnProject(varsel.Uuid); } }
private async void DeleteAllNotifications(object sender, EventArgs e) { var action = await DisplayActionSheet("Slett alle varsler", "Avbryt", null, "OK"); if (action != null && action == "OK") { DbNotification dbNotification = new DbNotification(); dbNotification.DeleteAllNotifications(); } //Sort(); ExcecuteRefreshCommand(); }