Ejemplo n.º 1
0
        public void Add(DoctorInputModel doctorInputModel)
        {
            Doctor doctor = new Doctor()
            {
                FirstName  = doctorInputModel.FirstName,
                MiddleName = doctorInputModel.MiddleName,
                LastName   = doctorInputModel.LastName,
                Specialty  = doctorInputModel.Specialty,
                HospitalId = doctorInputModel.HospitalId
            };

            if (doctorInputModel.Address != null)
            {
                string addressId = this.addressesService.Add(doctorInputModel.Address);
                doctor.Addresses.Add(this.addressesService.GetAddress(addressId));
            }

            if (doctorInputModel.Phone != null)
            {
                string phoneId = this.phonesService.Add(doctorInputModel.Phone);
                doctor.Phones.Add(this.phonesService.GetPhone(phoneId));
            }

            if (doctorInputModel.Email != null)
            {
                string emailId = this.emailsService.Add(doctorInputModel.Email);
                doctor.Emails.Add(this.emailsService.GetEmail(emailId));
            }

            this.db.Doctors.Add(doctor);
            this.db.SaveChanges();
        }
Ejemplo n.º 2
0
        public async Task AddDoctor(DoctorInputModel inputModel)
        {
            var userManager = this.serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();
            var user        = new ApplicationUser
            {
                UserName = inputModel.LastName + "@bestpaws.eu",
                Email    = inputModel.LastName + "@bestpaws.eu",
                Doctor   = new Doctor
                {
                    FirstName      = inputModel.FirstName,
                    MiddleName     = inputModel.MiddleName,
                    LastName       = inputModel.LastName,
                    Specialization = inputModel.Specialization,
                    Biography      = inputModel.Biography,
                },
            };

            var password = this.GeneratePassword(user.UserName);

            IdentityResult result = new IdentityResult();

            result = userManager.CreateAsync(user, password).Result;

            if (result.Succeeded)
            {
                await userManager.AddToRoleAsync(user, "Doctor");
            }
            else
            {
                throw new ArgumentException(string.Format(Common.ErrorMessages.UserIsNotInDesiredRole, user, Common.GlobalConstants.DoctorRoleName));
            }

            await this.doctorRepository.SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create()
        {
            var doctor       = new DoctorInputModel();
            var specialities = await specialitiesService.GetAll <SpecialityViewModel>();

            var formModel = new CreateDoctorFormModel
            {
                Doctor       = doctor,
                Specialities = specialities,
            };

            return(View(formModel));
        }
Ejemplo n.º 4
0
        public async Task EditAsync(string id, DoctorInputModel model)
        {
            var editedDoctor = this.doctorRepository
                               .AllWithDeleted()
                               .FirstOrDefault(x => x.Id == id);

            editedDoctor.FirstName      = model.FirstName;
            editedDoctor.MiddleName     = model.MiddleName;
            editedDoctor.LastName       = model.LastName;
            editedDoctor.Biography      = model.Biography;
            editedDoctor.Specialization = model.Specialization;

            await this.doctorRepository.SaveChangesAsync();
        }