Ejemplo n.º 1
0
        public async Task <IActionResult> UpdatePatient(PatientWriteDtoModel model)
        {
            // map Dto model to Internal Model  , We can Use auto mapper packeges

            var entity = _patientRepository.Get(model.PatientId);

            if (entity == null)
            {
                return(NotFound());
            }



            entity.DateOfBirth  = model.DateOfBirth;
            entity.EmailAddress = model.EmailAddress;
            entity.MetaData     = model.MetaData.Select(x => new MetaDataModel {
                Key = x.Key, Value = x.Value
            }).ToList();
            entity.PatientName = model.PatientName;
            entity.OfficialID  = model.OfficialID;


            _patientRepository.Update(entity);

            if (_patientRepository.SaveChanges())
            {
                return(Ok(new { message = "Patient updated successfully." }));
            }

            return(BadRequest());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreatePatient(PatientWriteDtoModel model)
        {
            // we can use auto mapper to map internal model to dto
            PatientModel entity = new PatientModel
            {
                DateOfBirth  = model.DateOfBirth,
                EmailAddress = model.EmailAddress,
                MetaData     = model.MetaData.Select(x => new MetaDataModel {
                    Key = x.Key, Value = x.Value
                }).ToList(),
                PatientName = model.PatientName,
                OfficialID  = model.OfficialID
            };

            _patientRepository.Add(entity);
            if (_patientRepository.SaveChanges())
            {
                return(Ok(new { message = "Patient added successfully." }));
            }

            return(BadRequest());
        }