Exemplo n.º 1
0
        public async Task <string> PutToSoldHistory(BidViewModel bidFromView)
        {
            var product = await _repository.Products.Get(bidFromView.ProductId);

            var result = 0;

            var isAvilable = await _repository.SoldRepository.Find(s => s.ProductID == bidFromView.ProductId.ToString());

            if (isAvilable.Count() > 0)
            {
                isAvilable.ElementAt(0).BuyerID   = bidFromView.ApplicationUserId;
                isAvilable.ElementAt(0).SoldPrice = bidFromView.BidPrice;
                result = await _repository.SoldRepository.Update(isAvilable.ElementAt(0).Id, isAvilable.ElementAt(0));

                if (1 == result)
                {
                    return(isAvilable.ElementAt(0).Id.ToString());
                }
            }
            else
            {
                var soldHistory = new SoldHistory
                {
                    Id = Guid.NewGuid(),
                    ApplicationUserId  = product.ApplicationUserId,
                    ProductName        = product.ProductName,
                    ProductDescription = product.ProductDescription,
                    SoldPrice          = bidFromView.BidPrice,
                    DateTime           = product.EndDateTime,
                    BuyerID            = bidFromView.ApplicationUserId,
                    ProductID          = bidFromView.ProductId.ToString()
                };
                result = await _repository.SoldRepository.Add(soldHistory);

                if (1 == result)
                {
                    return(soldHistory.Id.ToString());
                }
            }

            return("Unsucessfull");
        }
        public void SubmitSold(int id, string date, int qty, string sizes, string market)
        {
            var inventoryAsset = _context
                                 .InventoryAssets.Include(asset => asset.Category)
                                 .Include(asset => asset.Market)
                                 .FirstOrDefault(asset => asset.Id == id);

            // design decision: Do you want to let the available count go negative?
            // This is pending feedback, at the moment I think it may be useful to let the available count go negative and setting the color to red when it does.
            // If you've sold and shipped more than you have in stock then either a recount of physical inventory needs to take place, or you've made shipping errors.
            inventoryAsset.Available -= qty;
            var soldItem = new SoldHistory
            {
                InventoryAsset = inventoryAsset,
                Date           = date,
                Quantity       = qty,
                Sizes          = sizes,
                Market         = market
            };

            _context.Add(soldItem);
            _context.Update(inventoryAsset);
            _context.SaveChanges();
        }