Example #1
0
        public IList <Document> FetchDocuments(string countryCode)
        {
            IList <Document> docList = null;

            try
            {
                Dictionary <string, IList <Document> > countryToDocMap = SPObjectCache.Get(cacheKey) as Dictionary <string, IList <Document> >;

                if (countryToDocMap == null)
                {
                    countryToDocMap = new Dictionary <string, IList <Document> >();
                }

                if (countryToDocMap.ContainsKey(countryCode))
                {
                    docList = countryToDocMap[countryCode];
                }

                if (docList == null)
                {
                    SharePointHelper spHelper = new SharePointHelper();
                    docList = spHelper.GetCountryDocuments(countryCode);

                    countryToDocMap[countryCode] = docList;
                    SPObjectCache.Add(cacheKey, countryToDocMap);
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogError(string.Format(@"Error fetching document for {0}", countryCode), ex);
            }

            return(docList);
        }
Example #2
0
        public IList <Models.Document> FetchDocuments()
        {
            List <Document> docList = SPObjectCache.Get(cacheKey) as List <Document>;

            if (docList == null)
            {
                SharePointHelper spHelper = new SharePointHelper();
                docList = spHelper.GetDocumnentsByMenu(Constants.NewBusinessFiles);

                SPObjectCache.Add(cacheKey, docList);
            }

            return(docList);
        }
        public IEnumerable <Models.Country> FetchAllCountries()
        {
            List <Country> countryList = SPObjectCache.Get(cacheKey) as List <Country>;

            //return from cache if record exists else fetch from sharepoint.
            if (countryList == null)
            {
                countryList = new List <Country>();
                ClientContext context           = new ClientContext(ConfigHelper.GetConfigValue(Constants.ClientSharePointSiteConfigKey));
                List          announcementsList = context.Web.Lists.GetByTitle(Constants.CountryList);

                // Get all the items from the Countries list
                CamlQuery query     = CamlQuery.CreateAllItemsQuery();
                string    queryText = @"<View ><Query>
                        <Where>
                            <Eq>
                                <FieldRef Name='IsActive'/>
                                <Value Type='Integer'>1</Value>
                            </Eq>
                        </Where>
                        <OrderBy>
                            <FieldRef Name='Country'/>
                        </OrderBy>
                        </Query>
                        </View>";
                query.ViewXml = queryText;
                ListItemCollection items = announcementsList.GetItems(query);

                context.Load(items);
                context.ExecuteQuery();
                foreach (ListItem listItem in items)
                {
                    if (listItem[Constants.CountryColoumnDisplayName] != null)
                    {
                        Country country = new Country();
                        country.Name        = listItem[Constants.CountryColoumnDisplayName].ToString();
                        country.Aplha3_Code = listItem[Constants.AlphaCodeColoumnDisplayName].ToString();
                        countryList.Add(country);
                    }
                }

                SPObjectCache.Add(cacheKey, countryList);
            }

            return(countryList);
        }