public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var contract = _mapper.Map <Contract>(request.ModifiedContract); var contractExists = await _db.Contract.AnyAsync(x => x.Id == contract.Id && x.VersionNumber == contract.VersionNumber, cancellationToken); if (contractExists) { _db.Update(contract); } else { await _db.Contract.AddAsync(contract, cancellationToken); } contract.UpdateInst = DateTime.UtcNow; if (request.UniqueDisplayedContractVersion) { contract.DisplayOnContractList = true; } await _db.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(Command command, CancellationToken cancellationToken) { var contract = await _dbContext.Contract.FindAsync(command.ContractId, command.VersionNumber); _dbContext.Contract.Remove(contract); await _dbContext.SaveChangesAsync(cancellationToken); return(Unit.Value); }