I have a product table with the following fields as shown , i am diplaying the product specification on a Product detail page via Store controller .
Now i want to manage the stock quantity like if customer try to add 60 cases of coke ( any product) into the basket and i have only 40 cases then it will show either bulk purchase or it exceeds the total quantity in stock .
Secondly if any item quantity is zero in database then it should show the product specification along with the message saying the item is out of stock and give an
alternative like any other product specification depending upon price or Title
Please if someone can help me how would i go about managing the stock management , I dont want to show the actual quantity in database to the user , but it should manage my above two queries whenever it displays the product detail page to the user. Many
Thanks
Product Table
public class ProductModels
{
[Key]
public int ProductID { get; set; }
public int TypeID { get; set; }
public int SubTypeID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string SKU { get; set; }
public decimal UnitPrice { get; set; }
public int UnitsInStock { get; set; } // Quantity in stock
public virtual ProductTypeModels ProductTypes { get; set; }
public virtual ProductSubTypeModels ProductSubTypes { get; set; }
public List<ProductTypeModels> productTypes { get; set; }
public List<ProductSubTypeModels> productSubTypes { get; set; }
}
Store Controller
public class StoreController : Controller
{
private DataContext db = new DataContext();
//
// GET: /Store/
public ActionResult Index()
{
List<TypeViewModel> model = new List<TypeViewModel>();
foreach (var item in db.ProductTypes) //loop through each ProductType and add it to TypeViewModel
{
model.Add(new TypeViewModel
{
TypeId = item.TypeID,
TypeName = item.TypeName,
ProductSubTypes = db.ProductSubTypes.Where(sub => sub.TypeID == item.TypeID).ToList()
});
}
return View(model);
}
//
// GET: /Store/Details/5
public ActionResult ProductDetail(int typeId, bool isTypeId) //the isTyped is to check if the typeId is typeId or subTypeId
{
List<ProductModels> allProducts = new List<ProductModels>();
if (isTypeId)
{
allProducts = db.Products.Where(p => p.ProductSubTypes.TypeID == typeId).ToList();
}
else
{
allProducts = db.Products.Where(p => p.SubTypeID == typeId).ToList();
}
return View(allProducts);
}
Now i want to manage the stock quantity like if customer try to add 60 cases of coke ( any product) into the basket and i have only 40 cases then it will show either bulk purchase or it exceeds the total quantity in stock .
Verify in the ACtion code ( or in the ViewModel) this .
its more complex than that. lets say you have 60 cases of coke in stock. and two users want to add 40 cases to their baskets. do you allow over book? if you do and both commit, the last will lose. do you commit their other basket entries, or roll all back.
even in the commit, the user may fail payment, which may require roll back.
you need to get the business rules on how to handle inventory.
Hi bruce , if two users try to add at the same time then i have to handle concurrency . But here i want to handle stock control for displaying data to the user . Do you know any tutorials to follow on mvc where there have done stock management and also Given
discount percentage on different items on offer or if you can guide me through : Like this website :
browse the last product where they have given alternative and also on many products there are tags like 36% off and the discounted value is calculated .
rlondonboy
Member
2 Points
29 Posts
How to manage stock control in e-commerce for displaying quantity in mvc3.0
Nov 11, 2012 10:28 AM|LINK
I have a product table with the following fields as shown , i am diplaying the product specification on a Product detail page via Store controller .
Please if someone can help me how would i go about managing the stock management , I dont want to show the actual quantity in database to the user , but it should manage my above two queries whenever it displays the product detail page to the user. Many Thanks
Product Table
public class ProductModels { [Key] public int ProductID { get; set; } public int TypeID { get; set; } public int SubTypeID { get; set; } public string Title { get; set; } public string Description { get; set; } public string SKU { get; set; } public decimal UnitPrice { get; set; } public int UnitsInStock { get; set; } // Quantity in stock public virtual ProductTypeModels ProductTypes { get; set; } public virtual ProductSubTypeModels ProductSubTypes { get; set; } public List<ProductTypeModels> productTypes { get; set; } public List<ProductSubTypeModels> productSubTypes { get; set; } }Store Controller
public class StoreController : Controller { private DataContext db = new DataContext(); // // GET: /Store/ public ActionResult Index() { List<TypeViewModel> model = new List<TypeViewModel>(); foreach (var item in db.ProductTypes) //loop through each ProductType and add it to TypeViewModel { model.Add(new TypeViewModel { TypeId = item.TypeID, TypeName = item.TypeName, ProductSubTypes = db.ProductSubTypes.Where(sub => sub.TypeID == item.TypeID).ToList() }); } return View(model); } // // GET: /Store/Details/5 public ActionResult ProductDetail(int typeId, bool isTypeId) //the isTyped is to check if the typeId is typeId or subTypeId { List<ProductModels> allProducts = new List<ProductModels>(); if (isTypeId) { allProducts = db.Products.Where(p => p.ProductSubTypes.TypeID == typeId).ToList(); } else { allProducts = db.Products.Where(p => p.SubTypeID == typeId).ToList(); } return View(allProducts); }ignatandrei
All-Star
137716 Points
22159 Posts
Moderator
MVP
Re: How to manage stock control in e-commerce for displaying quantity in mvc3.0
Nov 11, 2012 04:37 PM|LINK
Verify in the ACtion code ( or in the ViewModel) this .
bruce (sqlwo...
All-Star
37626 Points
5574 Posts
Re: How to manage stock control in e-commerce for displaying quantity in mvc3.0
Nov 11, 2012 08:00 PM|LINK
its more complex than that. lets say you have 60 cases of coke in stock. and two users want to add 40 cases to their baskets. do you allow over book? if you do and both commit, the last will lose. do you commit their other basket entries, or roll all back. even in the commit, the user may fail payment, which may require roll back.
you need to get the business rules on how to handle inventory.
rlondonboy
Member
2 Points
29 Posts
Re: How to manage stock control in e-commerce for displaying quantity in mvc3.0
Nov 11, 2012 08:11 PM|LINK
Hi bruce , if two users try to add at the same time then i have to handle concurrency . But here i want to handle stock control for displaying data to the user . Do you know any tutorials to follow on mvc where there have done stock management and also Given discount percentage on different items on offer or if you can guide me through : Like this website :
http://www.tesco.com/wine/product/search/default.aspx?searchBox=chablis&No=10&pageSize=max
browse the last product where they have given alternative and also on many products there are tags like 36% off and the discounted value is calculated .