Beispiel #1
0
 public string GetTime(int id)
 {
     using (var db = new OfCourseContext())
     {
         return(db.Courses.Find(id).AvailableTime);
     }
 }
Beispiel #2
0
        /////////FOR BOOKING TAB
        ///

        public string GetCourseTitle(int id)
        {
            using (var db = new OfCourseContext())
            {
                return(db.Courses.Find(id).Title);
            }
        }
Beispiel #3
0
 public string GetDate(int id)
 {
     using (var db = new OfCourseContext())
     {
         return(String.Format("{0:ddd, MMM d, yyyy}", db.Courses.Find(id).AvailableDate));
     }
 }
Beispiel #4
0
        public void Setup()
        {
            _courseManager = new CourseManager();
            // remove test entry in DB if present
            using (var db = new OfCourseContext())
            {
                var selectedCourses =
                    from c in db.Courses
                    where c.Title.Equals("TestCrochetBasics")
                    select c;

                db.Courses.RemoveRange(selectedCourses);
                db.SaveChanges();

                var selectedCourses2 =
                    from c in db.Courses
                    where c.Title.Equals("testtest")
                    select c;

                db.Courses.RemoveRange(selectedCourses);
                db.SaveChanges();



                var selectedCustomer =
                    from c in db.Customers
                    where c.Username.Equals("testJohn")
                    select c;

                db.Customers.RemoveRange(selectedCustomer);
                db.SaveChanges();
            }
        }
Beispiel #5
0
        public void WhenACourseIsBooked_TheDatabaseIsUpdated()
        {
            using (var db = new OfCourseContext())
            {
                //make course to book
                DateTime date = new DateTime(2021, 5, 1, 8, 30, 52);
                _courseManager.Create(1, "Knitting", "testtest", "Hey sweet purls, come join us for this knit sesh", "Birmingham", "W2", 20.0, 33, 1, date, "Morning", 10);

                //gets the courseID
                var courseId = db.Courses.Where(c => c.Title.Equals("testtest")).FirstOrDefault().CourseId;

                //make a customer
                _courseManager.CreateCustomer("John", "Smith", "testJohn", "password", "Shrewsbury", "SH1");
                var selectedCustomer = db.Customers.Where(c => c.Username.Equals("testJohn")).First();

                var numOfBookedCoursesBefore = selectedCustomer.BookedCourses.Count();

                _courseManager.BookCourse(courseId, selectedCustomer.CustomerId);


                //Have to join the booked courses list otherwise you can't find it
                List <Course> BookedCourses = db.Customers.Include(bc => bc.BookedCourses).Where(c => c.CustomerId == selectedCustomer.CustomerId).FirstOrDefault().BookedCourses.ToList();

                var updatedBookedCoursesNum = BookedCourses.Count();
                Assert.AreEqual(numOfBookedCoursesBefore + 1, updatedBookedCoursesNum);
            }
        }
Beispiel #6
0
        //This works, as it is being deleted from the database, but it isn't being deleted in the list?
        public void DeleteSelectedBookedCourse(object course, int custId)
        {
            using (var db = new OfCourseContext())
            {
                Course selectedCourse = (Course)course;
                var    courseId       = selectedCourse.CourseId;

                //var selectedCustomer = db.Customers.Where(c => c.CustomerId == custId);


                List <Course> BookedCourseList = db.Customers.Include(bc => bc.BookedCourses).Where(c => c.CustomerId == custId).FirstOrDefault().BookedCourses.ToList();
                var           courseOnList     = BookedCourseList.Find(c => c.CourseId == courseId);


                // call remove range just in case there are multiple, useful to use if you don't know if its in the table or not.
                if (BookedCourseList.Contains(courseOnList))
                {
                    var oldList = db.Customers.Include(bc => bc.BookedCourses).Where(c => c.CustomerId == custId).FirstOrDefault().BookedCourses.Count();

                    //This returns true, so it does get removed
                    db.Customers.Include(bc => bc.BookedCourses).Where(c => c.CustomerId == custId).FirstOrDefault().BookedCourses.Remove(courseOnList);

                    var newBookedCourses = db.Customers.Include(bc => bc.BookedCourses).Where(c => c.CustomerId == custId).FirstOrDefault().BookedCourses.Count();

                    db.SaveChanges();
                }
            }
        }
