示例#1
0
        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();
     }
 }
示例#3
0
 public void UpdateTermEntity(TermEntity termEntityToUpdate)
 {
     using (var db = new PlutoContext())
     {
         db.Entry(termEntityToUpdate).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
示例#4
0
 public void DeleteTermEntity(TermEntity termEntityToDelete)
 {
     using (var db = new PlutoContext())
     {
         db.Entry(termEntityToDelete).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
示例#5
0
 public void DeleteRegisteredSubjectEntity(RegisteredSubjectEntity registeredSubjectEntityToDelete)
 {
     using (var db = new PlutoContext())
     {
         db.Entry(registeredSubjectEntityToDelete).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
示例#6
0
 public void DeleteSubjectEntity(SubjectEntity subjectEntityToDelete)
 {
     using (var db = new PlutoContext())
     {
         db.Entry(subjectEntityToDelete).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
示例#7
0
 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);
        }
示例#9
0
        public int AddSubjectEntity(SubjectEntity subjectEntity)
        {
            using (var db = new PlutoContext())
            {
                db.Subjects.Add(subjectEntity);
                db.SaveChanges();
            }

            return(subjectEntity.Id);
        }
示例#10
0
        public int AddTermEntity(TermEntity termEntity)
        {
            using (var db = new PlutoContext())
            {
                db.Terms.Add(termEntity);
                db.SaveChanges();
            }

            return(termEntity.Id);
        }
示例#11
0
        public int AddRegisteredSubjectEntity(RegisteredSubjectEntity registeredSubjectEntity)
        {
            using (var db = new PlutoContext())
            {
                db.RegisteredSubjects.Add(registeredSubjectEntity);
                db.SaveChanges();
            }

            return(registeredSubjectEntity.Id);
        }
示例#12
0
        public static void RemoveCourse()
        {
            using (var context = new PlutoContext())
            {
                var course = context.Courses.Find(6);

                context.Courses.Remove(course);

                context.SaveChanges();
            }
        }
示例#13
0
        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();
        }
示例#14
0
        public static void UpdateCourse()
        {
            using (var context = new PlutoContext())
            {
                var course = context.Courses.Find(4);

                course.Name     = "New Name";
                course.AuthorId = 2;

                context.SaveChanges();
            }
        }
示例#15
0
        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();
            }
        }
示例#16
0
        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();
        }
示例#17
0
        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();
        }
示例#18
0
        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();
        }
示例#19
0
        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();
        }
示例#20
0
        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();
        }
示例#21
0
        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();
            }
        }
示例#22
0
        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();
            }
        }
示例#23
0
        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();
        }
示例#24
0
        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();
            }
        }
示例#25
0
 public virtual void Save()
 {
     _context.SaveChanges();
 }
示例#26
0
 public int Complete()
 {
     return(_context.SaveChanges());
 }
示例#27
0
 protected void Save() => _context.SaveChanges();