Exemple #1
0
        public IHttpActionResult GetAllBillsOfUser(int buyerId)
        {
            //UserModel buyer = db.UsersRepository.GetByID(buyerId);

            //if (buyer == null)
            //{
            //    return NotFound();
            //}

            //if (buyer != null)
            //{
            //    Debug.WriteLine("Buyer is found, and it's: {0}, {1}, with id: {2}", buyer.first_name, buyer.last_name, buyerId);
            //}

            //// THIS ONLY WORKED AFTER CHANGED NAVIGATION PROPERTY FROM IENUMERABLE TO ICOLLECTION...
            //// see here: https://stackoverflow.com/a/32997694/4486196
            //IEnumerable<BillModel> bills =
            //    db.UsersRepository.
            //    Get(
            //        filter: u => u.id == buyerId,
            //        includeProperties: "billModels").
            //        FirstOrDefault().
            //        billModels;

            //// For some reason with the following one billModels is always null, with and without virtual (lazy loading) ?
            //// IEnumerable<BillModel> bills = buyer.billModels.ToList();


            ///*
            // * EXTREMELY IMPORTANT:
            // * From a more specific standpoint, lazy loading comes in to play with choosing the type.
            // * By default, navigation properties in Entity Framework come with change tracking and are proxies.
            // * In order for the dynamic proxy to be created as a navigation property,
            // * the virtual type must implement ICollection.
            // * source: https://stackoverflow.com/a/10113331/4486196
            // */

            //return Ok(bills);
            return(Ok(billService.GetBillsByBuyer(buyerId)));
        }
Exemple #2
0
 public IEnumerable <BillModel> GetBillsByBuyer(int buyerId)
 {
     return(billsService.GetBillsByBuyer(buyerId));
 }