Exemple #1
0
        private static void SeedDatabase(ClinicsDB db)
        {
            var proc1 = new Procedure() { Name = "Blood test", Price = 50.00m };
            var proc2 = new Procedure() { Name = "MRI", Price = 1000.00m };

            var specialty = new Specialty() { Name = "Internist" };

            var specialist = new Specialist()
            {
                FirstName = "Gregory",
                LastName = "House",
                SpecialtyId = specialty.Id
            };

            var manip = new Manipulation()
            {
                Date = DateTime.Now,
                SpecialistId = specialist.Id
            };

            manip.Procedures.Add(proc1);
            manip.Procedures.Add(proc2);

            db.Procedures.Add(proc1);
            db.Procedures.Add(proc2);
            db.Specialties.Add(specialty);
            db.Specialists.Add(specialist);
            db.Manipulations.Add(manip);

            SaveChanges(db);
        }
        private void ImportSpecialists(IClinicsData data)
        {
            var allSpecialists = mongoDb.GetCollection<BsonDocument>("Specialists").FindAll();

            foreach (var specialist in allSpecialists)
            {
                var mongoId = this.GetValue(specialist, "Id");
                var idGuid = new Guid(mongoId);

                var firstName = this.GetValue(specialist, "FirstName");
                var middleName = this.GetValue(specialist, "MiddleName");
                var lastName = this.GetValue(specialist, "LastName");

                var title = this.GetValue(specialist, "TitleId");
                var titleGuid = new Guid(title);

                var specialty = this.GetValue(specialist, "SpecialtyId");
                var specialtyGuid = new Guid(specialty);

                var uin = this.GetValue(specialist, "Uin");

                var existingRecord = data.Specialists.All()
                    .Where(s => s.Id.Equals(idGuid))
                    .FirstOrDefault();

                if (existingRecord == null)
                {
                    Specialist newSpecialist = new Specialist
                    {
                        Id = idGuid,
                        FirstName = firstName,
                        MiddleName = middleName,
                        LastName = lastName,
                        SpecialtyId = specialtyGuid,
                        TitleId = titleGuid,
                        Uin = uin
                    };

                    data.Specialists.Add(newSpecialist);
                }
                else
                {
                    existingRecord.FirstName = firstName;
                    existingRecord.MiddleName = middleName;
                    existingRecord.LastName = lastName;
                    existingRecord.SpecialtyId = specialtyGuid;
                    existingRecord.TitleId = titleGuid;
                    existingRecord.Uin = uin;
                }
            }
        }