public async Task <IActionResult> UpdatePatientProfile(Guid id, [FromBody] PatientProfileViewModel formdata)
        {
            try
            {
                if (formdata == null)
                {
                    return(BadRequest(new JsonResult(new { message = "object sent from client is null." })));
                }
                if (id == null || id == Guid.Empty)
                {
                    return(BadRequest(new JsonResult(new { message = "object sent from client is null." })));
                }
                if (id != formdata.Id)
                {
                    return(BadRequest(new JsonResult(new { message = "please ensure you are updating right object" })));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object sent from client."));
                }
                var patientProfile   = _mapper.Map <PatientProfileDto>(formdata);
                var patientProfileId = await _patientProfileService.UpdatePatientProfile(patientProfile);

                if (patientProfileId == Guid.Empty)
                {
                    return(NotFound());
                }
                patientProfile.Id = patientProfileId;
                return(CreatedAtAction(nameof(GetPatientProfile), new { id = patientProfileId }, _mapper.Map <PatientProfileViewModel>(patientProfile)));
            }
            catch (Exception e)
            {
                return(StatusCode(500, new JsonResult(new { message = $"Something went wrong inside update patientProfile action: {e.Message}" })));
            }
        }
Пример #2
0
        public async Task <IActionResult> Put([FromBody] Patient patient)
        {
            var emailid = (Request.HttpContext.User.Identity as ClaimsIdentity).FindFirst("EmailId").Value;

            try
            {
                var resultPatient = patientService.ViewProfile(emailid);
                if (resultPatient != null)
                {
                    return(Ok(await patientService.UpdatePatientProfile(emailid, patient)));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(NotFound(ex.Message));
            }
        }