Beispiel #7
0
 public List <Category> GetAllCategories()
 {
     using (var db = new OfCourseContext())
     {
         return(db.Categories.ToList());
     }
 }
Beispiel #8
0
 public List <Course> RetrieveTrainerCourses(int trainerId)
 {
     using (var db = new OfCourseContext())
     {
         var justTrainerCourses = db.Courses.Where(c => c.TrainerId == trainerId).ToList();
         return(justTrainerCourses);
     }
 }
Beispiel #9
0
 public string CategoryTitleFromId(int id)
 {
     using (var db = new OfCourseContext())
     {
         var catName = db.Categories.Where(c => c.CategoryId == id).First().CategoryName;
         return(catName);
     }
 }
Beispiel #10
0
        public void CheckThereIsAtLeastOneCourse()
        {
            using var db = new OfCourseContext();
            // if empty returns -1, if not returns ID of first entry
            int categoryNotEmpty = _courseManager.IsCourseTableEmptyReturnIdOfFirst();

            if (categoryNotEmpty >= 0)
            {
                Assert.Pass();
            }
        }
Beispiel #11
0
        public void CategoryListCanBeRetrievedForTheCategoryDropDownMenus()
        {
            using (var db = new OfCourseContext())
            {
                var NumListofCats = _courseManager.GetAllCategories().Count();

                var NumOfCatsFromDB = db.Categories.Count();

                Assert.AreEqual(NumListofCats, NumOfCatsFromDB);
            }
        }
Beispiel #12
0
        public void CoursesListCanBeRetrieved()
        {
            using (var db = new OfCourseContext())
            {
                var NumListofCourses = _courseManager.RetrieveAll().Count();

                var NumOfCoursesFromDB = db.Courses.Count();

                Assert.AreEqual(NumListofCourses, NumOfCoursesFromDB);
            }
        }
Beispiel #13
0
        public void WhenACustomerLogsIn_AnErrorIsReturnedIfUserIsntThere(string username)
        {
            using (var db = new OfCourseContext())
            {
                var selectedCustomer = db.Customers.Where(c => c.Username.Equals(username)).FirstOrDefault();

                var returnsTuple = _courseManager.Login("testJohn", "password");

                Assert.AreEqual(returnsTuple.Item1, "E");
            }
        }
Beispiel #14
0
        public List <Course> RetrieveThisCustomersBookings(int custId)
        {
            using (var db = new OfCourseContext())
            {
                //IF error here, customer doesn't exist

                Customer      selectedCustomer = db.Customers.Find(custId);
                List <Course> BookedCourses    = db.Customers.Include(bc => bc.BookedCourses).Where(c => c.CustomerId == custId).FirstOrDefault().BookedCourses.ToList();

                return(BookedCourses);
            }
        }
Beispiel #15
0
        public void WhenANewCourseIsAdded_TheNumberOfCoursesIncreasesBy1()
        {
            using (var db = new OfCourseContext())
            {
                var      numberOfCustomersBefore = db.Courses.Count();
                DateTime date = new DateTime(2021, 5, 1, 8, 30, 52);
                _courseManager.Create(1, "Knitting", "TestCrochetBasics", "Hey sweet purls, come join us for this knit sesh", "London", "W2", 20.0, 33, 1, date, "Morning", 10);
                var numberOfCustomersAfter = db.Courses.Count();

                Assert.AreEqual(numberOfCustomersBefore + 1, numberOfCustomersAfter);
            }
        }
Beispiel #16
0
        public void CreateCustomer(string firstName, string lastName, string username, string password, string city, string postCode)
        {
            var newCustomer = new Customer()
            {
                FirstName = firstName, LastName = lastName, Username = username, Password = password, City = city, PostCode = postCode
            };

            using (var db = new OfCourseContext())
            {
                db.Customers.Add(newCustomer);
                db.SaveChanges();
            }
        }
Beispiel #17
0
        public void WhenAUserLogsIn_TheUsernameIsNotCaseSensitive()
        {
            using (var db = new OfCourseContext())
            {
                //make a customer
                _courseManager.CreateCustomer("John", "Smith", "testJohn", "password", "Shrewsbury", "SH1");
                var selectedCustomer = db.Customers.Where(c => c.Username.Equals("john")).First();

                var returnsTuple  = _courseManager.Login("testJohn", "password");
                var returnsTuple2 = _courseManager.Login("TEsTJOhN", "password");

                Assert.AreEqual(returnsTuple, returnsTuple2);
            }
        }
