public ActionResult Edit(long id) { var result = new EditProductPageViewModel(); var groups = _shopService.GetGroups().OrderBy(q => q.Name); var manufactures = _shopService.GetManufacturers().OrderBy(q => q.Name); if (id == 0) { var firstGroup = groups.First(q => q.Category.Any()); var categoriesByFirstGroup = _shopService.GetCategories(firstGroup.ID).ToList(); var firstCategoriesByFirstGroup = categoriesByFirstGroup.First(); result.Groups = new SelectList(groups.OrderBy(q => q.Name), "ID", "Name", firstGroup); result.Manufacturers = new SelectList(manufactures, "ID", "Name"); result.Categories = new SelectList(categoriesByFirstGroup.OrderBy(q => q.Name), "ID", "Name", firstCategoriesByFirstGroup); result.Sections = _productService.GetProductParameters(firstCategoriesByFirstGroup.ID).ToList(); return(View(result)); } var product = _productService.GetProduct(id); if (product == null) { return(RedirectToAction("Index")); } result.Product = product; result.Groups = new SelectList(groups.OrderBy(q => q.Name), "ID", "Name", product.Category.GroupID); result.Manufacturers = new SelectList(manufactures, "ID", "Name", product.ManufacturerID); result.Categories = new SelectList( _shopService.GetCategories(product.Category.GroupID).OrderBy(q => q.Name), "ID", "Name", product.CategoryID); result.Sections = _productService.GetProductParameters(product.CategoryID, product.ID).ToList(); //result.Photos = // product.ProductImage.Select( // q => // String.Format( // "<img src='/Images/Catalog/Product/{0}' class='file-preview-image' alt='The Moon' title='The Moon'>", // q.ImageName)).ToArray(); ViewBag.UploadedImages = (product.ProductImage != null) ? from image in product.ProductImage select "/Images/Catalog/Product/" + image.ImageName + ";" + image.IsTitular.ToString().ToLower() : null; return(View(result)); }
public ActionResult Index() { return(View(_shopService.GetManufacturers())); }
public ActionResult BaseProducts(ProductForShopViewModel model, FilterParams filter = null) { if (filter == null) { filter = new FilterParams(); } var shop = _shopService.GetShop(filter.Id); //Verification access if (shop == null || (WebSecurity.CurrentUserId != shop.UserID && !User.IsInRole("Administrator") && !User.IsInRole("Moderator"))) { return(HttpNotFound()); } if (WebSecurity.CurrentUserId == shop.UserID && shop.IsActive == false && !User.IsInRole("Administrator") && !User.IsInRole("Moderator")) { TempData["error"] = "Магазин еще не активирован!"; return(Redirect("/")); } var groups = _shopService.GetGroups().ToList(); var selectedGroup = filter.CategoryId == 0 ? groups.First() : groups.First(q => q.ID == filter.CategoryId); var categories = _shopService.GetCategories(selectedGroup.ID); var selectedCategory = filter.SecondCategoryId == 0 ? categories.First() : categories.First(q => q.ID == filter.SecondCategoryId); var emptyManufacturer = new Manufacturer { ID = 0, Name = "Все" }; var manufacturers = new List <Manufacturer> { emptyManufacturer }; manufacturers.AddRange(_shopService.GetManufacturers(selectedCategory.ID)); Manufacturer selectedManufacturer = emptyManufacturer; if (manufacturers.Count > 1) { selectedManufacturer = filter.ThirdCategoryId == 0 ? manufacturers.First() : manufacturers.First(q => q.ID == filter.ThirdCategoryId); } var shopProducts = _shopService.GetShopProducts(shop.ID); model.Filter = filter; model.Groups = new SelectList(groups, "ID", "Name", selectedGroup); model.Categories = new SelectList(categories, "ID", "Name", selectedCategory); model.Manufacturers = new SelectList(manufacturers, "ID", "Name", selectedManufacturer); model.CurrentCategoryID = selectedCategory.ID; model.Shop = shop; model.MonthlyFee = 0; model.ShopProducts = shopProducts; model.Products = selectedCategory.Product.Where(q => selectedManufacturer.ID == 0 || selectedManufacturer.ID == q.ManufacturerID).ToPagedList(filter.Page, ProjectConfiguration.Get.ProductsOnPageInBasePage); var categories2 = shop.ShopProduct.Select(q => q.Product.Category).Distinct().ToList(); if (categories2.Any()) { model.MonthlyFee = categories2.Sum(x => x.Price); } return(View(model)); }