public async Task <IActionResult> AddPatientProfile([FromBody] PatientProfileViewModel formdata)
        {
            try
            {
                if (formdata == null)
                {
                    return(BadRequest(new JsonResult(new { message = "object sent from client is null." })));
                }
                else if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object sent from client."));
                }
                var patientProfile     = _mapper.Map <PatientProfileDto>(formdata);
                var patientProfileData = await _patientProfileService.AddPatientProfile(patientProfile);

                if (patientProfileData == Guid.Empty)
                {
                    return(NotFound());
                }
                patientProfile.Id = patientProfileData;
                var addedPatientProfile = _mapper.Map <PatientProfileViewModel>(patientProfile);
                return(CreatedAtAction(nameof(GetPatientProfile), new { id = patientProfileData }, addedPatientProfile));
            }
            catch (Exception e)
            {
                return(StatusCode(500, $"Something went wrong inside add patientProfile action: {e.Message}"));
            }
        }
示例#2
0
        public async Task <IActionResult> Post([FromBody] Patient patient)
        {
            try
            {
                var patients = await patientService.AddPatientProfile(patient);

                return(StatusCode((int)HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                return(NotFound(ex.Message));
            }
        }