Exemplo n.º 1
0
 public int SaveCategory(BlogCategoryModelBinding Model, string UserID)
 {
     using (var _c = db)
     {
         Can(Model.SiteID, UserID, _c);
         var _C = new BlogCategory
         {
             SiteID = Model.SiteID
         };
         if (Model.BlogCategoryID == 0)
         {
             _C.BlogCategoryCultures = new List<BlogCategoryCulture>();
         }
         else
         {
             _C = _c.BlogCategories.Where(m => m.BlogCategoryID == Model.BlogCategoryID)
                 .FirstOrDefault();
         }
         foreach (var item in Model.CategoryCultures)
         {
             if (string.IsNullOrEmpty(item.FriendlyUrl))
             {
                 item.FriendlyUrl = item.BlogCategoryName.CleanUrl();
             }
             if (Model.BlogCategoryID == 0)
             {
                 _C.BlogCategoryCultures.Add(new BlogCategoryCulture
                 {
                     BlogCategoryName = item.BlogCategoryName,
                     CultureID = item.CultureID,
                     FriendlyUrl = item.FriendlyUrl
                 });
                 _c.BlogCategories.Add(_C);
             }
             else
             {
                 var _BCC = _c.BlogCategoryCultures
                     .Where(m => m.BlogCategoryID == Model.BlogCategoryID
                         && m.CultureID == item.CultureID).FirstOrDefault();
                 if (_BCC != null)
                 {
                     _BCC.BlogCategoryName = item.BlogCategoryName;
                     _BCC.FriendlyUrl = item.FriendlyUrl;
                 }
                 else
                 {
                     _BCC = new BlogCategoryCulture
                     {
                         BlogCategoryID = Model.BlogCategoryID,
                         BlogCategoryName = item.BlogCategoryName,
                         CultureID = item.CultureID,
                         FriendlyUrl = item.FriendlyUrl
                     };
                     _C.BlogCategoryCultures.Add(_BCC);
                 }
             }
         }
         _c.SaveChanges();
         return _C.BlogCategoryID;
     }
 }
Exemplo n.º 2
0
        public void BlogCategoryGetOneLangTest()
        {
            SettingUp();
            var _Categories = new List<BlogCategoryCultureBase>();
            _Categories.Add(new BlogCategoryCultureBase
            {
                BlogCategoryName = "c2-es",
                CultureID = _Cultures[0].CultureID,
            });
            var _Category1 = new BlogCategoryModelBinding
            {
                SiteID = _SiteID,
                CategoryCultures = _Categories
            };
            _Category1.BlogCategoryID = new BlogBLL().SaveCategory(_Category1, _CustomerUser.Id);

            var _C = new BlogBLL().GetCategories(_SiteID, _Cultures[0].CultureID);
            Assert.IsTrue(_C.Count == 2);
            Assert.IsNotNull(_C[0].CategoryCultures);
            Assert.IsNotNull(_C[1].CategoryCultures);
            _C = new BlogBLL().GetCategories(_SiteID, _Cultures[1].CultureID);
            Assert.IsNotNull(_C[0].CategoryCultures);
            Assert.IsTrue(_C.Count == 2);
        }
Exemplo n.º 3
0
        private void SettingUp()
        {
            //CREATING CATEGORIES
            var _Categories = new List<BlogCategoryCultureBase>();
            _Categories.Add(new BlogCategoryCultureBase
            {
                BlogCategoryName = "c1-es",
                CultureID = _Cultures[0].CultureID,
            });
            _Categories.Add(new BlogCategoryCultureBase
            {
                BlogCategoryName = "c1-en",
                CultureID = _Cultures[1].CultureID
            });
            _Category = new BlogCategoryModelBinding
            {
                SiteID = _SiteID,
                CategoryCultures = _Categories
            };
            _Category.BlogCategoryID = new BlogBLL().SaveCategory(_Category, _CustomerUser.Id);

            //CREATING TAGS
            var _Tags = new List<BlogTagModelBinding>();
            _Tags.Add(new BlogTagModelBinding
            {
                BlogTagName = "t1"
            });
            _Tags.Add(new BlogTagModelBinding
            {
                BlogTagName = "t2"
            });
            //CREATING POSTS
            _BlogPost = new BlogPostModelBinding
            {
                SiteID = _SiteID,
                CultureID = _Cultures[0].CultureID,
                Title = "b1",
                Tags = _Tags,
                Published = true
            };
            _BlogPost.BlogPostID = new BlogBLL().Save(_BlogPost, _CustomerUser.Id);
            Assert.IsTrue(_BlogPost.BlogPostID != 0);

            _BlogPost2 = new BlogPostModelBinding
            {
                SiteID = _SiteID,
                CultureID = _Cultures[0].CultureID,
                Title = "b2",
                Published = true
            };
            _BlogPost2.BlogPostID = new BlogBLL().Save(_BlogPost2, _CustomerUser.Id);
            Assert.IsTrue(_BlogPost2.BlogPostID != 0);

            _BlogPost3 = new BlogPostModelBinding
            {
                SiteID = _SiteID,
                CultureID = _Cultures[1].CultureID,
                Title = "b3",
                Published = true,
                FriendlyUrl="b3"
            };
            _BlogPost3.BlogPostID = new BlogBLL().Save(_BlogPost3, _CustomerUser.Id);
            Assert.IsTrue(_BlogPost3.BlogPostID != 0);
        }
Exemplo n.º 4
0
        public void BlogCategoryUpdatingNewLangTest()
        {
            SettingUp();
            var _Categories = new List<BlogCategoryCultureBase>();
            _Categories.Add(new BlogCategoryCultureBase
            {
                BlogCategoryName = "c2-es",
                CultureID = _Cultures[0].CultureID,
            });
            var _Category1 = new BlogCategoryModelBinding
            {
                SiteID = _SiteID,
                CategoryCultures = _Categories
            };
            _Category1.BlogCategoryID = new BlogBLL().SaveCategory(_Category1, _CustomerUser.Id);

            var _Categories2 = new List<BlogCategoryCultureBase>();
            _Categories2.Add(new BlogCategoryCultureBase
            {
                BlogCategoryName = "c2-en",
                CultureID = _Cultures[1].CultureID,
            });
            var _Category2 = new BlogCategoryModelBinding
            {
                SiteID = _SiteID,
                CategoryCultures = _Categories2,
                BlogCategoryID = _Category1.BlogCategoryID
            };
            _Category2.BlogCategoryID = new BlogBLL().SaveCategory(_Category2, _CustomerUser.Id);

            var _C = new BlogBLL().GetCategories(_SiteID, _Cultures[0].CultureID);
            Assert.AreEqual(_Category1.CategoryCultures[0].BlogCategoryName, _C[1].BlogCategoryName);
            var _C2 = new BlogBLL().GetCategories(_SiteID, _Cultures[1].CultureID);
            Assert.AreEqual(_Category2.CategoryCultures[0].BlogCategoryName, _C2[1].BlogCategoryName);
        }
Exemplo n.º 5
0
 public IHttpActionResult PostSaveCategory(BlogCategoryModelBinding Model)
 {
     _BlogService.SaveCategory(Model, User.Identity.GetUserId());
     return Ok();
 }