Пример #1
0
        public IEnumerable <string> GetFormBlogTags(int BlogID)
        {
            var           tag          = allFormBlogsTags.Where(x => x.BlogID == BlogID).Select(x => x.TagID).ToList();
            var           _tagContexts = new TagsContexts();
            List <string> lst          = new List <string>();

            foreach (var t in tag)
            {
                lst.Add(_tagContexts.GetTags().Where(x => x.TagID == Convert.ToInt32(t)).Select(x => x.TagNameTxt).FirstOrDefault());
            }
            return(lst);
        }
Пример #2
0
        public void AddBlogs(BlogsModel _BlogsModel)
        {
            _BlogsModel.BlogID = (int)(from S in BlogsData.Descendants("Blog") orderby(short) S.Element("BlogID") descending select(short) S.Element("BlogID")).FirstOrDefault() + 1;
            BlogsData.Root.Add(new XElement("Blog", new XElement("BlogID", _BlogsModel.BlogID),
                                            new XElement("TitleTxt", !string.IsNullOrEmpty(_BlogsModel.TitleTxt) ? _BlogsModel.TitleTxt : ""),
                                            new XElement("AuthorNameTxt", !string.IsNullOrEmpty(_BlogsModel.AuthorNameID) ? _BlogsModel.AuthorNameID : ""),
                                            new XElement("BlogDescription", !string.IsNullOrEmpty(_BlogsModel.BlogDescription) ? _BlogsModel.BlogDescription : ""),
                                            new XElement("ImagePathTxt", !string.IsNullOrEmpty(_BlogsModel.ImagePathTxt) ? _BlogsModel.ImagePathTxt : ""),
                                            new XElement("PostedDate", !string.IsNullOrEmpty(Convert.ToString(_BlogsModel.PostedDate)) ? _BlogsModel.PostedDate : System.DateTime.Today),
                                            new XElement("SlagTxt", !string.IsNullOrEmpty(_BlogsModel.SlagTxt) ? _BlogsModel.SlagTxt : ""),
                                            new XElement("IsActiveInd", _BlogsModel.IsActiveInd),
                                            new XElement("MetaTitleTxt", !string.IsNullOrEmpty(_BlogsModel.MetaTitleTxt) ? _BlogsModel.MetaTitleTxt : ""),
                                            new XElement("MetaKeywordTxt", !string.IsNullOrEmpty(_BlogsModel.MetaKeywordTxt) ? _BlogsModel.MetaKeywordTxt : ""),
                                            new XElement("MetaDescriptionTxt", !string.IsNullOrEmpty(_BlogsModel.MetaDescriptionTxt) ? _BlogsModel.MetaDescriptionTxt : ""),
                                            new XElement("IsCommentEnabledInd", _BlogsModel.IsCommentEnabledInd),
                                            new XElement("SocialMediaTxt", !string.IsNullOrEmpty(_BlogsModel.SocialMediaTxt) ? _BlogsModel.SocialMediaTxt : ""),
                                            new XElement("CategoryID", !string.IsNullOrEmpty(_BlogsModel.strCategoryid) ? Convert.ToInt32(_BlogsModel.strCategoryid) : 0),
                                            new XElement("AbstractTxt", !string.IsNullOrEmpty(_BlogsModel.AbstractTxt) ? _BlogsModel.AbstractTxt : "")

                                            ));

            BlogsData.Save(HttpContext.Current.Server.MapPath("~/App_Data/blogs.xml"));
            #region Tag section

            FormBlogTags _FormBlogTags  = new FormBlogTags();
            TagsModel    _TagsModel     = new TagsModel();
            var          _BlogsContexts = new BlogsContexts();
            _FormBlogTags.BlogID = _BlogsModel.BlogID;

            if (_BlogsModel.SelectedTagsID != null)
            {
                foreach (var item in _BlogsModel.SelectedTagsID)
                {
                    foreach (var i in item.Split(','))
                    {
                        var  _TagContexts = new TagsContexts();
                        var  id           = 0;
                        var  tagName      = string.Empty;
                        int  n;
                        var  flag      = false;
                        bool isNumeric = int.TryParse(i, out n);
                        if (isNumeric)
                        {
                            var formBlogtag_count = _BlogsContexts.GetAllFormBlogTags().Where(x => x.BlogID == _BlogsModel.BlogID && x.TagID == i.ToString()).Count();
                            if (formBlogtag_count == 0)
                            {
                                id      = _TagContexts.GetTags().Where(x => x.TagID == Convert.ToInt32(i)).Select(x => x.TagID).FirstOrDefault();
                                tagName = _TagContexts.GetTags().Where(x => x.TagID == Convert.ToInt32(i)).Select(x => x.TagNameTxt).FirstOrDefault();
                                flag    = true;
                            }
                        }
                        else
                        {
                            id      = 0;
                            tagName = i;
                        }

                        if (id == 0)
                        {
                            _TagsModel.TagNameTxt = tagName;
                            var IsTagName_exist = _TagContexts.GetTags().Where(x => x.TagNameTxt.ToLower().Trim() == tagName.ToLower().Trim()).Count();
                            if (IsTagName_exist == 0)
                            {
                                _TagContexts.AddTags(_TagsModel);// Add tags in tag context
                                id   = _TagContexts.GetTags().Select(x => x.TagID).Count() > 0 ? _TagContexts.GetTags().Select(x => x.TagID).Max() + 1 : 1;
                                flag = true;
                            }
                            else
                            {
                                var tagID_exist       = _TagContexts.GetTags().Where(x => x.TagNameTxt.ToLower().Trim() == tagName.ToLower().Trim()).Select(x => x.TagID).FirstOrDefault();
                                var formBlogtag_count = _BlogsContexts.GetAllFormBlogTags().Where(x => x.BlogID == _BlogsModel.BlogID && x.TagID == tagID_exist.ToString()).Count();
                                if (formBlogtag_count == 0)
                                {
                                    id   = tagID_exist;
                                    flag = true;
                                }
                            }
                        }

                        if (flag == true)
                        {
                            _FormBlogTags.BlogTagID = (int)(from S in BlogsTagsData.Descendants("FormBlogTag") orderby(short) S.Element("BlogTagID") descending select(short) S.Element("BlogTagID")).FirstOrDefault() + 1;
                            BlogsTagsData.Root.Add(new XElement("FormBlogTag", new XElement("BlogTagID", _FormBlogTags.BlogTagID),
                                                                new XElement("BlogID", _FormBlogTags.BlogID),
                                                                new XElement("TagID", id)));
                            BlogsTagsData.Save(HttpContext.Current.Server.MapPath("~/App_Data/formblogstag.xml"));
                        }
                    }
                }
            }
            #endregion

            #region social media
            FormBlogSocialMedia _FormBlogSM = new FormBlogSocialMedia();
            _FormBlogSM.BlogID = _BlogsModel.BlogID;
            if (_BlogsModel.SelectedSocialMedia != null)
            {
                foreach (var item in _BlogsModel.SelectedSocialMedia)
                {
                    _FormBlogSM.BlogSocialMediaID = (int)(from S in BlogsSocialMediaData.Descendants("FormBlogSocialMedia") orderby(short) S.Element("BlogSocialMediaID") descending select(short) S.Element("BlogSocialMediaID")).FirstOrDefault() + 1;
                    BlogsSocialMediaData.Root.Add(new XElement("FormBlogSocialMedia", new XElement("BlogSocialMediaID", _FormBlogSM.BlogSocialMediaID),
                                                               new XElement("BlogID", _FormBlogSM.BlogID),
                                                               new XElement("SocialMediaID", item)));
                }
                BlogsSocialMediaData.Save(HttpContext.Current.Server.MapPath("~/App_Data/formblogssocialmedia.xml"));
            }
            #endregion
        }