Example #1
0
        public void ToEntity_DoctorEqualsViewModel()
        {
            DoctorViewModel testDoctor = new DoctorViewModel
            {
                DoctorId    = 1,
                FirstName   = "Andrew",
                LastName    = "Moshko",
                MiddleName  = "Victor",
                Age         = "18",
                Weight      = "83",
                Height      = "195",
                Email       = "*****@*****.**",
                PhoneNumber = "+380995135682",
                HomeNumber  = "-",
                Sex         = "man",
                Condition   = "test Doctor",
                Text        = "default string"
            };

            Doctor doctor = testDoctor.ToEntity();

            Assert.Equal(testDoctor.DoctorId, doctor.DoctorId);
            Assert.Equal(testDoctor.FirstName, doctor.FirstName);
            Assert.Equal(testDoctor.LastName, doctor.LastName);
            Assert.Equal(testDoctor.MiddleName, doctor.MiddleName);
            Assert.Equal(testDoctor.Age, doctor.Age);
            Assert.Equal(testDoctor.Weight, doctor.Weight);
            Assert.Equal(testDoctor.Height, doctor.Height);
            Assert.Equal(testDoctor.PhoneNumber, doctor.PhoneNumber);
            Assert.Equal(testDoctor.HomeNumber, doctor.HomeNumber);
            Assert.Equal(testDoctor.Sex, doctor.Sex);
            Assert.Equal(testDoctor.Condition, doctor.Condition);
            Assert.Equal(testDoctor.Text, doctor.Text);
        }
Example #2
0
        public async Task <DoctorViewModel> AddDoctorAsync(DoctorViewModel doctorViewModel)
        {
            try
            {
                Doctor doctor = await this.repo.AddDoctorAsync(doctorViewModel.ToEntity());

                doctorViewModel.ToModel(doctor);

                return(doctorViewModel);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        public async Task AddDoctor_SuccessResult()
        {
            DoctorLogic doctorData = new DoctorLogic(this.repository.Object);

            // Create model
            DoctorViewModel model = new DoctorViewModel()
            {
                DoctorId    = 1,
                FirstName   = "Andrew",
                LastName    = "Moshko",
                MiddleName  = "Victor",
                Age         = "18",
                Weight      = "83",
                Height      = "195",
                Email       = "*****@*****.**",
                PhoneNumber = "+380995135682",
                HomeNumber  = "-",
                Sex         = "man",
                Condition   = "test Doctor",
                Text        = "default string"
            };

            // Create object Doctor
            Doctor doctor = model.ToEntity();

            // this.ultraRepository.Setup(x => x.AddDoctorAsync(model.ToEntity()))
            //    .Returns(Task.FromResult(doctor)).Verifiable();
            this.repository.Setup(x => x.AddDoctorAsync(doctor))
            .ReturnsAsync(doctor).Verifiable();

            // Run Code
            var result = await doctorData.AddDoctorAsync(model); // AddAsync(mockModel.Object);

            // validate true result
            Assert.Equal(result.DoctorId, model.DoctorId);
            Assert.Equal(result.FirstName, model.FirstName);
            Assert.Equal(result.LastName, model.LastName);
            Assert.Equal(result.MiddleName, model.MiddleName);
            Assert.Equal(result.Age, model.Age);
            Assert.Equal(result.Weight, model.Weight);
            Assert.Equal(result.Height, model.Height);
            Assert.Equal(result.Email, model.Email);
            Assert.Equal(result.PhoneNumber, model.PhoneNumber);
            Assert.Equal(result.HomeNumber, model.HomeNumber);
            Assert.Equal(result.Sex, model.Sex);
            Assert.Equal(result.Condition, model.Condition);
            Assert.Equal(result.Text, model.Text);
        }
Example #4
0
        public async Task DeleteDoctor_SuccessResult()
        {
            DoctorLogic doctorData = new DoctorLogic(this.repository.Object);

            // Create model
            DoctorViewModel model = new DoctorViewModel()
            {
                DoctorId    = 1,
                FirstName   = "Andrew",
                LastName    = "Moshko",
                MiddleName  = "Victor",
                Age         = "18",
                Weight      = "83",
                Height      = "195",
                Email       = "*****@*****.**",
                PhoneNumber = "+380995135682",
                HomeNumber  = "-",
                Sex         = "man",
                Condition   = "test Doctor",
                Text        = "default string"
            };

            // Create object Doctor
            Doctor doctor = model.ToEntity();

            // this.ultraRepository.Setup(x => x.AddDoctorAsync(model.ToEntity()))
            //    .Returns(Task.FromResult(doctor)).Verifiable();
            this.repository.Setup(x => x.AddDoctorAsync(doctor))
            .ReturnsAsync(doctor).Verifiable();

            this.repository.Setup(x => x.DeleteDoctorAsync(doctor.DoctorId))
            .ReturnsAsync(true).Verifiable();


            // Run Code
            var result = await doctorData.DeleteDoctorAsync(model.DoctorId); // AddAsync(mockModel.Object);

            Assert.True(result);
        }
 public ActionResult CreateDoctor(DoctorViewModel vm)
 {
     using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
     {
         var doctor = vm.ToEntity();
         if (vm.Files != null)
         {
             var uploadFolderPath =
                 HostingEnvironment.MapPath(string.Concat(SiteConstants.Instance.UploadFolderPath,
                                                          "ImageDoctors"));
             if (!Directory.Exists(uploadFolderPath))
             {
                 Directory.CreateDirectory(uploadFolderPath);
             }
             foreach (var file in vm.Files)
             {
                 if (file != null)
                 {
                     // If successful then upload the file
                     var uploadResult = AppHelpers.UploadFile(file, uploadFolderPath,
                                                              LocalizationService);
                     if (!uploadResult.UploadSuccessful)
                     {
                         TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                         {
                             Message     = uploadResult.ErrorMessage,
                             MessageType = GenericMessages.danger
                         };
                         unitOfWork.Rollback();
                         return(Json(new
                         {
                             Result = false,
                             Message = "Vui lòng kiểm tra lại file thông tin",
                         }, JsonRequestBehavior.AllowGet));
                     }
                     doctor.Avatar = uploadResult.UploadedFileName;
                     // Add the filename to the database
                     //var uploadedFile = new UploadedFile
                     //{
                     //    Filename = uploadResult.UploadedFileName,
                     //    question.UrlFile = uploadResult.UploadedFileName;
                     //};
                     //_uploadedFileService.Add(uploadedFile);
                 }
             }
         }
         if (doctor.DepartmentId != null)
         {
             doctor.DepartmentManage = _doctorService.GetDepartmentById(doctor.DepartmentId);
         }
         _doctorService.Add(doctor);
         try
         {
             unitOfWork.Commit();
             return(Json(new
             {
                 Result = true,
                 Message = "Thành công",
             }, JsonRequestBehavior.AllowGet));
         }
         catch (Exception ex)
         {
             unitOfWork.Rollback();
             LoggingService.Error(ex);
             return(Json(new
             {
                 Result = false,
                 Message = "Vui lòng kiểm tra lại thông tin",
             }, JsonRequestBehavior.AllowGet));
         }
     }
 }