Esempio n. 1
0
 private async void fillMockDatabase(int numberOfElements, BefordingTestContext context)
 {
     for (int i = 0; i < numberOfElements; i++)
     {
         var dummyHospital = new HospitalProfile()
         {
             Address        = "" + i,
             NameOfHospital = "UUU",
             Rate           = i
         };
         context.Profiles.Add(dummyHospital);
         await context.SaveChangesAsync();
     }
 }
Esempio n. 2
0
        public async Task <ActionResult <Patient> > UpdateProfile(HospitalProfile updatedProfile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _repository.UpdateProfile(updatedProfile);

            if (result == null)
            {
                ModelState.AddErrorMessage("Unable to update profile");
                return(BadRequest(ModelState));
            }
            return(Ok(result));
        }
Esempio n. 3
0
        private void CreateUser(HospitalProfile hospital)
        {
            Console.WriteLine("Create Users");

            var servie       = Container.Resolve <IUserManagementService>();
            var configServie = Container.Resolve <IConsultationConfigurationService>();
            var risContext   = Container.Resolve <RisProContext>();
            var users        = risContext.Set <User>().AsQueryable().ProjectTo <UserDto>();

            foreach (var u in users)
            {
                u.Roles      = configServie.GetRoles().ToList();
                u.HospitalID = hospital.UniqueID;
                servie.SaveUser(u);
            }
        }
Esempio n. 4
0
        public HospitalProfileDto GetHospital(string userID)
        {
            //get hos info by userid
            HospitalProfile hospitalProfile = (from h in _DBContext.Set <HospitalProfile>()
                                               join o in _DBContext.Set <UserExtention>() on h.UniqueID equals o.HospitalID
                                               where o.UniqueID == userID
                                               select h).FirstOrDefault();

            if (hospitalProfile != null)
            {
                return(Mapper.Map <HospitalProfile, HospitalProfileDto>(hospitalProfile));
            }

            return(new HospitalProfileDto {
                UniqueID = "1"
            });
        }
Esempio n. 5
0
        public async Task <HospitalProfile> UpdateProfile(HospitalProfile updatedProfile)
        {
            try
            {
                var profileToUpdate = await _context.Profiles.AsNoTracking().FirstOrDefaultAsync(x => x.Id == updatedProfile.Id);

                profileToUpdate = updatedProfile;
                _context.Profiles.Update(profileToUpdate);
                await _context.SaveChangesAsync();

                return(profileToUpdate);
            }
            catch (Exception ex)
            {
                await _logRepository.AddLog(UserId, ex.Message, updatedProfile.Id, false);

                return(null);
            }
        }
Esempio n. 6
0
        private HospitalProfile CreateHospital()
        {
            Console.WriteLine("Create Hospital");

            var context = Container.Resolve <ConsultationContext>();
            var profile = new HospitalProfile
            {
                UniqueID       = Guid.NewGuid().ToString(),
                LastEditUser   = "******",
                HospitalName   = "重医",
                IsConsultation = true,
                DicomPrefix    = "Arbin",
                LastEditTime   = DateTime.Now
            };

            context.Set <HospitalProfile>().Add(profile);
            context.SaveChanges();
            return(profile);
        }
Esempio n. 7
0
        public async void IntegrationTestDeleteProfile()
        {
            var options = new DbContextOptionsBuilder <BefordingTestContext>()
                          .UseInMemoryDatabase(databaseName: "BefordingTestDb")
                          .Options;
            var context = new BefordingTestContext(options);

            var logRepository = new LogRepository(context, _userInfoServiceMock.Object);

            var profileRepository = new ProfileRepository(context, _userInfoServiceMock.Object, logRepository);

            var dummyHospital = new HospitalProfile()
            {
                Address        = "Address",
                NameOfHospital = "UUU",
                Rate           = 0
            };

            context.Profiles.Add(dummyHospital);
            await context.SaveChangesAsync();

            Assert.True(context.Profiles.FirstOrDefaultAsync(x => x.Address == "Address") != null);
            Assert.True(context.Profiles.FirstOrDefaultAsync(x => x.Id == 1) != null);
            Assert.True(await context.Profiles.CountAsync() == 1);

            await profileRepository.DeleteProfileAdmin(1);

            Assert.True(await context.Profiles.CountAsync() == 0);

            Assert.True(await context.Logs.CountAsync() == 0);

            context.Profiles.Add(dummyHospital);
            await context.SaveChangesAsync();

            await profileRepository.DeleteProfileAdmin(-1);

            Assert.True(await context.Logs.CountAsync() == 1);
        }
Esempio n. 8
0
        public async Task <HospitalProfile> CreateProfile(HospitalProfileVM newProfileVm)
        {
            var dummyProfile = new HospitalProfile()
            {
                UserId         = UserId,
                NameOfHospital = newProfileVm.NameOfHospital,
                Address        = newProfileVm.Address,
                Rate           = newProfileVm.Rate
            };

            try
            {
                _context.Profiles.Add(dummyProfile);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                await _logRepository.AddLog(UserId, ex.Message);

                return(null);
            }
            return(dummyProfile);
        }