Ejemplo n.º 1
0
        public async Task <bool> Edit(string id, DoctorServiceModel doctorServiceModel)
        {
            Department departmentFromDb = await GetDepartmentFromDb(doctorServiceModel);

            if (departmentFromDb == null)
            {
                throw new ArgumentNullException(nameof(departmentFromDb));
            }

            Doctor doctorFromDb = await context.Doctors.SingleOrDefaultAsync(doctor => doctor.Id == id);

            if (doctorFromDb == null)
            {
                throw new ArgumentNullException(nameof(doctorFromDb));
            }

            doctorFromDb.FirstName   = doctorServiceModel.FirstName;
            doctorFromDb.LastName    = doctorServiceModel.LastName;
            doctorFromDb.PhoneNumber = doctorServiceModel.PhoneNumber;
            doctorFromDb.Department  = departmentFromDb;


            context.Doctors.Update(doctorFromDb);
            int result = await context.SaveChangesAsync();

            return(result > 0);
        }
Ejemplo n.º 2
0
        public async Task <bool> Create(string password, DoctorServiceModel doctorServiceModel)
        {
            var user = new HospitalMSUser {
                UserName = doctorServiceModel.Email, Email = doctorServiceModel.Email
            };
            var userCreateResult = await userManager.CreateAsync(user, password);

            if (userCreateResult.Succeeded)
            {
                user.EmailConfirmed = true;
                user.IsFirstLogin   = false;

                await userManager.AddToRoleAsync(user, GlobalConstants.DoctorRoleName);
            }

            Department departmentFromDb = await GetDepartmentFromDb(doctorServiceModel);

            if (departmentFromDb == null)
            {
                throw new ArgumentNullException(nameof(departmentFromDb));
            }

            doctorServiceModel.HospitalMSUserId = user.Id;

            Doctor doctor = AutoMapper.Mapper.Map <Doctor>(doctorServiceModel);

            doctor.Department = departmentFromDb;
            context.Doctors.Add(doctor);

            int result = await context.SaveChangesAsync();

            return(result > 0);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(string id, DoctorEditInputModel doctorEditInputModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(doctorEditInputModel));
            }

            DoctorServiceModel doctorServiceModel = AutoMapper.Mapper.Map <DoctorServiceModel>(doctorEditInputModel);

            await doctorService.Edit(id, doctorServiceModel);

            return(Redirect("/Doctor/All"));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(DoctorCreateInputModel doctorCreateInputModel)
        {
            if (!ModelState.IsValid)
            {
                await GetAllDepartments();

                return(View(doctorCreateInputModel));
            }

            DoctorServiceModel doctorServiceModel = AutoMapper.Mapper.Map <DoctorServiceModel>(doctorCreateInputModel);

            await doctorService.Create(doctorCreateInputModel.Password, doctorServiceModel);


            return(Redirect("/Doctor/All"));
        }
Ejemplo n.º 5
0
 private Task <Department> GetDepartmentFromDb(DoctorServiceModel doctorServiceModel)
 {
     return(context.Departments
            .SingleOrDefaultAsync(department => department.Name == doctorServiceModel.Department.Name));
 }