public static void delete(int? assignmentID, SchedulerContext dbcontext) { if (assignmentID == null) { return; } Assignment a = dbcontext.Assignments.Find(assignmentID); dbcontext.Assignments.Remove(a); dbcontext.SaveChanges(); }
public static Role getRoleByID(int roleID) { Role role = new Role(); using (var sc = new SchedulerContext()) { role = sc.Roles.Where(r => r.ID == roleID).SingleOrDefault(); } return role; }
public static List<Role> getAll() { List<Role> roles = new List<Role>(); using (var sc = new SchedulerContext()) { roles = sc.Roles.ToList(); } return roles; }
public static List<Person> getAll() { List<Person> persons = new List<Person>(); using (var sc = new SchedulerContext()) { persons = sc.Persons.ToList(); } return persons; }
public static Role getRoleByName(string Name) { Role role = new Role(); using (var sc = new SchedulerContext()) { role = sc.Roles.Where(r => r.Name == Name).SingleOrDefault(); } return role; }
public static List<Event> getAll() { List<Event> events = new List<Event>(); using (var sc = new SchedulerContext()) { events = sc.Events.ToList(); } return events; }
public static void delete(int? assignmentID) { if (assignmentID == null) { return; } using (var sc = new SchedulerContext()) { Assignment a = sc.Assignments.Find(assignmentID); sc.Assignments.Remove(a); sc.SaveChanges(); } }
public static Person getPersonByID(int? personID) { if (personID == null) { return null; } Person person = new Person(); using (var sc = new SchedulerContext()) { person = sc.Persons.Where(p => p.ID == personID).SingleOrDefault(); } return person; }
public static void delete(int? personID) { if (personID == null) { return; } using (var sc = new SchedulerContext()) { Person p = sc.Persons.Find(personID); // also remove any assignments associated with person p //p.Assignments = Assignment.getAssignmentsByPersonID(p.ID); //foreach (Assignment assignment in p.Assignments) //{ // Assignment.delete(assignment.ID); //} sc.Persons.Remove(p); sc.SaveChanges(); } }
public static void delete(int? eveID) { if (eveID == null) { return; } using (var sc = new SchedulerContext()) { Event p = sc.Events.Find(eveID); // also remove assignments associated with event p //p.Assignments = Assignment.getAssignmentsByEvent(p.ID); //foreach (Assignment assignment in p.Assignments) //{ // sc.Assignments.Remove(assignment); // sc.SaveChanges(); //} sc.Events.Remove(p); sc.SaveChanges(); } }
public void save() { if (this.ID <= 0) { //new person if (this.FirstName != null && this.FirstName.Length > 0 && this.LastName != null && this.LastName.Length > 0 && this.Email != null && this.Email.Length > 0) { using (var sc = new SchedulerContext()) { sc.Persons.Add(this); sc.SaveChanges(); } } } else { //update existing if (this.FirstName != null && this.FirstName.Length > 0 && this.LastName != null && this.LastName.Length > 0 && this.Email != null && this.Email.Length > 0) { using (var sc = new SchedulerContext()) { sc.Persons.Attach(this); sc.Entry(this).State = EntityState.Modified; sc.SaveChanges(); } } } }
public static Event getEventByID(int eventID) { Event eve = new Event(); using (var sc = new SchedulerContext()) { eve = sc.Events.Where(e => e.ID == eventID).SingleOrDefault(); } return eve; }
public void save() { if (this.ID <= 0) { //new person if (this.Name != null && this.Name.Length > 0 && this.Room != null && this.Room.Length > 0 && this.EventDate != null && this.StartTime != null && this.EndTime != null) { using (var sc = new SchedulerContext()) { sc.Events.Add(this); sc.SaveChanges(); } } } else { //update existing if (this.Name != null && this.Name.Length > 0 && this.Room != null && this.Room.Length > 0 && this.EventDate != null && this.StartTime != null && this.EndTime != null) { using (var sc = new SchedulerContext()) { sc.Events.Attach(this); sc.Entry(this).State = EntityState.Modified; sc.SaveChanges(); } } } }
public static List<Assignment> getAssignmentsByEvent(int eventID) { List<Assignment> Assignments = new List<Assignment>(); using (var sc = new SchedulerContext()) { Assignments = sc.Assignments.Where(a => a.EventID == eventID).ToList(); } return Assignments; }
public static List<Assignment> getAll() { List<Assignment> assignments = new List<Assignment>(); using (var sc = new SchedulerContext()) { assignments = sc.Assignments.ToList(); } return assignments; }
public static List<Assignment> getAssignmentsByPersonID(int? personID) { if (personID == null) { return null; } List<Assignment> Assignments = new List<Assignment>(); using (var sc = new SchedulerContext()) { Assignments = sc.Assignments.Where(a => a.PersonID == personID).ToList(); } return Assignments; }