Beispiel #18
0
        public void WhenACustomerLogsIn_TheCorrectUserTypeAndIdIsReturned()
        {
            using (var db = new OfCourseContext())
            {
                //make a customer
                _courseManager.CreateCustomer("John", "Smith", "testJohn", "password", "Shrewsbury", "SH1");
                var selectedCustomer = db.Customers.Where(c => c.Username.Equals("testJohn")).First();

                var returnsTuple = _courseManager.Login("testJohn", "password");

                Assert.AreEqual(returnsTuple.Item1, "C");
                Assert.AreEqual(returnsTuple.Item2, selectedCustomer.CustomerId);
            }
        }
Beispiel #19
0
 public int IsCourseTableEmptyReturnIdOfFirst()
 {
     using (var db = new OfCourseContext())
     {
         if (db.Courses.Any())
         {
             return(db.Courses.First().CategoryId);
         }
         else
         {
             return(-1);
         }
     }
 }
Beispiel #20
0
        public List <String> GetAllCategoryNames()
        {
            List <string> catList = new List <string>();

            using (var db = new OfCourseContext())
            {
                var categoryQuery = GetAllCategories();
                foreach (var cat in categoryQuery)
                {
                    catList.Add(cat.CategoryName);
                }
            }
            return(catList);
        }
Beispiel #21
0
        public void BookCourse(int courseId, int custId)
        {
            using (var db = new OfCourseContext())
            {
                Course   selectedCourse   = db.Courses.Find(courseId);
                Customer selectedCustomer = db.Customers.Find(custId);


                db.Courses.Find(courseId).BookedCustomers.Add(selectedCustomer);

                db.Customers.Find(custId).BookedCourses.Add(selectedCourse);

                db.SaveChanges();
            }
        }
Beispiel #22
0
        //FOR extension:
        //FOR the FILTER, trying to access only checked categories and then fill up that list with the selected cats
        public List <Course> RetrieveCategories()
        {
            using (var db = new OfCourseContext())
            {
                List <Course> coursesOfSelectedCats = new List <Course>();
                var           selecteds             = db.Categories.Where(c => c.isSelected == true);
                foreach (var item in selecteds)
                {
                    var catId = db.Categories.Where(c => c.CategoryName.Equals(item)).First().CategoryId;
                    coursesOfSelectedCats.Add(db.Courses.Find(catId));
                }

                return(coursesOfSelectedCats.ToList());
            }
        }
Beispiel #23
0
        public void WhenACourseDetailsAreChanged_TheDatabaseIsUpdated()
        {
            using (var db = new OfCourseContext())
            {
                DateTime date = new DateTime(2021, 5, 1, 8, 30, 52);

                //this one sometimes fails especially if I try and take it out in the setup test
                _courseManager.Create(1, "Knitting", "testtest", "Hey sweet purls, come join us for this knit sesh", "Alabama", "W2", 20.0, 33, 1, date, "Morning", 10);

                var courseId = db.Courses.Where(c => c.Title.Equals("testtest")).FirstOrDefault().CourseId;

                _courseManager.Update(courseId, "testtest", "A course that is surprisingly difficult", "Alabama", "W2", 20.0, 33, 1, 10);

                var updatedCourse = db.Courses.Find(courseId);
                Assert.AreEqual("Alabama", updatedCourse.City);
            }
        }
Beispiel #24
0
        // Test that course list appears, so ToString() is course Title
        public void CheckCoursesToStringShowJustCourseTitle(int id, string expTitle)
        {
            //trying to add a moq test
            //// Arrange
            //var mockCatalogItemManager = new Mock<ICourseManager>();
            //var mockExchangeRateService = new Mock<IExchangeRateService>();
            //// Act
            //_sut = new SaleCreator(mockCatalogItemManager.Object, mockExchangeRateService.Object);
            //// Assert
            //Assert.That(_sut, Is.InstanceOf<SaleCreator>());

            using var db = new OfCourseContext();

            string title = db.Courses.Find(id).ToString();

            Assert.AreEqual(title, expTitle);
        }
