public IActionResult Register(TherapistDto therapistDto)
        {
            var therapist        = _mapper.Map <Therapist>(therapistDto);
            var validationResult = _validator.Validate(therapist);

            if (!ModelState.IsValid)
            {
                var errors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).ToList();
                return(BadRequest(errors));
            }
            else if (!validationResult.IsValid)
            {
                var validationErrors = validationResult.Errors.Select(x => $"{x.PropertyName} failed validation: ${x.ErrorMessage}.");
                return(BadRequest(string.Join(";", validationErrors)));
            }

            Therapist result = _therapistRepository.Create(therapist, therapistDto.Password);

            if (result != null)
            {
                return(Ok("Therapist created."));
            }

            return(StatusCode(500, "There was a problem trying to create therapist."));
        }
        public async Task <IActionResult> Edit(TherapistDto therapistDto)
        {
            var therapist        = _mapper.Map <Therapist>(therapistDto);
            var validationResult = _validator.Validate(therapist);

            if (!ModelState.IsValid)
            {
                var errors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).ToList();
                return(BadRequest(errors));
            }
            else if (!validationResult.IsValid)
            {
                var validationErrors = validationResult.Errors.Select(x => $"{x.PropertyName} failed validation: ${x.ErrorMessage}.");
                return(BadRequest(string.Join(";", validationErrors)));
            }

            int result = await _therapistRepository.Update(therapist).ConfigureAwait(false);

            if (result == 1)
            {
                return(Ok("Therapist updated."));
            }

            return(StatusCode(500, "There was a problem trying to update therapist."));
        }
Esempio n. 3
0
        public IActionResult Register(TherapistDto therapistDto)
        {
            var therapist = _mapper.Map <Therapist> (therapistDto);

            if (!ModelState.IsValid)
            {
                var errors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).ToList();
                return(BadRequest(errors));
            }

            this._therapistRepository.Create(therapist, therapistDto.Password);
            return(Ok());
        }