예제 #1
0
        public async Task <IActionResult> Record(RecordingDTO model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    _logger.LogError("Model validation failed.");
                    return(BadRequest(ModelState));
                }

                // ensure a device or user cannot update the position of another vehicle
                var canRecord = await _registrationService.CanRecordPosition(model.UserID, model.DeviceID);

                if (!canRecord)
                {
                    _logger.LogError("User or Device has not a permission to record this Location.");
                    return(BadRequest("User or Device has not a permission to record this Location."));
                }

                bool result = await _trackingService.RecordPosition(model);

                if (result)
                {
                    _logger.LogInformation("Position Recorded.");
                    return(Ok(true));
                }
                else
                {
                    _logger.LogInformation("Error Occured");
                    return(Ok(false));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest("Error Occured"));
            }
        }