public async Task <DeployResult> Handle(Command request, CancellationToken cancellationToken) { var oldBinding = _context.Bindings.Include(b => b.Floor).SingleOrDefault(x => x.Host == request.DeployInfo.Host); if (oldBinding != null && oldBinding.Floor.Id != request.DeployInfo.FloorId) { throw new RestException(HttpStatusCode.BadRequest, new { Username = ErrorMessages.ServerHostWasBound }); } _remoteClient.Deploy(request.DeployInfo); var floor = await _context.Floors.SingleOrDefaultAsync(x => x.Id == request.DeployInfo.FloorId, cancellationToken); floor.MasterId = request.DeployInfo.MasterId; var binding = new Binding { Host = request.DeployInfo.Host, Port = request.DeployInfo.Port, UserName = request.DeployInfo.UserName, Password = request.DeployInfo.Password, FloorId = floor.Id }; await _context.Bindings.AddAsync(binding, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(new DeployResult { MasterId = request.DeployInfo.MasterId }); }