コード例 #1
0
        public async Task <ApiResponse <WorkerResponse> > Handle(DeleteWorkerCommand request, CancellationToken cancellationToken)
        {
            var worker = await _db.FindAsync <Models.Worker>(request.WorkerId);

            if (worker == null)
            {
                return(new ApiResponse <WorkerResponse>($"Could not find work order with Object number: {request.WorkerId}"));
            }

            _db.Remove(worker);
            await _db.SaveChangesAsync(cancellationToken);

            var response = _mapper.Map <WorkerResponse>(worker);

            return(new ApiResponse <WorkerResponse>(response));
        }
コード例 #2
0
        public async Task <ApiResponse <WorkOrderResponse> > Handle(UpdateWorkOrderCommand request, CancellationToken cancellationToken)
        {
            var workOrder = await _db.FindAsync <Models.WorkOrder>(request.ObjectNumber);

            if (workOrder == null)
            {
                return(new ApiResponse <WorkOrderResponse>($"Could not find work order with ID: {request.ObjectNumber}"));
            }

            workOrder = _mapper.Map <Models.WorkOrder>(request);
            _db.WorkOrders.Update(workOrder);
            await _db.SaveChangesAsync(cancellationToken);

            var response = _mapper.Map <WorkOrderResponse>(workOrder);

            return(new ApiResponse <WorkOrderResponse>(response));
        }