Exemple #1
0
 public void ChooseMember(string username)
 {
     using (var db = new NSCContext())
     {
         SelectMember = db.Members.Where(e => e.Username.Trim() == username.Trim()).FirstOrDefault();
     }
 }
Exemple #2
0
 public List <Sport> AllSports()
 {
     using (var db = new NSCContext())
     {
         return(db.Sports.ToList());
     }
 }
Exemple #3
0
 public Sport SpecSport_ID(int?id)
 {
     using (var db = new NSCContext())
     {
         Sport
         //sport = "1 - Platform Diving";
             sport = id switch
         {
             1 => db.Sports.Where(e => e.SportId == 1).FirstOrDefault(),                        //sport = "1 - Platform Diving";
             2 => db.Sports.Where(e => e.SportId == 2).FirstOrDefault(),
             3 => db.Sports.Where(e => e.SportId == 3).FirstOrDefault(),
             4 => db.Sports.Where(e => e.SportId == 4).FirstOrDefault(),
             5 => db.Sports.Where(e => e.SportId == 5).FirstOrDefault(),
             6 => db.Sports.Where(e => e.SportId == 6).FirstOrDefault(),
             7 => db.Sports.Where(e => e.SportId == 7).FirstOrDefault(),
             8 => db.Sports.Where(e => e.SportId == 8).FirstOrDefault(),
             9 => db.Sports.Where(e => e.SportId == 9).FirstOrDefault(),
             10 => db.Sports.Where(e => e.SportId == 10).FirstOrDefault(),
             11 => db.Sports.Where(e => e.SportId == 11).FirstOrDefault(),
             12 => db.Sports.Where(e => e.SportId == 12).FirstOrDefault(),
             13 => db.Sports.Where(e => e.SportId == 13).FirstOrDefault(),
             _ => db.Sports.Where(e => e.SportId == 1).FirstOrDefault(),
         };
         return(sport);
     }
 }
Exemple #4
0
 public List <Booking> MemberBookings(string username)
 {
     using (var db = new NSCContext())
     {
         return((from b in db.Bookings
                 join m in db.Members on b.MemberId equals m.MemberId
                 where m.Username == username
                 select b).ToList());
     }
 }
Exemple #5
0
        public void CREATEBooking_NumberIncreasesBy1()
        {
            using (var db = new NSCContext())
            {
                var numberBefore = db.Bookings.ToList().Count();
                _crudBookings.CreateBooking(1, 2, 4, DateTime.Now, TimeSpan.FromHours(1.00));
                var numberAfter = db.Bookings.ToList().Count();

                Assert.AreEqual(numberBefore + 1, numberAfter);
            }
        }
Exemple #6
0
        public void CREATEMember_NumberIncreasesBy1()
        {
            using (var db = new NSCContext())
            {
                var numberBefore = db.Members.ToList().Count();
                _crudMembers.CreateMember("stephfoxton", "Password");
                var numberAfter = db.Members.ToList().Count();

                Assert.AreEqual(numberBefore + 1, numberAfter);
            }
        }
Exemple #7
0
 public void TearDown()
 {
     using (var db = new NSCContext())
     {
         var selectedMember =
             from m in db.Members
             where m.Username == "stephfoxton"
             select m;
         db.Members.RemoveRange(selectedMember);
         db.SaveChanges();
     }
 }
Exemple #8
0
 public void DeleteBooking(int bookingId)
 {
     using (var db = new NSCContext())
     {
         var selectedBooking =
             from b in db.Bookings
             where b.BookingId == bookingId
             select b;
         db.Bookings.RemoveRange(selectedBooking);
         db.SaveChanges();
     }
 }
Exemple #9
0
 public void TearDown()
 {
     using (var db = new NSCContext())
     {
         var selectedBookings =
             from b in db.Bookings
             where b.MemberId == 1 && b.RoomId == 2
             select b;
         db.Bookings.RemoveRange(selectedBookings);
         db.SaveChanges();
     }
 }
Exemple #10
0
        public void UPDATEBookingDetails_DatabaseIsUpdated()
        {
            _crudBookings.UpdateBooking(8, 4, 7, Convert.ToDateTime("11/03/2021"), TimeSpan.FromHours(1.00));

            using (var db = new NSCContext())
            {
                var SelectedBooking = db.Bookings.Where(c => c.BookingId == 8).FirstOrDefault();

                Assert.AreEqual(4, SelectedBooking.RoomId);
                Assert.AreEqual(7, SelectedBooking.SportId);
                Assert.AreEqual(Convert.ToDateTime("11/03/2021"), SelectedBooking.DateNeeded);
                Assert.AreEqual(TimeSpan.FromHours(1.00), SelectedBooking.TimeSlot);
            }
        }
