Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. public interface IProductRepository : IDisposable
  2. {
  3. IEnumerable<Category> GetCategories();
  4. IEnumerable<Manufacturer> GetManufacturers();
  5. IEnumerable<ProductType> GetProductTypes();
  6. IEnumerable<Availability> GetAvailabilities();
  7. IEnumerable<ShipMethod> GetShipMethods();
  8. IEnumerable<Product> GetProducts();
  9. IEnumerable<Product> GetProductsByName(string productName);
  10. Product GetProductById(int productId);
  11. void InsertProduct(Product product);
  12. void DeleteProduct(int productId);
  13. void UpdateProduct(Product product);
  14. void Save();
  15. }
  16.  
  17. public class ProductController : Controller
  18. {
  19. private IProductRepository productRepository;
  20.  
  21. public ProductController()
  22. {
  23. this.productRepository = new ProductRepository(new ProductContext())
  24. }
  25.  
  26. public ProductController(IProductRepository productRepository)
  27. {
  28. this.productRepository = productRepository;
  29. }
  30.  
  31. public ActionResult Create()
  32. {
  33. Product product = new Product();
  34. product.Created = DateTime.Now;
  35. ViewBag.AvailabilityId = new SelectList(productRepository.GetAvailabilities(), "AvailabilityId", "Name");
  36. ViewBag.CategoryId = new SelectList(productRepository.GetCategories(), "CategoryId", "Name");
  37. ViewBag.ManufacturerId = new SelectList(productRepository.GetManufacturers(), "ManufacturerId", "Name");
  38. ViewBag.ProductTypeId = new SelectList(productRepository.GetProductTypes(), "ProductTypeId", "Name");
  39. ViewBag.ShipMethodId = new SelectList(productRepository.GetShipMethods(), "ShipMethodId", "Name");
  40. return View(product);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement