public void DeleteCategory(ProductCategory category) { }
public void SaveCategory(ProductCategory category) { }
public ActionResult ProductCreate(ProductCreateVM pcVM, HttpPostedFileBase file ) { if (ModelState.IsValid) { // product image file upload //if (file.ContentLength > 0) //{ // string fileName = "Product-" + peVM.ProductVariant.Image.ImageID.ToString() + "-mid"; // string path = Path.Combine(Server.MapPath("~/Contents/Site-Image"), fileName); // file.SaveAs(path); //} // if ProductType (DropDownList) = Product , exist choose so and create ProductVariant only ! , else if not create new Product & ProductVariant // TODO : many to many relationship for dbcontext - use Fluent API ? //Product newProduct = productRepo.Products // .Include("Variants") // .Include("Categories") // .FirstOrDefault(p => p.ProductID == 1); // newProduct.Variants.Add(pcVM.ProductVariant); // Create new dummy product for now , ProductID = auto generated by DB pcVM.ProductVariant.Product.ProductGUID = "N/A"; pcVM.ProductVariant.Product.Name = "N/A"; pcVM.ProductVariant.Product.Categories = new List<ProductCategory>(); // Save category info to product // if category was chosen from DDL if (!String.IsNullOrEmpty(pcVM.SelectedCategoryID)) { pcVM.ProductVariant.Product.Categories = new List<ProductCategory>(); int selectedCatID = Int32.Parse(pcVM.SelectedCategoryID); ProductCategory category = categoryRepo.Categories .Where(c => c.CategoryID == selectedCatID) .FirstOrDefault(); ProductCategory newCategory = new ProductCategory { CategoryID = category.CategoryID , CategoryGUID = category.CategoryGUID ?? "", Description = category.Description ?? "" , Name = category.Name ?? "" , Products = category.Products }; //pcVM.ProductVariant.Product.Categories.Add(category); categoryRepo.SaveCategory(category); } // implement create new category later //else //{ // // New category added from "Create Category Field" - for now just create new instand of obj with ID = 0 // ProductCategory category = new ProductCategory { CategoryID = 0 }; // pcVM.ProductVariant.Product.Categories.Add(category); //} // productRepo.SaveProduct(newProduct); // Try to make below into one single method and DB access // Create new SKU productRepo.SaveProductVariant(pcVM.ProductVariant); // Save Button if (!String.IsNullOrEmpty(pcVM.SelectedButtonID)) { int selectedButtonID = Int32.Parse(pcVM.SelectedButtonID); // == null ? 0 : Int32.Parse(peVM.SelectedButtonID); Button modifiedButton = buttonRepo.Buttons .Where(b => b.ButtonID == selectedButtonID) .FirstOrDefault(); modifiedButton.VariantID = pcVM.ProductVariant.VariantID; //modifiedButton.Variant = pcVM.ProductVariant; buttonRepo.SaveButton(modifiedButton); } return View("TaskCompleted"); } return View(pcVM); }