/// <summary> /// Deploys a new android in the field. /// </summary> /// <param name="teamId">The unique identifier of the registered team that is sending this request.</param> /// <param name="androidId">The unique identifier of the deployed android this reuest is meant for.</param> /// <param name="request">The actual request.</param> /// <returns>The android the request is for.</returns> public async Task <AndroidDto> SendRequest(Guid teamId, Guid androidId, AndroidRequestDto request) { Team teamToCheck = await _dbContext.Teams.SingleOrDefaultAsync(x => x.Id == teamId); if (teamToCheck == null) { throw new HtfValidationException("The specified team is unknown!"); } if (!Crypt.EnhancedVerify(request.Password, teamToCheck.Password)) { throw new HtfValidationException("The specified password is not correct!"); } Android androidToRequest = await _dbContext.Androids.SingleOrDefaultAsync(x => x.Id == androidId); if (androidToRequest == null) { throw new HtfValidationException("The specified android is unknown!"); } if (androidToRequest.Compromised) { throw new HtfValidationException("The specified android is compromised!"); } if (androidToRequest.AutoPilot == AutoPilot.Level1) { throw new HtfValidationException("The specified level-1 android does not support manual requests!"); } SensoryDataRequest requestToCreate = _requestMapper.Map(request); requestToCreate.AndroidId = androidId; requestToCreate.TimeStamp = DateTime.UtcNow; await _dbContext.SensoryDataRequests.AddAsync(requestToCreate); await _dbContext.SaveChangesAsync(); return(_androidMapper.Map(androidToRequest)); }
public async Task <IActionResult> SendRequest(Guid teamId, Guid androidId, [FromBody] AndroidRequestDto request) { AndroidDto android = await _androidLogic.SendRequest(teamId, androidId, request); return(Ok(android)); }
public SensoryDataRequest Map(AndroidRequestDto team) { return(_mapper.Map <SensoryDataRequest>(team)); }