public async Task <bool> EditExam(ExamEditInputModel inputModel) { var examDb = new Exam(); if (String.IsNullOrWhiteSpace(inputModel.Id)) { throw new NullReferenceException("Id must not be null or whitespace"); } try { examDb = this.db.Exams.FirstOrDefault(x => x.Id == inputModel.Id); } catch (Exception e) { throw new NullReferenceException("There was an error in EditExam"); } examDb.Condition = inputModel.Condition; examDb.Diagnose = inputModel.Diagnose; examDb.Prescription = inputModel.Prescription; int result = this.db.SaveChanges(); if (result > 0) { return(true); } return(false); }
public async Task <IActionResult> EditExam(ExamEditInputModel model) { if (!this.ModelState.IsValid) { return(this.Redirect("~/Doctor/Users/GetAllUsers")); } try { await this.examService.EditExam(model); } catch (Exception e) { return(this.Redirect("~/Doctor/Users/GetAllUsers")); } return(this.Redirect("~/Doctor/Users/GetAllUsers")); }
public async Task <IActionResult> EditExam(string examId) { var exam = new SingelExamViewModel(); try { exam = await this.examService.GetSingelExam(examId); } catch (Exception e) { return(this.Redirect("~/Doctor/Users/GetAllUsers")); } this.ViewData["Exam"] = exam; var emptyExam = new ExamEditInputModel(); emptyExam.Condition = exam.Condition; emptyExam.Diagnose = exam.Diagnose; emptyExam.Prescription = exam.Prescription; emptyExam.Id = exam.Id; return(this.View(emptyExam)); }
public async void EditExamShoulReturnFalse() { var options = new DbContextOptionsBuilder <EClinicDbContext>() .UseInMemoryDatabase(databaseName: "Appointment_CreateAppointment") .Options; var dbContext = new EClinicDbContext(options); //var mockUserStore = new Mock<IUserStore<EClinicUser>>(); //var mockRoleManager = new Mock<IUserRoleStore<EClinicUser>>(); //var userManager = new UserManager<EClinicUser>(mockUserStore.Object, null, null, null, null, null, null, null, null); var userManager = MockHelpers.MockUserManager <EClinicUser>().Object; var examService = new Mock <ExamService>(dbContext).Object; var appointmentService = new Mock <AppointmentService>(dbContext).Object; var usersService = new Mock <UsersService>(dbContext, userManager, examService).Object; AutoMapperConfig.RegisterMappings(typeof(SetingViewModel).GetTypeInfo().Assembly); var AdminUserToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Ivo", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "Nqkyde Tam 35", Age = 25, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; var userToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Petyr", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "I tuk i tam", Age = 30, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; dbContext.Users.Add(AdminUserToAdd); dbContext.Users.Add(userToAdd); dbContext.SaveChanges(); var date = new DateTime(2019, 08, 03, 09, 00, 00); await appointmentService.CreateAppointment("*****@*****.**", "*****@*****.**", date); var exam = new CreateExamInputModel() { Condition = "good", DoctorUserName = "******", Diagnose = "adss", PatientUserName = "******", Prescription = "sdfsdd" }; var examInputModel = new ExamEditInputModel(); bool result = await examService.CreateExam(exam); await Assert.ThrowsAsync <NullReferenceException>(() => examService.EditExam(examInputModel)); }