public void ChooseMember(string username) { using (var db = new NSCContext()) { SelectMember = db.Members.Where(e => e.Username.Trim() == username.Trim()).FirstOrDefault(); } }
public List <Sport> AllSports() { using (var db = new NSCContext()) { return(db.Sports.ToList()); } }
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); } }
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()); } }
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); } }
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); } }
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(); } }
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(); } }
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(); } }
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); } }
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); } }
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(); } }
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(); } }
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(); } }
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); } }
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(); } }
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); } } }
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); } } }
static void Main(string[] args) { using (var db = new NSCContext()) { } }