Beispiel #1
0
        public async Task <IActionResult> RegisterAsync([FromBody] RegisterPatientDTO model)
        {
            if (ModelState.IsValid) //The RegisterPatientDTO Errormessage fires before
            {
                try
                {
                    await _patientServices.CheckIfEmailExistAsync(model.Email);
                }
                catch (AppException ex)
                {
                    return(BadRequest(new { message = ex.Message }));
                }

                var mappedUser = _mapper.Map <EntityPatient>(model);
                mappedUser.SocialSecurityNumber = model.Year + model.Month + model.Day + model.LastDigits;

                try
                {
                    await _patientServices.RegisterAsync(mappedUser);

                    return(Ok(model));
                }
                catch (AppException ex)
                {
                    return(BadRequest(new { message = ex.Message }));
                }
            }
            return(BadRequest(ModelState));
        }