public async Task <Unit> Handle(AddWorkHoursCommand request, CancellationToken cancellationToken) { var workOrderWorker = _mapper.Map <WorkOrderWorker.Models.WorkOrderWorker>(request); _db.Set <WorkOrderWorker.Models.WorkOrderWorker>().Add(workOrderWorker); await _db.SaveChangesAsync(cancellationToken); return(await Unit.Task); }
public async Task <ApiResponse <WorkOrderResponse> > Handle(CreateWorkOrderCommand request, CancellationToken cancellationToken) { var workOrder = _mapper.Map <Models.WorkOrder>(request); var result = _db.WorkOrders.Add(workOrder); await _db.SaveChangesAsync(cancellationToken); var response = _mapper.Map <WorkOrderResponse>(result.Entity); return(new ApiResponse <WorkOrderResponse>(response)); }
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)); }
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)); }