示例#1
0
        public ProductModel Add(ProductModel product)
        {
            var addedProduct = _db.Add(product);

            _db.SaveChanges();
            //product.ProductCode = addedProduct.Entity.ProductCode;

            return(product);
        }
示例#2
0
        public CampaignModel Add(CampaignModel campaign)
        {
            var addedCampaign = _db.Add(campaign);

            _db.SaveChanges();
            campaign.CampaignId = addedCampaign.Entity.CampaignId;

            return(campaign);
        }
示例#3
0
        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();
            }
        }