Esempio n. 1
0
        private List <TagModel> getTags()
        {
            List <TagModel> tags = new List <TagModel>();

            // the fail case for this method is if there is no selected language
            if (Session["Language"] == null)
            {
                return(tags);
            }

            // check if Session already has a tags list
            if (Session["Tags"] != null)
            {
                tags = (List <TagModel>)Session["Tags"];
                // now, if the list isn't empty return it
                if (tags.Count != 0)
                {
                    return(tags);
                }
            }

            // otherwise, Session does not have a tags list object, so we'll instead start checking the database
            // now load the tags from the database
            List <TagDataModel> dmClassifications = TagProcessor.LoadTags((int)Session["Language"]);

            foreach (TagDataModel tag in dmClassifications)
            {
                tags.Add(new TagModel
                {
                    Id          = tag.Id,
                    Name        = tag.Name,
                    Description = tag.Description
                });
            }

            // now make sure Session has tags list
            if (Session["Tags"] != null)
            {
                Session["Tags"] = tags;
            }
            else
            {
                Session.Add("Tags", tags);
            }

            return(tags);
        }