Beispiel #25
0
 public CourseService()
 {
     _context = new OfCourseContext();
 }
Beispiel #26
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            using (var db = new OfCourseContext())
            {
                Console.WriteLine(db.ContextId);
                Console.WriteLine("creating new customer");
                //READ

                //iterate over and output all customers
                // has to be in the using statement
                //foreach (var c in db.Customers)
                //{
                //    Console.WriteLine($"Customer {c.FirstName} had ID {c.CustomerId} and lives in {c.City}");
                //}

                //CREATE(add a new customer)
                //construct a new customer
                //var newCategory = new Category()
                //{
                //    CategoryName = "Craft"

                //};
                //var newCategory3 = new Category()
                //{
                //    CategoryName = "Cookery"

                //};
                //var newCategory1 = new Category()
                //{
                //    CategoryName = "Gardening"

                //};
                var newTrainer = new Trainer()
                {
                    PostCode  = "SE1",
                    City      = "London",
                    Username  = "******",
                    Password  = "******",
                    FirstName = "Julia",
                    LastName  = "Smith"
                };
                var newCustomer = new Customer()
                {
                    PostCode  = "TN13",
                    City      = "Sevenoaks",
                    Username  = "******",
                    Password  = "******",
                    FirstName = "Shelly",
                    LastName  = "Smith"
                };
                //var newCourse = new Course()
                //{
                //    CategoryId = 2,
                //    TrainerId = 2,
                //    PostCode = "W1",
                //    Title = "Floristry 101",
                //    Description = "Learn basic Floristry  techniques in just two sessions!",
                //    City = "London",
                //    PricePerSession = 15.0,
                //    MaxPeople = 5,
                //    TotalSessions = 2,
                //    SessionLengthMinutes = 60
                //};

                //var newAdmin = new Admin()
                //{

                //    City = "London",
                //    Username = "******",
                //    Password = "******",
                //    FirstName = "Megan",
                //    LastName = "Benson"
                //};



                ////};
                ////DELETE a customer
                //// this line DEFINES the query (LINQ steps)
                //var selectedCustomer = db.Customers.Where(c => c.CustomerId == "BLOB");
                //// call remove range just in case there are multiple, useful to use if you don't know if its in the table or not.
                //db.Customers.RemoveRange(selectedCustomer);
                //db.SaveChanges();

                //ADD the customer
                //made a new customer, adding it to the customers database adn then saving.
                //// using properties instead of fields
                db.Customers.Add(newCustomer);
                //db.Categories.Add(newCategory);
                //db.Categories.Add(newCategory1);
                //db.Categories.Add(newCategory3);
                db.Trainers.Add(newTrainer);
                //db.Courses.Add(newCourse);
                // db.Admins.Add(newAdmin);
                db.SaveChanges();

                //UPDATE a customer
                //get the first customer with the id of blob
                // this line EXCEUTES the query (LINQ steps)
                //var customer = db.Customers.Where(c => c.CustomerId == "BLOB").FirstOrDefault();
                ////change that one's city to Paris
                //customer.City = "Paris";
                //db.SaveChanges();


                ///// LINQ queries
                ////define the query
                //var query = db.Customers.Where(c => c.CustomerId == "BONAP");
                ////execute the query
                //// this below line can be called many times, so you could have many queries saved and ready to check for them
                //var selected = query.FirstOrDefault();

                ////To do both at the same time, defne and execute (if you don't wan tot keep your query
                //var selected2 = db.Customers.Where(c => c.CustomerId == "BONAP").FirstOrDefault();

                ////LINQ to SQL
                //// Find is shorthand for ID
                //var selected3 = db.Customers.Find("BLOG");

                ////Query syntax
                //var query1 =
                //    from c in db.Customers
                //    where c.City == "London"
                //    orderby c.ContactName
                //    select c;

                //foreach (var cust in query1)
                //{
                //    Console.WriteLine(cust.GetFullName());
                //}

                ////method syntax
                //IEnumerable<Customer> query2 = db.Customers
                //    .Where(c => c.City == "London")
                //    .OrderBy(c => c.ContactName);
            }
        }
Beispiel #27
0
 public CourseService(OfCourseContext context)
 {
     _context = context;
 }