public IEnumerable<OrderMovie> GetAllOrderMoviesByOrder(Order item)
 {
     using (Context mCon = new Context())
     {
         return mCon.OrderMovie.Include("Movie.Genres").Include("Order").Where(x => x.Order.Id == item.Id).ToList();
     }
 }
示例#2
0
 public IEnumerable<Movie> GetMoviesByOrder(Order item)
 {
     if (item == null)
         throw new ArgumentNullException("Order can not be null");
     using (Context mCon = new Context())
     {
         List<OrderMovie> oms = mCon.OrderMovie.Include("Movie.Genres").Include("Order").Where(x => x.Order.Id == item.Id).ToList();
         List<Movie> movies = new List<Movie>();
         foreach (var i in oms)
         {
             movies.Add(i.Movie);
         }
         return movies;
     }
 }
示例#3
0
 public Order Add(Order item)
 {
     if (item == null)
         throw new ArgumentNullException("Order is null");
     if (item.Customer == null)
         throw new ArgumentException("Customer can not be null");
     using (Context mCon = new Context())
     {
         if (mCon.Customers.FirstOrDefault(x => x.Id == item.Customer.Id) != null)
             item.Customer = mCon.Customers.FirstOrDefault(x => x.Id == item.Customer.Id);
         item = mCon.Orders.Add(item);
         mCon.SaveChanges();
     }
     return item;
 }
        public void Order_added_on_create_test()
        {
            Facade facade = new Facade();

            Customer cus = new Customer()
            {
                FirstName = "Test",
                Address = "TestAddress",
                BirthDate = DateTime.Now,
                Email = "TestEmail",
                PhoneNumber = 1234
            };
            cus = facade.GetCustomerRepo().Add(cus);
            Genre genre = new Genre() { Name = "TestGenre" };
            List<Genre> list = new List<Genre>();
            genre = facade.GetGenreRepo().Add(genre);
            list.Add(genre);
            Movie movie = new Movie()
            {
                Name = "TestName",
                Genres = list,
                Price = 123,
                TrailerURL = "TestURL"
            };
            movie = facade.GetMovieRepo().Add(movie);
            Order order = new Order()
            {
                Customer = cus,
                Date = DateTime.Now
            };
            OrderMovie om = new OrderMovie() { Movie = movie, Order = order };
            om = facade.GetOrderMovieRepo().Add(om);

            order.OrderMovie.Add(om);

            order = facade.GetOrderRepo().Add(order);

            facade = new Facade();

            Assert.AreEqual(order.Customer.FirstName, facade.GetOrderRepo().Get(order.Id).Customer.FirstName);
        }
示例#5
0
        public HttpResponseMessage Order(Order item)
        {
            item = facade.GetOrderRepo().Add(item);
            var response = Request.CreateResponse<Order>(HttpStatusCode.Created, item);

            string uri = Url.Link("DefaultApi", new { id = item.Id });
            response.Headers.Location = new Uri(uri);
            return response;
        }
示例#6
0
 public void Order(int id, Order order)
 {
     order.Id = id;
     if (!facade.GetOrderRepo().Update(order))
     {
         throw new HttpResponseException(HttpStatusCode.NotFound);
     }
 }
示例#7
0
 public bool Update(Order item)
 {
     if (item == null)
         throw new ArgumentNullException("Order is null");
     if (Get(item.Id) == null)
         return false;
     using (Context mCon = new Context())
     {
         Order temp = mCon.Orders.FirstOrDefault(x => x.Id == item.Id);
         temp.OrderMovie = item.OrderMovie;
         temp.Customer = item.Customer;
         temp.Date = item.Date;
         mCon.SaveChanges();
     }
     return true;
 }
        public void Order_update_updates_in_database_test()
        {
            Facade facade = new Facade();
            Order order = new Order()
            {
                Date = DateTime.Now,
                Customer = new Customer()
                {
                    BirthDate = DateTime.Now,
                    FirstName = "jonas"
                },
                OrderMovie = new List<OrderMovie>()
            };

            order = facade.GetOrderRepo().Add(order);

            order.Customer = new Customer() { BirthDate = DateTime.Now, FirstName = "hans" };

            facade = new Facade();
            Assert.IsTrue(facade.GetOrderRepo().Update(order));

            facade = new Facade();
            Assert.AreEqual(facade.GetOrderRepo().Get(order.Id).Customer.FirstName, "hans");
        }
        public void Order_getorderbycustomer_returns_multiple_test()
        {
            Facade facade = new Facade();
            Customer cus = new Customer()
            {
                BirthDate = DateTime.Now,
                FirstName = "jonas",
                Address ="hest",
                Email = "hest"
            };
            cus = facade.GetCustomerRepo().Add(cus);
            Order orderOne = new Order() { Customer = cus, Date = DateTime.Now, OrderMovie = new List<OrderMovie>() };
            Order orderTwo = new Order() { Customer = cus, Date = DateTime.Now, OrderMovie = new List<OrderMovie>() };

            orderOne = facade.GetOrderRepo().Add(orderOne);
            orderTwo = facade.GetOrderRepo().Add(orderTwo);

            facade = new Facade();

            Assert.GreaterOrEqual(facade.GetOrderRepo().GetOrdersByCustomer(cus).ToList().Count, 2);
        }
        public void Order_getmoviesbyorder_returns_multiple_right_movies_test()
        {
            Facade facade = new Facade();
            Movie movieOne = new Movie() { Year = DateTime.Now, Name = "mov1" };
            Movie movieTwo = new Movie() { Year = DateTime.Now, Name = "mov2" };
            List<OrderMovie> list = new List<OrderMovie>();
            list.Add(new OrderMovie() { Movie = movieOne });
            list.Add(new OrderMovie() { Movie = movieTwo });
            Order order = new Order()
            {
                Date = DateTime.Now,
                OrderMovie = list,
                Customer = new Customer() { BirthDate = DateTime.Now}
            };

            order = facade.GetOrderRepo().Add(order);

            facade = new Facade();
            Assert.GreaterOrEqual(facade.GetOrderRepo().GetMoviesByOrder(order).ToList().Count, 2);
            Assert.AreEqual(facade.GetOrderRepo().GetMoviesByOrder(order).FirstOrDefault().Name, movieOne.Name);
        }