コード例 #1
0
ファイル: RegisterController.cs プロジェクト: lulzzz/IQCareKe
        public async Task <IActionResult> PostServiceEntryPoint([FromBody] AddServiceEntryPointCommand serviceEntryPointCommand)
        {
            var response = await _mediator.Send(serviceEntryPointCommand, Request.HttpContext.RequestAborted);

            if (response.IsValid)
            {
                return(Ok(response.Value));
            }
            return(BadRequest(response));
        }
コード例 #2
0
        public async Task <Result <ServiceEntryPoint> > Handle(AddServiceEntryPointCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    if (request.Id > 0)
                    {
                        var result = await _unitOfWork.Repository <ServiceEntryPoint>().FindByIdAsync(request.Id);

                        if (result != null)
                        {
                            result.EntryPointId = request.EntryPointId;

                            _unitOfWork.Repository <ServiceEntryPoint>().Update(result);
                            await _unitOfWork.SaveAsync();

                            return(Result <ServiceEntryPoint> .Valid(result));
                        }

                        ServiceEntryPoint serviceEntryPoint = new ServiceEntryPoint()
                        {
                            PatientId     = request.PatientId,
                            ServiceAreaId = request.ServiceAreaId,
                            EntryPointId  = request.EntryPointId,
                            CreateDate    = request.CreateDate,
                            Active        = true,
                            CreatedBy     = request.CreatedBy,
                            DeleteFlag    = false
                        };

                        await _unitOfWork.Repository <ServiceEntryPoint>().AddAsync(serviceEntryPoint);

                        await _unitOfWork.SaveAsync();

                        return(Result <ServiceEntryPoint> .Valid(serviceEntryPoint));
                    }
                    else
                    {
                        ServiceEntryPoint serviceEntryPoint = new ServiceEntryPoint()
                        {
                            PatientId     = request.PatientId,
                            ServiceAreaId = request.ServiceAreaId,
                            EntryPointId  = request.EntryPointId,
                            CreateDate    = request.CreateDate,
                            Active        = true,
                            CreatedBy     = request.CreatedBy,
                            DeleteFlag    = false
                        };

                        await _unitOfWork.Repository <ServiceEntryPoint>().AddAsync(serviceEntryPoint);

                        await _unitOfWork.SaveAsync();

                        return(Result <ServiceEntryPoint> .Valid(serviceEntryPoint));
                    }
                }
                catch (Exception e)
                {
                    Log.Error($"Failed to add ServiceEntryPoint " + e.Message);
                    return(Result <ServiceEntryPoint> .Invalid($"Failed to add ServiceEntryPoint " + e.Message + ", InnerException: " + e.InnerException));
                }
            }
        }