public bool LoadById(Guid id) { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { tblEvent tevent = dc.tblEvents.Where(e => e.Id == id).FirstOrDefault(); if (tevent != null) { this.Id = tevent.Id; this.Name = tevent.Name; this.Type = tevent.Type; this.StartDate = tevent.StartDate; this.EndDate = tevent.EndDate; //Gage - Error Came from trying to pull a UserId from the Event Table, the user ID is part of the tblEventShowing Junction table -- i.e. A user can have many events and an event can have many users // otherwise looks good return(true); } else { return(false); } } } catch (Exception ex) { throw ex; } }
public void LoadStudents() // Load student attending event { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { Students = new List <Student>(); var eventShowings = dc.tblEventShowings.Where(e => e.EventId == this.Id); if (eventShowings != null) { foreach (var eventShowing in eventShowings) { tblUser user = dc.tblUsers.Where(u => u.Id == eventShowing.UserId).FirstOrDefault(); tblStudent student = dc.tblStudents.Where(s => s.UserId == user.Id).FirstOrDefault(); if (student != null) { Students.Add(new Student(student.Id, student.StudentFirstName, student.StudentLastName, student.Phone, student.Email, student.UserId, student.School, student.Field, student.ProfilePicture)); } } } } } catch (Exception ex) { throw ex; } }
public bool Insert() { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { tblEvent tevent = new tblEvent(); tevent.Id = Guid.NewGuid(); tevent.Name = this.Name; tevent.Type = this.Type; tevent.StartDate = Convert.ToDateTime(this.StartDate); tevent.EndDate = Convert.ToDateTime(this.EndDate); //the error was the same thing as above all good now :) dc.tblEvents.Add(tevent); dc.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public void LoadUsers() // Load users attending event { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { Users = new List <User>(); var eventShowings = dc.tblEventShowings.Where(e => e.EventId == this.Id); if (eventShowings != null) { foreach (var eventShowing in eventShowings) { tblUser user = dc.tblUsers.Where(u => u.Id == eventShowing.UserId).FirstOrDefault(); if (user != null) { Users.Add(new User(user.Id, user.UserName)); } } } } } catch (Exception ex) { throw ex; } }
public void StudentUpdate() { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { tblStudent student = dc.tblStudents.Where(s => s.Id == this.StudentID).FirstOrDefault(); tblUser user = dc.tblUsers.Where(u => u.Id == student.UserId).FirstOrDefault(); if (student != null && user != null) { student.StudentFirstName = (this.StudentFirstName == null) ? student.StudentFirstName: this.StudentFirstName; student.StudentLastName = (this.StudentLastName == null) ? student.StudentLastName: this.StudentLastName; student.Phone = this.Phone = (this.Phone == null) ? student.Phone : this.Phone; student.Email = (this.Email == null) ? student.Email : this.Email; student.School = (this.School == null) ? student.School : this.School; student.Field = (this.FieldOfStudy == null) ? student.Field : this.FieldOfStudy; user.UserName = (this.UserName == null) ? user.UserName : this.UserName; user.Password = (this.Password == null) ? user.Password : this.Password; student.ProfilePicture = (this.ProfilePicture == null) ? student.ProfilePicture : this.ProfilePicture; dc.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public bool UserInsert() { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { if (dc.tblUsers.Where(u => u.UserName == this.UserName).FirstOrDefault() == null) { tblUser user = new tblUser(); user.Id = Guid.NewGuid(); user.UserName = this.UserName; user.Password = GetHash(); dc.tblUsers.Add(user); dc.SaveChanges(); return(true); } else { return(false); } } } catch (Exception ex) { throw ex; } }
public bool UserLoadByUserName(string username) { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { tblUser user = dc.tblUsers.Where(u => u.UserName == username).FirstOrDefault(); if (user != null) { this.BaseUserID = user.Id; this.UserName = user.UserName; return(true); } else { return(false); } } } catch (Exception ex) { throw ex; } }
public bool AddUserToEvent(Guid userId) { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { tblEventShowing eventShowing = dc.tblEventShowings.Where(e => (e.UserId == userId) && (e.EventId == this.Id)).FirstOrDefault(); if (eventShowing == null) { eventShowing = new tblEventShowing(); eventShowing.Id = Guid.NewGuid(); eventShowing.UserId = userId; eventShowing.EventId = this.Id; dc.tblEventShowings.Add(eventShowing); dc.SaveChanges(); return(true); } else { return(false); // User already attending event. } } } catch (Exception ex) { throw ex; } }
public void EmployerUpdate(Guid employerId) { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { tblEmployer employer = dc.tblEmployers.Where(e => e.Id == employerId).FirstOrDefault(); tblUser user = dc.tblUsers.Where(u => u.Id == employer.UserId).FirstOrDefault(); if (employer != null && user != null) { employer.RepresentativeFirstName = (this.RepresentativeFirstName == null) ? employer.RepresentativeFirstName : this.RepresentativeFirstName; employer.RepresentativeLastName = (this.RepresentativeLastName == null) ? employer.RepresentativeLastName : this.RepresentativeLastName; employer.Phone = (this.Phone == null) ? employer.Phone: this.Phone; employer.Email = (this.Email == null) ? employer.Email : this.Email; employer.Industry = (this.Industry == null) ? employer.Industry : this.Industry; employer.OrganizationName = (this.OrganizationName == null) ? employer.OrganizationName: this.OrganizationName; user.UserName = (this.UserName == null) ? user.UserName : this.UserName; user.Password = (this.Password == null) ? user.Password: this.Password; employer.ProfilePicture = (this.ProfilePicture == null) ? employer.ProfilePicture: this.ProfilePicture; dc.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public bool UserLoadById(Guid baseUserId) { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { tblUser user = dc.tblUsers.Where(u => u.Id == baseUserId).FirstOrDefault(); if (user != null) { this.BaseUserID = user.Id; this.UserName = user.UserName; this.Password = user.Password; return(true); } else { return(false); } } } catch (Exception ex) { throw ex; } }
public void InsertTest() { Byte[] arrBYTE = new Byte[10000]; Student student = new Student(); student.UserName = "******"; student.Password = "******"; student.StudentFirstName = "Sally"; student.StudentLastName = "TheStudent"; student.Email = "*****@*****.**"; student.FieldOfStudy = "Computer Programmer"; student.School = "SomeSchool"; student.Phone = "666-666-6666"; student.ProfilePicture = arrBYTE; student.StudentInsert(); ITIndeedEntities dc = new ITIndeedEntities(); var users = dc.tblUsers; int expectedUsers = 25; int actualUsers = users.Count(); var students = dc.tblStudents; int expectedStudents = 2; int actualStudents = students.Count(); Assert.AreEqual(expectedStudents + expectedUsers, actualStudents + actualUsers); }
public void InsertTest() { Employer employer = new Employer(); Byte[] arrBYTE = new Byte[10000]; employer.UserName = "******"; employer.Password = "******"; employer.RepresentativeFirstName = "Joe"; employer.RepresentativeLastName = "Joe"; employer.Email = "*****@*****.**"; employer.Industry = "Clowning"; employer.OrganizationName = "Clown Store"; employer.Phone = "888-888-8888"; employer.ProfilePicture = arrBYTE; employer.EmployerInsert(); ITIndeedEntities dc = new ITIndeedEntities(); var users = dc.tblUsers; int expectedUsers = 8; int actualUsers = users.Count(); var employers = dc.tblEmployers; int expectedEmployers = 5; int actualEmployers = employers.Count(); Assert.AreEqual(expectedEmployers + expectedUsers, actualEmployers + actualUsers); }
public bool AddUserInterestedInEvent(Guid userId) { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { tblUserInterested eventInterested = dc.tblUserInteresteds.Where(e => (e.UserId == userId) && (e.EventId == this.Id)).FirstOrDefault(); // Check to see if user already joined event if (eventInterested == null) { eventInterested = new tblUserInterested(); eventInterested.Id = Guid.NewGuid(); eventInterested.UserId = userId; eventInterested.EventId = this.Id; dc.tblUserInteresteds.Add(eventInterested); dc.SaveChanges(); return(true); } else { return(false); // User already interested in event. } } } catch (Exception ex) { throw ex; } }
public void LoadUserImage() { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { this.ProfilePicture = dc.tblEmployers.Where(e => e.Id == this.EmployerId).FirstOrDefault().ProfilePicture; } } catch (Exception ex) { throw ex; } }
public void StudentListLoad() { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { dc.tblStudents.ToList().ForEach(s => Add(new Student(s.Id, s.StudentFirstName, s.StudentLastName, s.Phone, s.Email, s.UserId, s.Field, s.School, s.ProfilePicture))); } } catch (Exception ex) { throw ex; } }
public void UserListLoad() { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { dc.tblUsers.ToList().ForEach(u => Add(new User(u.Id, u.UserName, u.Password))); } } catch (Exception ex) { throw ex; } }
public void Load() { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { dc.tblEvents.ToList().ForEach(e => Add(new Event(e.Id, e.Name, e.StartDate, e.EndDate, e.Type))); } } catch (Exception ex) { throw ex; } }
//this is what is taking so long // cache on server? public void EmployerListLoad() { try { this.Clear(); using (ITIndeedEntities dc = new ITIndeedEntities()) { dc.tblEmployers.ToList().ForEach(e => Add(new Employer(e.Id, e.RepresentativeFirstName, e.RepresentativeLastName, e.Phone, e.Email, e.OrganizationName, e.Industry, e.UserId, e.ProfilePicture))); } } catch (Exception ex) { throw ex; } }
public void DeleteTest() { User user = new User(); user.BaseUserID = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); user.UserDelete(); ITIndeedEntities dc = new ITIndeedEntities(); var users = dc.tblUsers; int expected = 10; int actual = users.Count(); Assert.AreEqual(expected, actual); }
public void LoadCountOfUsersInterested() { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { var count = dc.tblUserInteresteds.Where(e => e.EventId == this.Id).Count(); // User already joined event this.InterestedCount = count; } } catch (Exception ex) { throw ex; } }
public void AddUserInterestedInEvent() { Event eventObject = new Event(); eventObject.Id = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); eventObject.AddUserInterestedInEvent(Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")); ITIndeedEntities dc = new ITIndeedEntities(); var userInterestedInEvent = dc.tblUserInteresteds; int expecteduserInterestedInEvent = 7; int actualuserInterestedInEvent = userInterestedInEvent.Count(); Assert.AreEqual(expecteduserInterestedInEvent, actualuserInterestedInEvent); }
public void AddUserToEvent() { Event eventObject = new Event(); eventObject.Id = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); eventObject.AddUserToEvent(Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")); ITIndeedEntities dc = new ITIndeedEntities(); var eventShowings = dc.tblEventShowings; int expectedEventShowings = 5; int actualEventShowings = eventShowings.Count(); Assert.AreEqual(expectedEventShowings, actualEventShowings); }
public void InsertTest() { //UserName cannot be the same for two Users//Business Rule User user = new User(); user.UserName = "******"; user.Password = "******"; user.UserInsert(); ITIndeedEntities dc = new ITIndeedEntities(); var users = dc.tblUsers; int expected = 6; int actual = users.Count(); Assert.AreEqual(expected, actual); }
public void DeleteTest() { Event eventObject = new Event(); eventObject.Id = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); eventObject.Delete(); ITIndeedEntities dc = new ITIndeedEntities(); var events = dc.tblEventShowings; var eventShowings = dc.tblEvents; int expected = 3 + 3; int actual = events.Count() + eventShowings.Count(); Assert.AreEqual(expected, actual); }
public void InsertTest() { Event eventObject = new Event(); eventObject.StartDate = Convert.ToDateTime("12/20/2017"); eventObject.EndDate = Convert.ToDateTime("12/21/2017"); eventObject.Name = "EventName"; eventObject.Type = "EventType"; eventObject.Insert(); ITIndeedEntities dc = new ITIndeedEntities(); var events = dc.tblEventShowings; int expectedEvents = 4; int actualEvents = events.Count(); Assert.AreEqual(expectedEvents, actualEvents); }
public bool UserLogin() { try { if (UserName != null && UserName != string.Empty) { if (Password != null && Password != string.Empty) { ITIndeedEntities dc = new ITIndeedEntities(); tblUser user = dc.tblUsers.FirstOrDefault(u => u.UserName == this.UserName); if (user != null) { if (user.Password == this.GetHash()) // Checks Password Correct { // Successful login BaseUserID = user.Id; return(true); } else { return(false); } } else { return(false); } } else { return(false); } } else { return(false); } } catch (Exception e) { throw e; } }
public void UserDelete() { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { tblUser user = dc.tblUsers.Where(u => u.Id == this.BaseUserID).FirstOrDefault(); if (user != null) { dc.tblUsers.Remove(user); dc.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public void DeleteTest() { Student student = new Student(); student.StudentID = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); student.StudentDelete(); ITIndeedEntities dc = new ITIndeedEntities(); var users = dc.tblUsers; int expectedUsers = 19; int actualUsers = users.Count(); var students = dc.tblStudents; int expectedStudents = 14; int actualStudents = students.Count(); Assert.AreEqual(expectedStudents + expectedUsers, actualStudents + actualUsers); }
public void EmployerDelete() { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { tblEmployer employer = dc.tblEmployers.Where(e => e.Id == this.EmployerId).FirstOrDefault(); tblUser user = dc.tblUsers.Where(u => u.Id == employer.UserId).FirstOrDefault(); if (employer != null & user != null) { dc.tblEmployers.Remove(employer); dc.tblUsers.Remove(user); dc.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public void UserUpdate() { try { using (ITIndeedEntities dc = new ITIndeedEntities()) { tblUser user = dc.tblUsers.Where(u => u.Id == this.BaseUserID).FirstOrDefault(); if (user != null) { user.UserName = this.UserName; user.Password = GetHash(); dc.SaveChanges(); } } } catch (Exception ex) { throw ex; } }