Esempio n. 1
0
        public async Task <ActionResult <HospitalProfile> > CreateProfile(HospitalProfileVM newProfileVm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var createdProfile = await _repository.CreateProfile(newProfileVm);

            if (createdProfile == null)
            {
                ModelState.AddErrorMessage("Unable to create profile");
                return(BadRequest(ModelState));
            }

            return(Ok(createdProfile));
        }
Esempio n. 2
0
        public async void CreateProfileTest()
        {
            var options = new DbContextOptionsBuilder <BefordingTestContext>()
                          .UseInMemoryDatabase(databaseName: "BefordingTestDb")
                          .Options;
            var context = new BefordingTestContext(options);

            var repository = new ProfileRepository(context, _userInfoServiceMock.Object, _logRepositoryMock.Object);

            var dummyHospitalVM = new HospitalProfileVM()
            {
                Address        = "a",
                NameOfHospital = "UUU",
                Rate           = 1
            };
            var result = await repository.CreateProfile(dummyHospitalVM);

            Assert.True(result.GetType() == typeof(HospitalProfile));
            Assert.True(result.Id == 1);
        }
Esempio n. 3
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);
        }