public List <LocationInventoryViewModel> AddToCart(List <LocationInventoryViewModel> livmList, LocationInventoryViewModel livm, CustomUser user) { var iloc = livm.Location.LocationId; var uloc = user.DefaultStore; CartInventory cInv = _repo.cartInventories.FirstOrDefault(x => x.CartId == user.CartId && x.ProductId == livm.ProductId); if (cInv == null) { cInv = new CartInventory { CartId = user.CartId, ProductId = livm.ProductId }; _repo.cartInventories.Add(cInv); } LocationInventory lInv = _repo.locationInventories.FirstOrDefault(z => z.LocationId == livm.Location.LocationId && z.ProductId == livm.ProductId); if (cInv != null && lInv.Quantity >= livm.purchaseQuantity) { cInv.CartQuantity += livm.purchaseQuantity; lInv.Quantity -= livm.purchaseQuantity; livm.Quantity -= livm.purchaseQuantity; livm.purchaseQuantity = 0; _repo.CommitSave(); } var l = livmList.FirstOrDefault(x => x.ProductId == livm.ProductId); l = livm; return(livmList); }
void Start() { gameManager = GameObject.Find("GameOverlay").GetComponent<GameManager>(); database = GameObject.Find ("ItemDatabase").GetComponent<ItemDatabase>(); inventory = GetComponentInParent<CartInventory>(); itemImage = transform.GetChild(0).GetComponent<Image>(); itemAmount = transform.GetChild(1).GetComponent<Text>(); invList = database.CartInv; quantList = database.CartInvQuant; }