public SiteModel(Language lang, SiteContext context, string contentId) { Title = "Leo"; _context = context; }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (requestContext.HttpContext.Request.Url != null) { HostName = requestContext.HttpContext.Request.Url.Authority; } if (requestContext.RouteData.Values["lang"] != null && requestContext.RouteData.Values["lang"] as string != "null") { CurrentLangCode = requestContext.RouteData.Values["lang"] as string; using (var context = new SiteContext()) { CurrentLang = context.Languages.First(p => p.Code == CurrentLangCode); } var ci = new CultureInfo(CurrentLangCode); Thread.CurrentThread.CurrentUICulture = ci; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name); } base.Initialize(requestContext); }
private void CreateOrChangeContentLang(SiteContext context, Article instance, Article cache, Language lang) { ArticleLang productLang = null; if (cache != null) { productLang = context.ArticleLangs.FirstOrDefault(p => p.ArticleId == cache.Id && p.LanguageId == lang.Id); } if (productLang == null) { var newPostLang = new ArticleLang { ArticleId = instance.Id, LanguageId = lang.Id, Title = instance.Title, Description = instance.Description }; context.ArticleLangs.Add(newPostLang); } else { productLang.Title = instance.Title; productLang.Description = instance.Description; } context.SaveChanges(); }
public ArticleController(SiteContext context) { _context = context; }
public HomeController(SiteContext context) { _context = context; }
public ProductTextBlockFileController(SiteContext context) { _context = context; }
private void CreateOrChangeContentLang(SiteContext context, ProductTextBlock instance, ProductTextBlock cache, Language lang) { ProductTextBlockLang productLang = null; if (cache != null) { productLang = context.ProductTextBlockLangs.FirstOrDefault(p => p.ProductTextBlockId == cache.Id && p.LanguageId == lang.Id); } if (productLang == null) { var newPostLang = new ProductTextBlockLang { ProductTextBlockId = instance.Id, LanguageId = lang.Id, Text = instance.Text, Title = instance.Title }; context.ProductTextBlockLangs.Add(newPostLang); } else { productLang.Text = instance.Text; productLang.Title = instance.Title; } context.SaveChanges(); }
private void CreateOrChangeContentLang(SiteContext context, ArticleItem instance, ArticleItem cache, Language lang) { ArticleItemLang productLang = null; if (cache != null) { productLang = context.ArticleItemLangs.FirstOrDefault(p => p.ArticleItemId == cache.Id && p.LanguageId == lang.Id); } if (productLang == null) { var newPostLang = new ArticleItemLang { ArticleItemId = instance.Id, LanguageId = lang.Id, Text = instance.Text }; context.ArticleItemLangs.Add(newPostLang); } else { productLang.Text = instance.Text; } context.SaveChanges(); }
public CategoryModel(Language lang, SiteContext context, string categoryName = null, string subcategoryName = null, string productName=null, int? articleId=null, bool intro = false) : base(lang, context, categoryName) { Categories = _context.Categories.ToList(); var currentCategoryName = subcategoryName ?? categoryName; Category = categoryName!=null ? Categories.FirstOrDefault(c => c.Name == currentCategoryName) : Categories.FirstOrDefault(c => c.Parent==null); int? currentCategoryId = null; var cc= Categories.FirstOrDefault(c => c.Name == categoryName); if (cc != null) { currentCategoryId = cc.Id; } if (subcategoryName == null) { SpecialContents = _context.SpecialContents.Where(sc => (sc.IsFirstCategory && currentCategoryId == 2) || (sc.IsSecondCategory && currentCategoryId == 1)).ToList().OrderBy(sc => Guid.NewGuid()); foreach (var specialContent in SpecialContents) { specialContent.CurrentLang = lang.Id; } var specialContentJsonModel = new SpecialContentJsonModel() { imagePath = "/content/images/", items = new List<item>() }; foreach (var content in SpecialContents) { specialContentJsonModel.items.Add(new item { contentImageSource = content.ContentImageSource, pageImageSource = content.PageImageSource, title = content.Title, text = content.Text }); } SpecialContentJson = "settings.specialContent = " + JsonConvert.SerializeObject(specialContentJsonModel); } var nextCategory = Categories.FirstOrDefault(c => c.Parent == null && c.Name != categoryName); if (nextCategory != null) { string[] titlesRu = {"","Я инвестирую / строю", "Я продаю / создаю"}; string[] titlesEn = {"", "Invest / Build", "Sell / Create"}; nextCategory.CurrentLang = lang.Id; NextCategoryName = nextCategory.Name; NextCategoryTitle = lang.Id == 1 ? titlesRu[nextCategory.Id] : titlesEn[nextCategory.Id]; } if (Category != null) { if (Category.IsNewsCategory||Category.HasContentPages) { if (_context.ProductImages.Any()) { var productImages = _context.ProductImages.ToList(); var randomInage = productImages.OrderBy(x => Guid.NewGuid()).Take(1).First().ImageSource; RandomImageFromProductImages = "settings.randomImageFromProductImages = '" + randomInage + "'"; RandomImageSource = randomInage; } } foreach (var article in Category.Articles) { article.CurrentLang = lang.Id; foreach (var articleItem in article.ArticleItems) { articleItem.CurrentLang = lang.Id; } } if (articleId.HasValue) { Article = Category.Articles.First(a => a.Id == articleId); Article.CurrentLang = lang.Id; } Products = Category.Products.ToList(); foreach (var product in Products) { product.CurrentLang = lang.Id; } if (productName != null) { Product = Category.Products.First(p => p.Name == productName); foreach (var block in Product.ProductTextBlocks) { block.CurrentLang = lang.Id; } } else if (subcategoryName != null && Products.Any()) { Product = Category.Products.OrderBy(p=>p.SortOrder).First(); } } foreach (var category in Categories) { category.CurrentLang = lang.Id; } SiteMenu = CreateSiteMenu(Categories); if (categoryName != null) { var menu = SiteMenu.First(m => m.ContentName == categoryName); SiteMenu = menu.Children.ToList(); } foreach (var item in SiteMenu.Where(item => item.ContentName == categoryName || item.ContentName == subcategoryName)) { if (Article != null) item.Selected = true; else item.Current = true; } if (intro) { Categories = Categories.Where(c => c.Parent == null); return; } //var currentCategory = Categories.First(c => c.Name == Category.Name); //Categories = currentCategory.Children; Categories = Category.Children; if (Product != null && Product.ProductImages.Any()&&!Product.IsContentPage) { var specialContentJsonModel = new SpecialContentJsonModel() { imagePath = "/content/images/", items = new List<item>() }; foreach (var img in Product.ProductImages) { specialContentJsonModel.items.Add(new item { contentImageSource = null, pageImageSource = img.ImageSource }); } SpecialContentJson = "settings.specialContent = " + JsonConvert.SerializeObject(specialContentJsonModel); } }
private void CreateOrChangeContentLang(SiteContext context, Category instance, Category cache, Language lang) { CategoryLang categoryLang = null; if (cache != null) { categoryLang = context.CategoryLangs.FirstOrDefault(p => p.CategoryId == cache.Id && p.LanguageId == lang.Id); } if (categoryLang == null) { var newPostLang = new CategoryLang { CategoryId = instance.Id, LanguageId = lang.Id, Title = instance.Title, Text = instance.Text }; context.CategoryLangs.Add(newPostLang); } else { categoryLang.Title = instance.Title; categoryLang.Text = instance.Text; } context.SaveChanges(); }
public CategoryController(SiteContext context) { _context = context; }
public ProductController(SiteContext context) { _context = context; }
public SpecialContentController(SiteContext context) { _context = context; }
private void CreateOrChangeContentLang(SiteContext context, SpecialContent instance, SpecialContent cache, Language lang) { SpecialContentLang specialContentLang = null; if (cache != null) { specialContentLang = context.SpecialContentLangs.FirstOrDefault(p => p.SpecialContentId == cache.Id && p.LanguageId == lang.Id); } if (specialContentLang == null) { var newPostLang = new SpecialContentLang { SpecialContentId = instance.Id, LanguageId = lang.Id, Title = instance.Title, Text = instance.Text }; context.SpecialContentLangs.Add(newPostLang); } else { specialContentLang.Title = instance.Title; specialContentLang.Text = instance.Text; } context.SaveChanges(); }