public async Task <BaseResponse <Patient> > Handle(UpdatePatientCommand request, CancellationToken cancellationToken)
        {
            var response = new BaseResponse <Patient> ()
            {
                ReponseName = nameof(UpdatePatientCommand), Content = new List <Patient> ()
                {
                }
            };
            var entity = await _patientRepository.GetOneAsync(p => p.Id == request.Id);

            if (entity == null)
            {
                response.Status  = ResponseType.Error;
                response.Message = $"{nameof(Patient)} not found.";
                response.Content = null;
            }
            else
            {
                _mapper.Map(request, entity, typeof(UpdatePatientCommand), typeof(Patient));
                await _patientRepository.UpdateAsync(entity);

                response.Status  = ResponseType.Success;
                response.Message = $"{nameof(Patient)} updated successfully.";
                response.Content.Add(entity);
            }
            return(response);
        }
        public async Task <IActionResult> UpdatePatient(Guid patientId, PatientForUpdateDto patient)
        {
            // add error handling
            var command = new UpdatePatientCommand(patientId, patient);
            await _mediator.Send(command);

            return(NoContent());
        }
        /// <summary>
        /// 更新患者信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <Unit> Handle(UpdatePatientCommand request, CancellationToken cancellationToken)
        {
            var data = await _patientRepository.TableNoTracking.FirstOrDefaultAsync(f => f.Id == request.Id, cancellationToken);

            data.Name = request.Name;
            await _patientRepository.UpdateAsync(data);

            await _patientRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

            return(new Unit());
        }
예제 #4
0
        public async Task <ActionResult> Update(int id, [FromBody] UpdatePatientCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
예제 #5
0
        public async Task <UpdatePatientCommandResult> Handle(UpdatePatientCommand request, CancellationToken cancellationToken)
        {
            var patientFromDb = await _context.Patients.SingleAsync(p => p.Id.Equals(request.Id), cancellationToken);

            var patient = _mapper.Map(request, patientFromDb);

            patient.AddDomainEvent(new PatientUpdatedEvent(patient));
            _context.Patients.Attach(patient);
            await _context.SaveChangesAsync(cancellationToken);

            await _mediator.Publish(new PatientUpdatedEvent(patient), cancellationToken);

            return(_mapper.Map(patient, new UpdatePatientCommandResult()));
        }
        public async Task <ActionResult <BaseResponse <Patient> > > UpdatePatient(UpdatePatientCommand command)
        {
            try {
                var result = await _mediator.Send(command);

                return(Ok(result));
            } catch (ValidationException ex) {
                var err = new BaseResponse <Patient> ();
                err.Status  = ResponseType.Error;
                err.Message = ex.Message;
                err.Content = null;
                return(Ok(err));
            }
        }
예제 #7
0
        public IActionResult UpdatePacijent([FromRoute] int id, [FromBody] UpdatePatientCommand pacijentCommand)
        {
            if (CheckIfExists(id))
            {
                Patient patientToUpdate = _context.Patients.Where(x => x.Id == id).FirstOrDefault();

                if (patientToUpdate != null)
                {
                    patientToUpdate.FirstName = pacijentCommand.FirstName;
                    patientToUpdate.LastName  = pacijentCommand.LastName;
                    patientToUpdate.Phone     = pacijentCommand.Phone;
                    patientToUpdate.Adress    = pacijentCommand.Adress;
                    patientToUpdate.Email     = pacijentCommand.Email;

                    _context.SaveChanges();
                }

                return(Ok(new { message = "Succesfully updated patient" }));
            }
            else
            {
                return(BadRequest(new { message = "Could not find user with provided id" }));
            }
        }
예제 #8
0
        public async Task <ActionResult> UpdatePatient([FromBody] UpdatePatientCommand command)
        {
            var patient = await Mediator.Send(command);

            return(Ok(patient));
        }
예제 #9
0
        public async Task <IActionResult> UpdateAsync(UpdatePatientCommand command)
        {
            await _mediator.Send(command);

            return(Success());
        }