public async Task <ActionResult> GetMessageBoxInstanceList(int instanceOwnerPartyId, [FromQuery] string state, [FromQuery] string language) { string[] allowedStates = { "active", "archived", "deleted" }; string[] acceptedLanguages = { "en", "nb", "nn" }; string languageId = "nb"; if (string.IsNullOrEmpty(state)) { return(BadRequest($"State is empty. Please provide on of: {string.Join(", ", allowedStates)}")); } state = state.ToLower(); if (!allowedStates.Contains(state)) { return(BadRequest($"Invalid instance state. Please provide on of: {string.Join(", ", allowedStates)}")); } if (language != null && acceptedLanguages.Contains(language.ToLower())) { languageId = language; } List <Instance> allInstances = await _instanceRepository.GetInstancesInStateOfInstanceOwner(instanceOwnerPartyId, state); if (allInstances.Count <= 0) { return(Ok(new List <MessageBoxInstance>())); } // removing properties only used for active messageBoxInstances if (!state.Equals("active")) { allInstances.ForEach(i => i.DueBefore = null); } List <MessageBoxInstance> authorizedInstances = await _authorizationHelper.AuthorizeMesseageBoxInstances(HttpContext.User, allInstances); List <string> appIds = authorizedInstances.Select(i => InstanceHelper.GetAppId(i)).Distinct().ToList(); List <TextResource> texts = await _textRepository.Get(appIds, languageId); InstanceHelper.ReplaceTextKeys(authorizedInstances, texts, languageId); return(Ok(authorizedInstances)); }
public async Task <ActionResult> GetMessageBoxInstanceList(int instanceOwnerId, [FromQuery] string state, [FromQuery] string language) { string[] allowedStates = new string[] { "active", "archived", "deleted" }; string[] acceptedLanguages = new string[] { "en", "nb", "nn-no" }; string languageId = "nb"; state = state.ToLower(); if (string.IsNullOrWhiteSpace(state) || !allowedStates.Contains(state)) { return(BadRequest("Invalid instance state")); } if (language != null && acceptedLanguages.Contains(language.ToLower())) { languageId = language; } List <Instance> allInstances = await _instanceRepository.GetInstancesInStateOfInstanceOwner(instanceOwnerId, state); if (allInstances == null || allInstances.Count == 0) { return(NotFound($"Did not find any instances for instanceOwnerId={instanceOwnerId}")); } // TODO: authorize instances and filter list // get appId from filteredInstances eventually List <string> appIds = allInstances.Select(i => i.AppId) .Distinct() .ToList(); // Get title from app metadata Dictionary <string, Dictionary <string, string> > appTitles = await _applicationRepository.GetAppTitles(appIds); // Simplify instances and return List <MessageBoxInstance> messageBoxInstances = InstanceHelper.ConvertToMessageBoxInstance(allInstances, appTitles, languageId); return(Ok(messageBoxInstances)); }
public async Task <ActionResult> GetMessageBoxInstanceList(int instanceOwnerPartyId, [FromQuery] string state, [FromQuery] string language) { string[] allowedStates = { "active", "archived", "deleted" }; string[] acceptedLanguages = { "en", "nb", "nn" }; string languageId = "nb"; if (string.IsNullOrEmpty(state)) { return(BadRequest($"State is empty. Please provide on of: {string.Join(", ", allowedStates)}")); } state = state.ToLower(); if (!allowedStates.Contains(state)) { return(BadRequest($"Invalid instance state. Please provide on of: {string.Join(", ", allowedStates)}")); } if (language != null && acceptedLanguages.Contains(language.ToLower())) { languageId = language; } List <Instance> allInstances = await _instanceRepository.GetInstancesInStateOfInstanceOwner(instanceOwnerPartyId, state); //// TODO: Authorise instances and filter list if (allInstances.Count <= 0) { return(Ok(new List <MessageBoxInstance>())); } List <string> appIds = allInstances.Select(i => i.AppId).Distinct().ToList(); Dictionary <string, Dictionary <string, string> > appTitles = await _applicationRepository.GetAppTitles(appIds); List <MessageBoxInstance> messageBoxInstances = InstanceHelper.ConvertToMessageBoxInstance(allInstances, appTitles, languageId); return(Ok(messageBoxInstances)); }