Пример #1
0
        public void AddDoctor(AddOrUpdateDoctorRequest req)
        {
            var addedDoctor = _context.Add(new Doctor {
                FirstName = req.FirstName, LastName = req.LastName, Email = req.Email
            });

            _context.SaveChanges();
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (var db = new CodeFirstDbContext())
            {
                var course = new Course
                {
                    Name        = "Algorihms",
                    Description = "gadno",
                    Materials   = "za sega njama"
                };

                //var material = "za sega njama";
                //course.Materials.Add(material);
                db.Courses.Add(course);

                var student = new Student
                {
                    Name   = "Pesho",
                    Number = 10000
                };

                student.Cources.Add(course);
                db.Students.Add(student);

                try
                {
                    db.SaveChanges();
                }
                catch (Exception exception)
                {
                    Response.Write(exception.InnerException.InnerException.Message);
                }
            }
        }
Пример #3
0
        private static void DeleteStudentById(int wantedId)
        {
            var db = new CodeFirstDbContext();

            var itemToRemove = db.Students.SingleOrDefault(x => x.Id == wantedId); // returns a single item.

            if (itemToRemove != null)
            {
                db.Students.Remove(itemToRemove);
                db.SaveChanges();
            }
        }
Пример #4
0
        public static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <CodeFirstDbContext, Configuration>());

            var db = new CodeFirstDbContext();

            var newCourse = new Course()
            {
                Name        = "Databases",
                Description = @"In this course we are learning about MSSQL, MySQL, MongoDB, ADNO.NET, 
                                DatabaseFirst & CodeFirst techniques, ENtityFramework and others."
            };
            //// db.Courses.Add(newCourse);
            //// DeleteCourseById();

            var newStudent = new Student()
            {
                FirstName     = "John",
                LastName      = "Snow",
                BirthDate     = new DateTime(1980, 04, 20, 11, 59, 59),
                Gender        = Gender.Male,
                StudentNumber = 123456789
            };
            //// db.Students.Add(newStudent);
            //// DeleteStudentById(2);

            var newHomework = new Homework()
            {
                Title                = "Code First Entity Framework",
                Attachments          = new byte[1000 * 1000 * 3],
                AttachmentsName      = "codeFirstHomework",
                AttachmentsExtension = "zip",
                CourseId             = 3,
                StudentId            = 3
            };

            db.Homeworks.Add(newHomework);

            db.SaveChanges();

            Console.WriteLine(db.Courses.Count());
            Console.WriteLine(db.Students.Count());
            Console.WriteLine(db.Homeworks.Count());
        }
Пример #5
0
 public void AddDoctor(Doctor doctor)
 {
     _context.Attach(doctor);
     _context.Add(doctor);
     _context.SaveChanges();
 }