示例#1
0
        public IActionResult CreatePatientDetails([FromBody] PatientDetailCreateDto pdDto)
        {
            int Userid = 0;

            int.TryParse(User.Identity.Name, out Userid);



            if (pdDto == null || Userid == 0)
            {
                return(BadRequest(ModelState));
            }
            if (_pdRepo.Exists(Userid))
            {
                ModelState.AddModelError("", "This user has already a profile!");
                return(StatusCode(404, ModelState));
            }

            var obj = _mapper.Map <PatientDetail>(pdDto);

            obj.UserId = Userid;
            if (!_pdRepo.CreatePatientDetail(obj))
            {
                ModelState.AddModelError("", $"Something went wrong when creating the record {Userid}");
                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetPatientDetails", new { version = HttpContext.GetRequestedApiVersion().ToString(), id = obj.UserId }, obj));
        }
示例#2
0
        public IActionResult CreatePatientDetailsWithUser([FromBody] PatientDetailCreateDto pdDto)
        {
            if (pdDto == null)
            {
                return(BadRequest(ModelState));
            }

            bool ifUserNameUnique = !_pdRepo.Exists(pdDto.Email);

            if (pdDto.Email != null && !ifUserNameUnique)
            {
                return(BadRequest(new { message = "This email already exists" }));
            }
            var user = _userRepo.Register(pdDto.Email, "dummypassword");

            if (user == null)
            {
                return(BadRequest(new { message = "Error while registering" }));
            }

            var obj = _mapper.Map <PatientDetail>(pdDto);

            obj.UserId = user.Id;
            if (!_pdRepo.CreatePatientDetail(obj))
            {
                ModelState.AddModelError("", $"Something went wrong when creating the record {user.Id}");
                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetPatientDetails", new { version = HttpContext.GetRequestedApiVersion().ToString(), id = obj.UserId }, obj));
        }