Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IProductRepository : IDisposable
- {
- IEnumerable<Category> GetCategories();
- IEnumerable<Manufacturer> GetManufacturers();
- IEnumerable<ProductType> GetProductTypes();
- IEnumerable<Availability> GetAvailabilities();
- IEnumerable<ShipMethod> GetShipMethods();
- IEnumerable<Product> GetProducts();
- IEnumerable<Product> GetProductsByName(string productName);
- Product GetProductById(int productId);
- void InsertProduct(Product product);
- void DeleteProduct(int productId);
- void UpdateProduct(Product product);
- void Save();
- }
- public class ProductController : Controller
- {
- private IProductRepository productRepository;
- public ProductController()
- {
- this.productRepository = new ProductRepository(new ProductContext())
- }
- public ProductController(IProductRepository productRepository)
- {
- this.productRepository = productRepository;
- }
- public ActionResult Create()
- {
- Product product = new Product();
- product.Created = DateTime.Now;
- ViewBag.AvailabilityId = new SelectList(productRepository.GetAvailabilities(), "AvailabilityId", "Name");
- ViewBag.CategoryId = new SelectList(productRepository.GetCategories(), "CategoryId", "Name");
- ViewBag.ManufacturerId = new SelectList(productRepository.GetManufacturers(), "ManufacturerId", "Name");
- ViewBag.ProductTypeId = new SelectList(productRepository.GetProductTypes(), "ProductTypeId", "Name");
- ViewBag.ShipMethodId = new SelectList(productRepository.GetShipMethods(), "ShipMethodId", "Name");
- return View(product);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement