public ProductModel Add(ProductModel product) { var addedProduct = _db.Add(product); _db.SaveChanges(); //product.ProductCode = addedProduct.Entity.ProductCode; return(product); }
public CampaignModel Add(CampaignModel campaign) { var addedCampaign = _db.Add(campaign); _db.SaveChanges(); campaign.CampaignId = addedCampaign.Entity.CampaignId; return(campaign); }
public void OrderLogic(OrderModel order) { var product = _productRepository.GetByProductCode(order.ProductCode); if (product == null) { //null id } else { if (product.Stock > order.Quantity) { product.Stock = product.Stock - order.Quantity; order.Status = true; //first campaign picked. var campaign = _db.Campaign.SingleOrDefault(x => x.ProductCode == product.ProductCode && x.Status == true); if (campaign == null) { //productPrice is same. //order has no campaign order.CampaignId = 0; } else { //productPrice decreased with campaign's limit. product.Price = product.Price - (product.Price / campaign.PriceManipulationLimit); order.CampaignId = campaign.CampaignId; } _productRepository.Update(product); } else { //productStock is insufficient. order.Status = false; } order.Price = product.Price; _db.Add(order); _db.SaveChanges(); } }