I have my Product class, which is pretty straight forward, Then I want to use an Interface to send a List of Product objects over the to Controller.
I think Im good to go with my Product class and IProduct interface ?
my problems: In MYcontext class, I am trying to make the list, but IM not really sure how to proceed. and MyRepository class should send the List to the Controller eventually.
My purpose of using the interface is just really for practice.. and I will do some Testing later too.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Uppgift_1.Models
{
public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public double PriceBuy { get; set; }
public double PriceSell { get; set; }
public double Moms { get; set; }
public Product()
{
}
public Product(int productId, string productName, double priceBuy, double priceSell, double moms)
{
ProductId = productId;
ProductName = productName;
PriceBuy = priceBuy;
PriceSell = priceSell;
Moms = moms;
}
// TODO: add calculation method
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Uppgift_1.Models
{
public interface IProduct
{
IQueryable<Product> Products { get; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Uppgift_1.Models
{
public class MYcontext : Product
{
IQueryable<Product> Products = new List<Product>();
Product p1 = new Product(21, "RollerSkates", 82.5, 164, 1.25);
Product p2 = new Product(22, "Fridge", 88, 844, 1.25);
Product p3 = new Product(23, "TV", 182.5, 364, 1.25);
Product p4 = new Product(24, "Boat", 325, 64, 1.25);
Product p5 = new Product(25, "Car", 22.5, 74, 1.25);
Product p6 = new Product(26, "Magasine", 84.3, 44, 1.25);
Product p7 = new Product(27, "Garage", 182.7, 843, 1.25);
Product p8 = new Product(28, "House", 182.8, 542, 1.25);
Product p9 = new Product(29, "Beach", 814.9, 62, 1.25);
Product p10 = new Product(30, "Ball", 69.3, 16, 1.25);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Uppgift_1.Models
{
public class MyRepository : IProduct
{
public IQueryable<Product> Products
{
get { return MYcontext.pList; }
}
}
}