public IActionResult Create()
        {
            CreateExamInputModel input = new CreateExamInputModel
            {
                CourseItems = this.coursesService.GetAllAsSelectListItems(),
            };

            return(this.View(input));
        }
        public async Task <Exam> Create(CreateExamInputModel model)
        {
            var exam = Mapper.Map <Exam>(model);

            await this.examRepository.AddAsync(exam);

            await this.examRepository.SaveChangesAsync();

            return(exam);
        }
示例#3
0
        public async Task CreateAsync(CreateExamInputModel input)
        {
            Exam exam = new Exam
            {
                Name       = input.Name,
                CourseId   = input.CourseId,
                LecturerId = input.LecturerId,
                StartDate  = input.StartDate,
                EndDate    = input.EndDate,
            };

            await this.examsRepository.AddAsync(exam);

            await this.examsRepository.SaveChangesAsync();
        }
        public async Task <IActionResult> Create(CreateExamInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input.CourseItems = this.coursesService.GetAllAsSelectListItems();
                return(this.View(input));
            }

            ApplicationUser user = await this.userManager.GetUserAsync(this.User);

            input.LecturerId = user.Id;
            await this.examsService.CreateAsync(input);

            this.TempData["Message"] = "Exam successfully created!";

            return(this.RedirectToAction(nameof(this.All)));
        }
 public ActionResult Create(int orderId)
 {
     try
     {
         var order = this.orderService.GetOrderById <DetailsOrderViewModel>(orderId);
         var model = new CreateExamInputModel()
         {
             CourseId   = order.CourseId,
             CustomerId = order.CustomerId
         };
         return(this.View(model));
     }
     catch (Exception e)
     {
         return(this.View("_Error", e.Message));
     }
 }
示例#6
0
        public async Task <IActionResult> CreateExam(CreateExamInputModel examInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(examInputModel));
            }

            try
            {
                await this.examService.CreateExam(examInputModel);
            }
            catch (NullReferenceException e)
            {
                return(this.View(examInputModel));
            }

            return(Redirect("~/Doctor/Users/GetAllUsers"));
        }
        public ActionResult Create(CreateExamInputModel model)
        {
            try
            {
                if (!this.ModelState.IsValid)
                {
                    return(this.View(model));
                }

                var exam = this.examService.Create(model).GetAwaiter().GetResult();

                return(this.RedirectToAction(nameof(All)));
            }
            catch
            {
                return(this.View(model));
            }
        }
示例#8
0
        public async Task <bool> CreateExam(CreateExamInputModel examInputModel)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(examInputModel.Condition) ||
                    String.IsNullOrWhiteSpace(examInputModel.Diagnose) ||
                    String.IsNullOrWhiteSpace(examInputModel.Prescription))
                {
                    throw new NullReferenceException("Condition, Doagnose, Prescription should be valid values.");
                }


                var examdb = new Exam()
                {
                    Condition    = examInputModel.Condition,
                    Date         = DateTime.UtcNow,
                    Diagnose     = examInputModel.Diagnose,
                    DoctorId     = this.db.Users.FirstOrDefault(d => d.UserName == examInputModel.DoctorUserName).Id,
                    PatientId    = this.db.Users.FirstOrDefault(p => p.UserName == examInputModel.PatientUserName).Id,
                    Prescription = examInputModel.Prescription
                };


                this.db.Exams.Add(examdb);
            }
            catch (NullReferenceException e)
            {
                return(false);
            }

            int result = this.db.SaveChanges();

            if (result > 0)
            {
                return(true);
            }

            return(false);
        }
示例#9
0
        public async void GetUserWhitEmptyModelShoulThrowExeption()
        {
            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"
            };

            await examService.CreateExam(exam);

            dbContext.Appointments.Where(x => true).ToList();


            await Assert.ThrowsAsync <ArgumentException>(async() => await usersService.GetUser(""));
        }
示例#10
0
        public async void CreateExamWithNoPRescriptionShoulReturnFalse()
        {
            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 exam = new CreateExamInputModel()
            {
                Condition       = "good",
                DoctorUserName  = "******",
                Diagnose        = "ssdcsds",
                PatientUserName = "******",
                Prescription    = ""
            };

            bool result = await examService.CreateExam(exam);


            Assert.False(result);
        }