Ejemplo n.º 1
0
 public DogOrder(DogBuyer buyer, double tot, StoreLocation sl)
 {
     this.DogBuyer      = buyer;
     this.StoreLocation = sl;
     this.Total         = tot;
     _itemsInOrder      = new List <Item>();
     this.OrderDate     = DateTime.Now;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Checks AddBuyer and FindBuyer
 /// </summary>
 public void AddBuyerAddsBuyer()
 {
     using (var context = new Entity.FannerDogsDBContext(options))
     {
         IRepo          _repoDS  = new Repo(context);
         Model.DogBuyer dogBuyer = new Model.DogBuyer("Texas Toaster", "Test, TX", 1234567890);
         _repoDS.AddBuyer
         (
             dogBuyer
         );
         Model.DogBuyer dogBuyerReturned = _repoDS.FindBuyer(1234567890);
         Assert.Equal(dogBuyerReturned.PhoneNumber, dogBuyer.PhoneNumber);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Checks FindBuyer to make sure it returns null appropriately
 /// </summary>
 public void WrongBuyerShouldNotBeFound()
 {
     using (var context = new Entity.FannerDogsDBContext(options))
     {
         IRepo          _repoDS  = new Repo(context);
         Model.DogBuyer dogBuyer = new Model.DogBuyer("Texas Toaster", "Test, TX", 1234567890);
         _repoDS.AddBuyer
         (
             dogBuyer
         );
         Model.DogBuyer dogBuyerReturned = _repoDS.FindBuyer(1235467890);
         bool           buyerNotThere    = (dogBuyerReturned == null);
         bool           expected         = true;
         Assert.Equal(buyerNotThere, expected);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Checks GetAllBuyers
 /// </summary>
 public void GetAllBuyersGetsBuyers()
 {
     using (var context = new Entity.FannerDogsDBContext(options))
     {
         IRepo          _repoDS  = new Repo(context);
         Model.DogBuyer dogBuyer = new Model.DogBuyer("Ama Test", "Wired, Wyoming", 9638527410);
         _repoDS.AddBuyer
         (
             dogBuyer
         );
         dogBuyer = new Model.DogBuyer("Texas Toaster", "Test, TX", 1234567890);
         _repoDS.AddBuyer
         (
             dogBuyer
         );
         List <Model.DogBuyer> dogBuyers = _repoDS.GetAllBuyers();
         int expected = 2;
         Assert.Equal(dogBuyers.Count, expected);
     }
 }
Ejemplo n.º 5
0
 public DogOrder(DogBuyer buyer, double tot, StoreLocation sl, int id) : this(buyer, tot, sl)
 {
     this.id = id;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Takes in a phone number of the user you're looking for and a special option
        /// parameter where user has inputted the query they wish to perform
        /// </summary>
        /// <param name="phoneNumber">phone number of User whose orders you wish to find</param>
        /// <param name="option">int where user has specified the query they wish to perform</param>
        /// <returns>List of orders user has purchased</returns>
        public List <Model.DogOrder> FindUserOrders(long phoneNumber, int option)
        {
            Model.DogBuyer         dogBuyer  = FindBuyer(phoneNumber);
            List <Entity.DogOrder> dogOrders = new List <Entity.DogOrder>();

            switch (option)
            {
            case 1:
                dogOrders = (
                    from DogOrder in _context.DogOrders where
                    DogOrder.BuyerId == phoneNumber
                    orderby DogOrder.DateOrder ascending
                    select DogOrder
                    ).ToList();
                break;

            case 2:
                dogOrders = (
                    from DogOrder in _context.DogOrders where
                    DogOrder.BuyerId == phoneNumber
                    orderby DogOrder.DateOrder descending
                    select DogOrder
                    ).ToList();
                break;

            case 3:
                dogOrders = (
                    from DogOrder in _context.DogOrders where
                    DogOrder.BuyerId == phoneNumber
                    orderby DogOrder.Total ascending
                    select DogOrder
                    ).ToList();
                break;

            case 4:
                dogOrders = (
                    from DogOrder in _context.DogOrders where
                    DogOrder.BuyerId == phoneNumber
                    orderby DogOrder.Total descending
                    select DogOrder
                    ).ToList();
                break;

            default:
                return(null);
            }
            Entity.DogStore         dogStore;
            List <Entity.OrderItem> orderItems;
            List <Model.DogOrder>   returnOrders = new List <Model.DogOrder>();

            Model.DogOrder returnOrder;
            Entity.Dog     dog;
            foreach (Entity.DogOrder dogOrder in dogOrders)
            {
                dogStore = (
                    from DogStore in _context.DogStores where
                    DogStore.Id == dogOrder.StoreId
                    select DogStore
                    ).Single();
                orderItems = (
                    from OrderItem in _context.OrderItems where
                    OrderItem.OrderId == dogOrder.Id
                    select OrderItem
                    ).ToList();
                returnOrder = new DogOrder(
                    dogBuyer,
                    dogOrder.Total,
                    new Model.StoreLocation(
                        dogStore.Id,
                        dogStore.StoreAddress,
                        dogStore.StoreName
                        )
                    );
                returnOrder.OrderDate = dogOrder.DateOrder;
                foreach (Entity.OrderItem orderItem in orderItems)
                {
                    dog = (
                        from Dog in _context.Dogs where
                        Dog.ItemId == orderItem.DogId
                        select Dog
                        ).Single();
                    returnOrder.AddItemToOrder(new Model.OrderItem(
                                                   new Model.Dog(
                                                       dog.Breed,
                                                       dog.Gender.ToCharArray()[0],
                                                       dog.Price
                                                       ),
                                                   orderItem.Quantity.Value
                                                   ));
                }
                returnOrders.Add(returnOrder);
            }
            return(returnOrders);
        }