Exemple #11
0
        public void DELETEBooking_NumberDecreasesBy1()
        {
            using (var db = new NSCContext())
            {
                //for this test, create a booking in program NSC_Model so we know the bookingid
                //find from sql query

                var numberBefore = db.Bookings.ToList().Count();
                _crudBookings.DeleteBooking(1016);
                var numberAfter = db.Bookings.ToList().Count();

                Assert.AreEqual(numberBefore, numberAfter + 1);
            }
        }
Exemple #12
0
        public void UpdateBooking(int bookingid, int roomId, int sportId, DateTime datePicked, TimeSpan timePicked)
        {
            using (var db = new NSCContext())
            {
                SelectBooking = db.Bookings.Where(c => c.BookingId == bookingid).FirstOrDefault();
                //setSelectedRider(email);
                SelectBooking.RoomId     = roomId;
                SelectBooking.SportId    = sportId;
                SelectBooking.DateNeeded = datePicked;
                SelectBooking.TimeSlot   = timePicked;

                db.SaveChanges();
            }
        }
Exemple #13
0
        public void CreateMember(string username, string password)
        {
            using (var db = new NSCContext())
            {
                var newMember = new Member
                {
                    Username = username.Trim(),
                    Passwrd  = password.Trim()
                };

                db.Members.Add(newMember);
                db.SaveChanges();
            }
        }
Exemple #14
0
        public void CreateBooking(int memberId, int roomId, int sportId, DateTime datePicked, TimeSpan timePicked)
        {
            using (var db = new NSCContext())
            {
                var newBooking = new Booking
                {
                    MemberId   = memberId,
                    RoomId     = roomId,
                    SportId    = sportId,
                    DateNeeded = datePicked,
                    TimeSlot   = timePicked
                };

                db.Bookings.Add(newBooking);
                db.SaveChanges();
            }
        }
Exemple #15
0
        public void DELETEMember_NumberDecreasesBy1()
        {
            using (var db = new NSCContext())
            {
                var newMember = new Member
                {
                    Username = "******",
                    Passwrd  = "Password"
                };
                db.Members.Add(newMember);
                db.SaveChanges();
                var numberBefore = db.Members.ToList().Count();

                _crudMembers.DeleteMember("stephfoxton", "Password");
                var numberAfter = db.Members.ToList().Count();

                Assert.AreEqual(numberBefore, numberAfter + 1);
            }
        }
Exemple #16
0
        public void DeleteMember(string username, string password)
        {
            using (var db = new NSCContext())
            {
                var selectedMemberBookings =
                    from b in db.Bookings
                    join m in db.Members on b.MemberId equals m.MemberId
                    where m.Username == username && m.Passwrd == password
                    select b;
                db.Bookings.RemoveRange(selectedMemberBookings);
                db.SaveChanges();

                var selectedMember =
                    from m in db.Members
                    where m.Username == username && m.Passwrd == password
                    select m;
                db.Members.RemoveRange(selectedMember);
                db.SaveChanges();
            }
        }
Exemple #17
0
        public void READMemberAdded_CorrectDetails()
        {
            using (var db = new NSCContext())
            {
                var numberBefore = db.Members.ToList().Count();
                _crudMembers.CreateMember("stephfoxton", "Password");
                var numberAfter = db.Members.ToList().Count();

                Assert.AreEqual(numberBefore + 1, numberAfter);

                var createdMember =
                    from m in db.Members
                    where m.Username == "stephfoxton"
                    select m;

                foreach (var c in createdMember)
                {
                    Assert.AreEqual("Password", c.Passwrd);
                    //Assert.AreEqual(1, c.MemberId);
                }
            }
        }
Exemple #18
0
        public void READBookingAdded_CorrectDetails()
        {
            using (var db = new NSCContext())
            {
                var numberBefore = db.Bookings.ToList().Count();
                _crudBookings.CreateBooking(1, 2, 4, Convert.ToDateTime("10/03/2021"), TimeSpan.FromHours(1.00));
                var numberAfter = db.Bookings.ToList().Count();

                Assert.AreEqual(numberBefore + 1, numberAfter);

                var createdBooking =
                    from b in db.Bookings
                    where b.MemberId == 1 && b.RoomId == 2
                    select b;

                foreach (var c in createdBooking)
                {
                    Assert.AreEqual(2, c.RoomId);
                    Assert.AreEqual(4, c.SportId);
                    Assert.AreEqual(Convert.ToDateTime("10/03/2021"), c.DateNeeded);
                    Assert.AreEqual(TimeSpan.FromHours(1.00), c.TimeSlot);
                }
            }
        }
Exemple #19
0
 static void Main(string[] args)
 {
     using (var db = new NSCContext())
     {
     }
 }