Пример #1
0
        public async Task <ApiResponse <PatientBookingModel> > CreateBookingAsync(
            IEnumerable <Claim> claims,
            HttpRequest request)
        {
            if (!CheckUserIdInClaims(claims, out int userId))
            {
                return(ApiResponse <PatientBookingModel> .BadRequest());
            }

            PatientBookingModel bookingModel = _mapper.SafeMap <PatientBookingModel>(request.Form);

            if (bookingModel == null)
            {
                return(ApiResponse <PatientBookingModel> .BadRequest(BookingErrorMessages.WrongBookingDataFormat));
            }

            var clinicClinician = await _unitOfWork.ClinicClinicianRepository
                                  .GetClinicClinicianAsync(bookingModel.ClinicId, bookingModel.ClinicianId);

            var validatioErrorResult = CheckPatientBookingModel(bookingModel, clinicClinician, claims);

            if (validatioErrorResult != null)
            {
                return(validatioErrorResult);
            }

            var newBooking = _mapper.Mapper.Map <Booking>(bookingModel);

            newBooking.PatientId         = userId;
            newBooking.ClinicClinicianId = clinicClinician.Id;
            AddNewDocuments(request, userId, newBooking);

            var result = _unitOfWork.BookingRepository.Create(newBooking);

            try
            {
                await _unitOfWork.SaveChangesAsync();

                return(ApiResponse <PatientBookingModel> .Ok(_mapper.Mapper.Map <PatientBookingModel>(result)));
            }
            catch
            {
                return(ApiResponse <PatientBookingModel> .InternalError(BookingErrorMessages.UpdateError));
            }
        }
Пример #2
0
        public async Task <ApiResponse <LoginResultModel> > RegisterClinicianAsync(HttpRequest request)
        {
            var registerModel = _mapper.SafeMap <ClinicianRegisterModel>(request.Form);

            if (registerModel == null)
            {
                return(ApiResponse <LoginResultModel> .BadRequest());
            }

            var validationError = ValidateRegistrationModel(registerModel);

            if (validationError != null)
            {
                return(validationError);
            }

            var clinics = await _unitOfWork.ClinicRepository.GetAsync(c => registerModel.ClinicsId.Contains(c.Id));

            if (clinics.Count() != registerModel.ClinicsId.Count())
            {
                return(ApiResponse <LoginResultModel> .ValidationError("Unexisting clinic is selected."));
            }

            var clinicianRegistrationDto = _mapper.Mapper.Map <ClinicianRegistrationDto>(registerModel);

            clinicianRegistrationDto.RelatedClinics = clinics;
            clinicianRegistrationDto.PasswordHash   = Hashing.HashPassword(registerModel.Password);
            clinicianRegistrationDto.Role           = UserRole.Clinician;

            try
            {
                var user = await _unitOfWork.ClinicianRepository.CreateClinicianAsync(clinicianRegistrationDto);

                var loginResult = await GenerateTokenAsync(user);

                return(ApiResponse <LoginResultModel> .Ok(loginResult));
            }
            catch (Exception)
            {
                return(ApiResponse <LoginResultModel> .InternalError());
            }
        }