Exemple #1
0
        public static void ManyToManyCourse()
        {
            using (PetShopDBContext _context = new PetShopDBContext())
            {
                var course = new Course()
                {
                    NAME         = "Customer 111 test 1",
                    SUBJECT_TYPE = "Custimer 111 test",
                    Customers    = GetJoinManyToManyCustomer()
                };
                _context.Courses.Add(course);
                _context.SaveChanges();
            }

            Customer      customer;
            List <Course> courses;

            using (PetShopDBContext _context = new PetShopDBContext())
            {
                customer = _context.Customers.Find(9162);
                courses  = _context.Courses.ToList();
            }

            /*using (PetShopDBContext _context = new PetShopDBContext())
             * {
             *  _context.Entry(customer).State = System.Data.Entity.EntityState.Modified;
             *  _context.Entry(customer).Collection(dc => dc.Courses).Load();
             *  var it = courses.Where(c => c.ID < 2).Select(c => new JoinCustomerCourse
             *  {
             *      CUSTOMER_ID = customer.ID,
             *      COURSE_ID = c.ID
             *  }).ToList();
             *  customer.Courses = it;
             *  _context.SaveChanges();
             * }*/

            var it = courses.Where(c => c.ID < 2).Select(c => new JoinCustomerCourse
            {
                CUSTOMER_ID = customer.ID,
                COURSE_ID   = 2
            }).ToList();

            it.Add(new JoinCustomerCourse
            {
                CUSTOMER_ID = customer.ID,
                COURSE_ID   = 1
            });
            customer.Courses = it;

            UpdateCustomerClass updateCustomer = new UpdateCustomerClass(customer);

            updateCustomer.SaveUpdate();
        }
        private void UpdateCustomer(Customer customer)
        {
            UpdateCustomerClass updateCustomer = new UpdateCustomerClass(customer);

            updateCustomer.SaveUpdate();
        }
        public static void TestManyToMay()
        {
            using (PetShopDBContext _context = new PetShopDBContext())
            {
                var course = new Course()
                {
                    NAME         = "Customer 111 test 1",
                    SUBJECT_TYPE = "Custimer 111 test",
                    Customers    = GetJoinManyToManyCustomer()
                };
                _context.Courses.Add(course);
                _context.SaveChanges();
            }

            Customer      customer;
            List <Course> courses;
            var           messages = new List <Message>();

            using (PetShopDBContext _context = new PetShopDBContext())
            {
                customer = _context.Customers.Find(9162);
                courses  = _context.Courses.ToList();

                /*messages = _context.Messages.Where(m => m.SENDER_ID == 9162)
                 *          .ToList();*/
            }

            var coursecustomer = courses.Where(c => c.ID < 10).Select(c => new JoinCustomerCourse
            {
                CUSTOMER_ID = customer.ID,
                COURSE_ID   = c.ID
            }).ToList();

            customer.Courses = coursecustomer;

            foreach (var message in messages)
            {
                message.MESSAGE_HEAD = "updated messgae";
                message.TEXT         = "I can now start working on something else";
            }

            using (PetShopDBContext _dbcontext = new PetShopDBContext())
            {
                for (int cycle = 0; cycle < 5; cycle++)
                {
                    Message message = new Message()
                    {
                        MESSAGE_HEAD = "test message",
                        SENDER       = "Need to put id",
                        RECEIVER     = "Definitly need to put id",
                        CREATE_DATE  = DateTime.Now,
                        SEND_BY_DATE = DateTime.Now,
                        TEXT         = "Well i guess i'm making changes to this table next",
                        SENDER_ID    = customer.ID
                    };

                    messages.Add(message);
                }
            }

            customer.Messages = messages;

            UpdateCustomerClass updateCustomer = new UpdateCustomerClass(customer);

            updateCustomer.SaveUpdate();
        }