public Timesheet SaveTimesheet(Timesheet model) { var timesheet = PlutoContext.Timesheets.Add(model); PlutoContext.SaveChanges(); return(timesheet); }
public void DeleteAttendanceEntity(AttendanceEntity attendanceEntityToDelete) { using (var db = new PlutoContext()) { db.Entry(attendanceEntityToDelete).State = EntityState.Deleted; db.SaveChanges(); } }
public void UpdateTermEntity(TermEntity termEntityToUpdate) { using (var db = new PlutoContext()) { db.Entry(termEntityToUpdate).State = EntityState.Modified; db.SaveChanges(); } }
public void DeleteTermEntity(TermEntity termEntityToDelete) { using (var db = new PlutoContext()) { db.Entry(termEntityToDelete).State = EntityState.Deleted; db.SaveChanges(); } }
public void DeleteRegisteredSubjectEntity(RegisteredSubjectEntity registeredSubjectEntityToDelete) { using (var db = new PlutoContext()) { db.Entry(registeredSubjectEntityToDelete).State = EntityState.Deleted; db.SaveChanges(); } }
public void DeleteSubjectEntity(SubjectEntity subjectEntityToDelete) { using (var db = new PlutoContext()) { db.Entry(subjectEntityToDelete).State = EntityState.Deleted; db.SaveChanges(); } }
public void UpdateSubjectEntity(SubjectEntity subjectEntityToUpdate) { using (var db = new PlutoContext()) { db.Entry(subjectEntityToUpdate).State = EntityState.Modified; db.SaveChanges(); } }
public int AddAttendanceEntity(AttendanceEntity attendanceEntity) { using (var db = new PlutoContext()) { db.Attendances.Add(attendanceEntity); db.SaveChanges(); } return(attendanceEntity.Id); }
public int AddSubjectEntity(SubjectEntity subjectEntity) { using (var db = new PlutoContext()) { db.Subjects.Add(subjectEntity); db.SaveChanges(); } return(subjectEntity.Id); }
public int AddTermEntity(TermEntity termEntity) { using (var db = new PlutoContext()) { db.Terms.Add(termEntity); db.SaveChanges(); } return(termEntity.Id); }
public int AddRegisteredSubjectEntity(RegisteredSubjectEntity registeredSubjectEntity) { using (var db = new PlutoContext()) { db.RegisteredSubjects.Add(registeredSubjectEntity); db.SaveChanges(); } return(registeredSubjectEntity.Id); }
public static void RemoveCourse() { using (var context = new PlutoContext()) { var course = context.Courses.Find(6); context.Courses.Remove(course); context.SaveChanges(); } }
private static void WithCascadeDelete() { //courses and tags var context = new PlutoContext(); var course = context.Courses.Find(6); //Single(c => c.Id == 6) context.Courses.Remove(course); context.SaveChanges(); }
public static void UpdateCourse() { using (var context = new PlutoContext()) { var course = context.Courses.Find(4); course.Name = "New Name"; course.AuthorId = 2; context.SaveChanges(); } }
public static void RemoveAuthor() { using (var context = new PlutoContext()) { var author = context.Authors.Include(a => a.Courses).Single(a => a.Id == 2); context.Courses.RemoveRange(author.Courses); context.Authors.Remove(author); context.SaveChanges(); } }
private void AddCourse_Click(object sender, RoutedEventArgs e) { _context.Courses.Add(new Course { AuthorId = 1, Name = "New Course at " + DateTime.Now.ToShortDateString(), Description = "Description", FullPrice = 49, Level = 1 }); _context.SaveChanges(); }
static void Main() { PlutoContext context = new PlutoContext(new DbContextOptions <PlutoContext>()); context.Courses.Add(new Course("Math", "Basic Math", CourseLevel.Beginner, 150, new Author())); context.SaveChanges(); Console.WriteLine("Hello World!"); var course = context.Courses.Find(1); Console.ReadKey(); }
private static void WithoutCascadeDelete() { //authors and courses var context = new PlutoContext(); //Eager load para sus cursos var author = context.Authors.Include(a => a.Courses).Single(a => a.Id == 2); context.Courses.RemoveRange(author.Courses); context.Authors.Remove(author); context.SaveChanges(); }
public void RemoveData() { var existingTags = context.Tags.ToList(); var existingAuthors = context.Authors.ToList(); var existingCourses = context.Courses.ToList(); foreach (var course in existingCourses) { context.Courses.Remove(course); } foreach (var tag in existingTags) { context.Tags.Remove(tag); } foreach (var author in existingAuthors) { context.Authors.Remove(author); } context.SaveChanges(); }
static void Main(string[] args) { var context = new PlutoContext(); var course = new Course { Name = "new course", Description = "new descr", FullPrice = 19.95f, Level = 1, AuthorId = 1, //using FK properties, better for web apps //Author = context.Authors.Single(a => a.Id == 1) //Using an existing object in context }; context.Courses.Add(course); context.SaveChanges(); }
public static void AddCourseWithAuthorId() { using (var context = new PlutoContext()) { var courseWithAuthorId = new Course { Name = "Course with author id", Description = "Descrpition", FullPrice = 19.95f, Level = Course.CourseLevel.Beginner, AuthorId = 1 }; context.Add(courseWithAuthorId); context.SaveChanges(); } }
public static void AddCourseWithAuthorObject() { using (var context = new PlutoContext()) { var author = context.Authors.Single(q => q.Id == 1); var courseWithAuthorObject = new Course { Name = "Course with author object", Description = "Descrpition", FullPrice = 19.95f, Level = Course.CourseLevel.Beginner, Author = author }; context.Add(courseWithAuthorObject); context.SaveChanges(); } }
static void Main(string[] args) { var context = new PlutoContext(); var course = context.Courses.Find(4, 1, 2); //Single(c => c.Id == 4) course.Name = "New name"; course.AuthorId = 2; //Change tracker var entries = context.ChangeTracker.Entries(); foreach (var entry in entries) { entry.Reload(); Console.WriteLine(entry.State); } context.SaveChanges(); }
public static void AddCourseWithAttachedAuthor() { using (var context = new PlutoContext()) { var newAuthor = new Author() { Id = 1, Name = "Mosh Hamedani" }; context.Authors.Attach(newAuthor); var courseWithAttachedAuthor = new Course { Name = "Course With Attached Author", Description = "Descrpition", FullPrice = 19.95f, Level = Course.CourseLevel.Beginner, Author = newAuthor }; context.Courses.Add(courseWithAttachedAuthor); context.SaveChanges(); } }
public virtual void Save() { _context.SaveChanges(); }
public int Complete() { return(_context.SaveChanges()); }
protected void Save() => _context.SaveChanges();