/// <summary> /// Retrieves the contents of the message box based on the user credentials of the currently logged in user /// and populates the local model of the message box /// </summary> /// <param name="type">The type of messages we want, i.e Messagebox or Archive</param> /// <param name="skipSize">Max result per API call is 50, use skip to get the next 50</param> /// <returns></returns> public async Task<List<Message>> PopulateMessagebox(Constants.MMBType type, int skipSize) { if (AppContext.Domain == null) { } //Setup the Profile Session.Profile = await GetProfile(); if (Session.Profile == null) { throw new AppException("0", "Failed to get profile"); } //Setup organizations Session.Organizations = await PopulateOrganizations(); if (Session.Organizations == null) throw new AppException("0", "Failed to get Organizations"); string url = string.Format(AppContext.RESTURL, Session.SelectedOrg.OrganizationNumber); //Setup messagebox string messagesJson = await _dal.GetMessageBox(type, skipSize, url); var mess = new List<Message>(); if (messagesJson == null) throw new AppException("0", "Failed to get Organizations"); try { if (!string.IsNullOrEmpty(messagesJson)) { mess = Serializer.DeserializeMessagebox(messagesJson); } } catch (Exception e) { Logger.Logg("Failed to de-serialize the messagebox:" + e); throw new AppException("0", ErrorMessages.SerializationError); } if (!UseOneInbox) { switch (type) { case Constants.MMBType.Messagebox: if (Session.mmb == null) { Session.mmb = new Messagebox {Messages = new List<Message>()}; } Session.mmb.Messages.AddRange(mess); Session.mmb.UnfilteredMessages = Session.mmb.Messages.ToList(); Session.mmb.Unread = Session.mmb.Messages.Count(m => m.Status == Constants.NO.Nob.Status.Unread); break; case Constants.MMBType.Archive: if (Session.mab == null) { Session.mab = new Messagebox {Messages = new List<Message>()}; } Session.mab.Messages.AddRange(mess); Session.mab.UnfilteredMessages = Session.mab.Messages.ToList(); Session.mab.Unread = Session.mab.Messages.Count(m => m.Status == Constants.NO.Nob.Status.Unread); break; } } else { if (Session.mmb == null) { Session.mmb = new Messagebox {Messages = new List<Message>()}; } Session.mmb.Messages.AddRange(mess); Session.mmb.UnfilteredMessages = Session.mmb.Messages.ToList(); Session.mmb.Unread = Session.mmb.Messages.Count(m => m.Status == Constants.NO.Nob.Status.Unread); } return mess; }
/// <summary> /// Search through the message box on the server, filters and sets the current message box to the search result /// </summary> /// <param name="p"></param> /// <param name="type"></param> public async Task<List<Message>> Search(string p, Constants.MMBType type) { var mess = new List<Message>(); try { string messageJSON = await _dal.Search(p, type); if (!string.IsNullOrEmpty(messageJSON)) { mess = Serializer.DeserializeMessagebox(messageJSON); } } catch (Exception e) { Logger.Logg("Failed to de-serialize the messagebox:" + e); throw new AppException("0", ErrorMessages.SerializationError); } return mess; }