public bool AddEvent(AEvent tourEvent) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { Event newEvent = new Event(); newEvent.TourID = System.Guid.Parse(tourEvent.TourID); newEvent.TourDate = tourEvent.TourDate; newEvent.TourGuide = tourEvent.TourGuide; newEvent.IsOn = (byte)(tourEvent.IsOn? 1 : 0); dc.Events.InsertOnSubmit(newEvent); dc.SubmitChanges(); return true; } }
public bool AddTour(ATour tour) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { Tour newTour = new Tour(); newTour.TourName = tour.TourName; newTour.TourPrice = tour.TourPrice; newTour.TourLocation = tour.TourLocation; newTour.TourArea = tour.TourArea; newTour.TourCategory = tour.TourCategory; newTour.TourDuration = (short)tour.TourDuration; newTour.TourDescription = tour.TourDescription; newTour.MinReg = (byte)tour.MinReg; newTour.MaxReg = (byte)tour.MaxReg; newTour.TourID = System.Guid.NewGuid(); dc.Tours.InsertOnSubmit(newTour); dc.SubmitChanges(); return true; } }
public bool AddReg(AReg reg) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { Registration registration = new Registration(); registration.IsSentEmail = 0; registration.IsPaid = 0; registration.Attended = 0; registration.RegFirstName = reg.RegFirstName; registration.RegLastName = reg.RegLastName; registration.RegBirthday = reg.RegBirthday; registration.TourDate = reg.TourDate; registration.TourID = System.Guid.Parse(reg.TourID); registration.UserID = System.Guid.Parse(reg.UserID); registration.RegTime = DateTime.Now; registration.WillAttend = (byte)(reg.WillAttend?1:0); registration.RegID = System.Guid.NewGuid(); dc.Registrations.InsertOnSubmit(registration); dc.SubmitChanges(); return true; } }
public bool DeleteEvent(string tourid, DateTime tourdate) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { Event row = (from c in dc.Events where (c.TourID.ToString() == tourid && c.TourDate == tourdate) select c).FirstOrDefault<Event>(); dc.Events.DeleteOnSubmit(row); // The deleted event's registrations must be deleted too. Otherwise, the sql servers throws an // exeption. List<Registration> registrations= (from r in dc.Registrations where (r.TourID.ToString() == tourid && r.TourDate == tourdate) select r).ToList(); foreach(Registration reg in registrations) { dc.Registrations.DeleteOnSubmit(reg); } dc.SubmitChanges(); return true; } }
public bool AddUser(AUser userReg) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { User user = new User(); user.RegTime = (DateTime)userReg.RegTime; user.RegIP = userReg.UserIP; user.UserFirstName = userReg.UserFirstName; user.UserLastName = userReg.UserLastName; user.UserPhone = userReg.UserPhone; user.UserEmail = userReg.UserEmail; user.UserPassword = userReg.UserPassword; user.UserBirthday = userReg.UserBirthday; user.Username = userReg.Username; user.salt = userReg.Salt; user.UserID = System.Guid.NewGuid(); dc.Users.InsertOnSubmit(user); dc.SubmitChanges(); return true; } }
public bool UpdateEmailSent(string userid, string first, string last, string tourid, DateTime tourdate, bool sentEmail) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { Registration row = (from c in dc.Registrations where (c.UserID.ToString()== userid && c.RegFirstName == first && c.RegLastName == last && c.TourID.ToString() == tourid && c.TourDate == tourdate ) select c).FirstOrDefault<Registration>(); row.IsSentEmail = (byte)(sentEmail? 1 : 0); dc.SubmitChanges(); return true; } }
public bool EditUser(AUser user) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { User row = (from c in dc.Users where (c.UserID.ToString() == user.UserID) select c).FirstOrDefault<User>(); row.UserBirthday = user.UserBirthday; row.UserEmail = user.UserEmail; row.UserFirstName = user.UserFirstName; row.UserLastName = user.UserLastName; row.Username = user.Username; row.UserPassword = user.UserPassword; row.UserPhone = user.UserPhone; row.ResetToken = user.ResetToken; row.salt = user.Salt; dc.SubmitChanges(); return true; } }
public bool EditTour(ATour tour) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { Tour row = (from c in dc.Tours where (c.TourID.ToString() == tour.TourID) select c).FirstOrDefault<Tour>(); row.MaxReg = (byte)tour.MaxReg; row.MinReg = (byte)tour.MinReg; row.TourArea = tour.TourArea; row.TourCategory = tour.TourCategory; row.TourDescription = tour.TourDescription; row.TourDuration = (short)tour.TourDuration; row.TourLocation = tour.TourLocation; row.TourName = tour.TourName; row.TourPrice = tour.TourPrice; row.ImageData = tour.ImageData; row.ImageMimeType = tour.ImageMimeType; dc.SubmitChanges(); return true; } }
public bool EditReg(AReg reg) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { Registration row = (from c in dc.Registrations where (c.RegID.ToString() == reg.RegID) select c).FirstOrDefault<Registration>(); row.IsSentEmail = (byte)(reg.IsSentEmail?1:0); row.IsPaid = (byte)(reg.IsPaid?1:0); row.Attended = (byte)(reg.Attended?1:0); row.RegFirstName = reg.RegFirstName; row.RegLastName = reg.RegLastName; row.RegBirthday = reg.RegBirthday; row.WillAttend = (byte)(reg.WillAttend?1:0); dc.SubmitChanges(); return true; } }
public bool EditEvent(AEvent tourEvent) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { if (tourEvent.TourDate == tourEvent.TourOriginalDate) // The TourDate is not changed - save the other changes { Event row = (from c in dc.Events where (c.TourID.ToString() == tourEvent.TourID && c.TourDate == tourEvent.TourDate) select c).FirstOrDefault<Event>(); row.TourGuide = tourEvent.TourGuide; row.IsOn = (byte)(tourEvent.IsOn?1:0); dc.SubmitChanges(); return true; } else // The TourDate has been changed - delete the event and create a new one with the new date. Copy the registrations with the new date { AddEvent(tourEvent); // Adding the new event (the same event with the new date) // Adding new registrations to the new event (with the new date) List<Registration> registrations = (from r in dc.Registrations where (r.TourID.ToString() == tourEvent.TourID && r.TourDate == tourEvent.TourOriginalDate) select r).ToList(); foreach (Registration reg in registrations) { AReg newReg = new AReg(); newReg.IsSentEmail = reg.IsSentEmail==1?true:false; newReg.IsPaid = reg.IsPaid==1?true:false; newReg.Attended = reg.Attended==1?true:false; newReg.RegFirstName = reg.RegFirstName; newReg.RegLastName = reg.RegLastName; newReg.RegBirthday = reg.RegBirthday; newReg.TourDate = tourEvent.TourDate; newReg.TourID = tourEvent.TourID; newReg.UserID = reg.UserID.ToString(); newReg.WillAttend = reg.WillAttend==1?true:false; AddReg(newReg); } DeleteEvent(tourEvent.TourID, tourEvent.TourOriginalDate); // this function also deletes the previous date regisrations dc.SubmitChanges(); return true; } } }
public bool DeleteUser(string id) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { User row = (from c in dc.Users where (c.UserID.ToString() == id) select c).FirstOrDefault<User>(); dc.Users.DeleteOnSubmit(row); // The deleted User's registrations must be deleted too. Otherwise, the sql servers throws an // exeption. List<Registration> registrations = (from r in dc.Registrations where (r.UserID.ToString() == id) select r).ToList(); foreach (Registration reg in registrations) { dc.Registrations.DeleteOnSubmit(reg); } dc.SubmitChanges(); return true; } }
public bool DeleteTour(string id) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { Tour row = (from c in dc.Tours where (c.TourID.ToString() == id) select c).FirstOrDefault<Tour>(); dc.Tours.DeleteOnSubmit(row); // The deleted Tour's events must be deleted too. Otherwise, the sql servers throws an // exeption. List<Event> events = (from e in dc.Events where (e.TourID.ToString() == id) select e).ToList(); foreach (Event e in events) { DeleteEvent(e.TourID.ToString(), e.TourDate); // this will also deleted all registrations for the event } dc.SubmitChanges(); return true; } }
public bool DeleteReg(string id) { using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext()) { Registration row = (from c in dc.Registrations where (c.RegID.ToString() == id) select c).FirstOrDefault<Registration>(); dc.Registrations.DeleteOnSubmit(row); dc.SubmitChanges(); return true; } }