public ActionResult Create(int? parentId, FormCollection collection) { using (var context = new SiteContainer()) { var category = new Category(); TryUpdateModel(category, new[] { "Name", "Title", "Description", "BottomDescription", "BottomDescriptionTitle", "ShowOnMainPage", "PageTitle" }); if (parentId.HasValue) { var parent = context.Category.First(c => c.Id == parentId); parent.Children.Add(category); } else { context.AddToCategory(category); } context.SaveChanges(); return RedirectToAction("Gallery", "Home", new { area = "", id = category.Name }); } }
public ActionResult Create(FormCollection collection) { using (var context = new SiteContainer()) { var category = new Category(); TryUpdateModel(category, new[] { "Name", "Title", "Description", "BottomDescription", "BottomDescriptionTitle" }); context.AddToCategory(category); context.SaveChanges(); return RedirectToAction("Gallery", "Home", new { area = "", id = category.Name }); } }
public SiteModel(SiteContainer context, string contentName, bool showArticles = false, bool showOurWorks = false) { Title = "Килими"; if (contentName == null) { Content = context.Content.First(c => c.MainPage); } else { Content = context.Content.FirstOrDefault(c => c.Name == contentName); if (Content == null) { throw new HttpNotFoundException(); } } if (!string.IsNullOrEmpty(Content.Title)) Title += " » " + Content.Title; PageTitle = Content.PageTitle; SeoDescription = Content.SeoDescription; SeoKeywords = Content.SeoKeywords; if (Content.MainPage) { IsHomePage = true; } if (showArticles) { Articles = context.Article.OrderByDescending(a => a.Date).ToList(); } if (showOurWorks) { OurWorks = context.Category.Include("Products").First(c => c.Name == "ourworks"); } if (IsHomePage) { MainPageCategories = new List<Category>(); var categories = new List<CategoryProductPresentation>(); var conn = DbHelper.Connection; using (conn.StateManager()) { var query = @"select parent.Id as CategoryId, parent.Title as CategoryTitle, parent.Name as CategoryName, t2.title as ProductTitle, t2.DiscountText as DiscountText, t2.Id as ProductId, t2.ImageSource as ImageSource from Category t1 join Product t2 on t2.CategoryId=t1.Id join Category parent on parent.Id=t1.CategoryId";// where parent.ShowOnMainPage=1"; conn.ReadToCollection(categories, r => CategoryProductPresentation.Init(new CategoryProductPresentation(), r), query); int oldCategoryId = 0; int newCategoryId; Category category = null; foreach (var presentation in categories.OrderBy(c => c.CategoryId)) { newCategoryId = presentation.CategoryId; if (oldCategoryId != newCategoryId) { if (category != null) MainPageCategories.Add(category); category = new Category { Id = presentation.CategoryId, Title = presentation.CategoryTitle, Name = presentation.CategoryName }; } var p = new Product { Id = presentation.ProductId, Title = presentation.ProductTitle, ImageSource = presentation.ProductImageSource, DiscountText = presentation.ProductDiscountText }; category.Products.Add(p); oldCategoryId = newCategoryId; } if (category != null) MainPageCategories.Add(category); } //var allCategories = context.Category.Include("Children").Include("Products").Where(c => c.ShowOnMainPage).ToList(); //foreach (var category in allCategories.Where(c => c.Parent == null && !c.SpecialCategory)) //{ // var cat = new Category { Name = category.Name, Title = category.Title, Id = category.Id }; // foreach (var child in category.Children) // { // foreach (var product in child.Products) // { // var p = new Product { Id = product.Id, ImageSource = product.ImageSource, Title = product.Title, Description = product.Description, Discount = product.Discount, DiscountText = product.DiscountText }; // cat.Products.Add(p); // } // } // MainPageCategories.Add(cat); //} Banners = context.Banner.ToList(); } }
/// <summary> /// Create a new Category object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="bottomDescriptionTitle">Initial value of the BottomDescriptionTitle property.</param> /// <param name="specialCategory">Initial value of the SpecialCategory property.</param> /// <param name="name">Initial value of the Name property.</param> public static Category CreateCategory(global::System.Int32 id, global::System.String title, global::System.String bottomDescriptionTitle, global::System.Boolean specialCategory, global::System.String name) { Category category = new Category(); category.Id = id; category.Title = title; category.BottomDescriptionTitle = bottomDescriptionTitle; category.SpecialCategory = specialCategory; category.Name = name; return category; }
/// <summary> /// Deprecated Method for adding a new object to the Category EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCategory(Category category) { base.AddObject("Category", category); }