コード例 #1
0
        public void Add([FromBody] AddDoctorDto doctorDto)
        {
            using (var dbContext = new ApplicationDbContext())
            {
                var userId = GetUserId();

                ValidateDoctorData(dbContext, userId, doctorDto.SpecialtyId, doctorDto.SubspecialtyId, doctorDto.WorkingHours);

                var doctor = new Clinic_Doctor
                {
                    FirstName          = doctorDto.FirstName,
                    LastName           = doctorDto.LastName,
                    Email              = doctorDto.Email,
                    PhoneNumber        = doctorDto.PhoneNumber,
                    SpecialtyId        = doctorDto.SpecialtyId,
                    SubspecialtyId     = doctorDto.SubspecialtyId,
                    ConsultationLength = doctorDto.ConsultationLength,
                    WorkingHours       = new List <Clinic_WorkingHours>(),
                    State              = DoctorStateEnum.Active,
                    UserId             = userId
                };

                dbContext.Clinic_Doctors.Add(doctor);
                dbContext.SaveChanges();

                doctor.WorkingHours = doctorDto.WorkingHours.Select(wh => new Clinic_WorkingHours {
                    DayNumber = wh.DayNumber, Start = wh.Start, End = wh.End
                }).ToList();
                dbContext.SaveChanges();
            }
        }
コード例 #2
0
        public int AddDoctor(AddDoctorDto data)
        {
            var newDoctor = AutoMapper.Mapper.Map <AddDoctorDto, Doctor>(data);

            _unitOfWork.DoctorRepository.Add(newDoctor);
            _unitOfWork.Commit();

            return(newDoctor.DoctorId);
        }
コード例 #3
0
        public async Task <IActionResult> Add([FromForm] AddDoctorDto doctorDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Root.Errors.ToString()));
            }

            var doctor = _mapper.Map <AddDoctorDto, Doctor>(doctorDto);
            await _context.Doctors.AddAsync(doctor);

            await _context.SaveChangesAsync();

            return(Ok(_mapper.Map <Doctor, DoctorResponse>(doctor)));
        }
        public async Task <IActionResult> AddDoctor([FromBody] AddDoctorDto doctorDto)
        {
            int doctorId = _doctorService.AddDoctor(doctorDto);

            var user = new User
            {
                UserName   = doctorDto.Email,
                Email      = doctorDto.Email,
                FirstName  = doctorDto.FirstName,
                LastName   = doctorDto.LastName,
                FacilityId = doctorDto.FacilityId,
                DoctorId   = doctorId,
                Role       = Role.FacilityDoctor
            };

            var result = await _userManager.CreateAsync(user, doctorDto.Password);

            return(Json(JsonResultData.Success()));
        }