public async Task <IActionResult> AddToCart([FromBody] ProductIdModel productId, int id) { if (productId != null) { CartItem cartItem = new CartItem() { UserId = id, AddedDate = DateTime.Now, ProductId = Convert.ToInt32(productId.id) }; context.Add(cartItem); /* * var query = from m in context.CartItems * where m.ProductId != 0 // or what ever the foreign key name is... * select m; * * var count = query.Count(); */ if (await repo.SaveAllAsync()) { return(Ok()); } } else { return(NotFound()); } throw new Exception($"Failed to Add to Cart"); }
public ProductIdModel GetProductBasedOnVehicleUsage([FromUri] int VehicleUsageId) { ProductIdModel ProductIds = new ProductIdModel(); var GetProductId = InsuranceContext.VehicleUsages.Single(where : $" Id='{VehicleUsageId}'"); if (GetProductId != null) { ProductIds.ProductId = GetProductId.ProductId; } return(ProductIds); }