Exemple #1
0
        public async Task <IActionResult> Get([FromBody] SearchRequestVM searchRequestVM)
        {
            try
            {
                #region Error Checking
                GenericResponseVM genericResponse = null;
                //Input validation
                if (searchRequestVM == null && searchRequestVM.Client == null && searchRequestVM.SearchObject == null)
                {
                    genericResponse = new GenericResponseVM()
                    {
                        Value   = errorSettings.MessageNoInputs,
                        Code    = HttpStatusCode.BadRequest.ToString(),
                        IsError = true
                    };
                    //If the input validation is failed, send GenericResponseVM which contains the error information
                    return(matterCenterServiceFunctions.ServiceResponse(genericResponse, (int)HttpStatusCode.OK));
                }
                #endregion
                ClientContext clientContext = null;
                clientContext = spoAuthorization.GetClientContext(searchRequestVM.Client.Url);
                var searchResultsVM = await documentProvision.GetDocumentsAsync(searchRequestVM, clientContext);

                return(matterCenterServiceFunctions.ServiceResponse(searchResultsVM.DocumentDataList, (int)HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                var errorResponse = customLogger.GenerateErrorResponse(ex);
                return(matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.OK));
            }
        }
        public async Task <IActionResult> GetTaxonomy([FromBody] TermStoreViewModel termStoreViewModel)
        {
            try
            {
                #region Error Checking

                var matterInformation = new MatterInformationVM()
                {
                    Client = new Client()
                    {
                        Url = termStoreViewModel.Client.Url
                    }
                };
                var genericResponseVM = validationFunctions.IsMatterValid(matterInformation, 0, null);
                if (genericResponseVM != null)
                {
                    genericResponseVM.Description = $"Error occurred while getting the taxonomy data";
                    return(matterCenterServiceFunctions.ServiceResponse(genericResponseVM, (int)HttpStatusCode.BadRequest));
                }
                #endregion

                string cacheValue = string.Empty;
                string key        = string.Empty;
                var    details    = termStoreViewModel.TermStoreDetails;
                if (details.TermSetName == taxonomySettings.PracticeGroupTermSetName)
                {
                    key = ServiceConstants.CACHE_MATTER_TYPE;
                }
                else if (details.TermSetName == taxonomySettings.ClientTermSetName)
                {
                    key = ServiceConstants.CACHE_CLIENTS;
                }

                ServiceUtility.RedisCacheHostName = generalSettings.RedisCacheHostName;
                cacheValue = ServiceUtility.GetDataFromAzureRedisCache(key);
                cacheValue = "";
                TaxonomyResponseVM taxonomyRepositoryVM = null;
                if (String.IsNullOrEmpty(cacheValue))
                {
                    taxonomyRepositoryVM = await taxonomyRepository.GetTaxonomyHierarchyAsync(termStoreViewModel);

                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.PracticeGroupTermSetName && taxonomyRepositoryVM.TermSets != null)
                    {
                        ServiceUtility.SetDataIntoAzureRedisCache <string>(key, taxonomyRepositoryVM.TermSets);
                        return(matterCenterServiceFunctions.ServiceResponse(taxonomyRepositoryVM.TermSets, (int)HttpStatusCode.OK));
                    }
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.ClientTermSetName && taxonomyRepositoryVM.ClientTermSets != null)
                    {
                        ServiceUtility.SetDataIntoAzureRedisCache <ClientTermSets>(key, taxonomyRepositoryVM.ClientTermSets);
                        return(matterCenterServiceFunctions.ServiceResponse(taxonomyRepositoryVM.ClientTermSets, (int)HttpStatusCode.OK));
                    }
                }
                else
                {
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.PracticeGroupTermSetName)
                    {
                        var pgTermSets = JsonConvert.DeserializeObject <string>(cacheValue);
                        if (pgTermSets == null)
                        {
                            genericResponseVM = new GenericResponseVM()
                            {
                                Value       = errorSettings.MessageNoResult,
                                Code        = "404",
                                Description = "No data is present for the given passed input"
                            };
                            return(matterCenterServiceFunctions.ServiceResponse(genericResponseVM, (int)HttpStatusCode.NotFound));
                        }
                        return(matterCenterServiceFunctions.ServiceResponse(pgTermSets, (int)HttpStatusCode.OK));
                    }
                    if (termStoreViewModel.TermStoreDetails.TermSetName == taxonomySettings.ClientTermSetName)
                    {
                        var clientTermSets = JsonConvert.DeserializeObject <ClientTermSets>(cacheValue);
                        if (clientTermSets == null)
                        {
                            genericResponseVM = new GenericResponseVM()
                            {
                                Value       = errorSettings.MessageNoResult,
                                Code        = HttpStatusCode.NotFound.ToString(),
                                Description = "No data is present for the given passed input"
                            };
                            return(matterCenterServiceFunctions.ServiceResponse(genericResponseVM, (int)HttpStatusCode.NotFound));
                        }
                        return(matterCenterServiceFunctions.ServiceResponse(clientTermSets, (int)HttpStatusCode.OK));
                    }
                }
                //If all the above condition fails, return validation error object
                genericResponseVM = new GenericResponseVM()
                {
                    Value       = errorSettings.MessageNoResult,
                    Code        = HttpStatusCode.NotFound.ToString(),
                    Description = "No data is present for the given passed input"
                };
                return(matterCenterServiceFunctions.ServiceResponse(genericResponseVM, (int)HttpStatusCode.BadRequest));
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                var errorResponse = customLogger.GenerateErrorResponse(ex);
                return(matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.InternalServerError));
            }
        }