Пример #1
0
        public async Task <string> InsertLog(InsertLogRequest data)
        {
            var auth = await _authRepository.GetByIdAsync(1);

            if (auth.Secret == data.Key)
            {
                var meter = await _trafficMeterRepoistory.GetByIdAsync(data.MeterId);

                if (meter != null)
                {
                    var newCongestion = await UpdateCongestionLevel(meter);

                    meter.Congestion = (int)newCongestion;

                    await _trafficMeterRepoistory.UpdateAsync(meter);

                    TrafficLog newLog = new TrafficLog
                    {
                        MeterId = meter.Id,
                        Time    = data.Timestamp,
                        Speed   = (int)data.Speed
                    };

                    await _trafficLogRepoistory.InsertAsync(newLog);

                    _traffixUpdateProvider.MeterUpdated(meter.Region, meter, newLog);
                    return("LOG ADDED");
                }
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            throw new HttpResponseException(HttpStatusCode.Unauthorized);
        }
Пример #2
0
        public override Task <InsertLogResponse> InsertLog(InsertLogRequest request, ServerCallContext context)
        {
            InsertLogResponse response = new InsertLogResponse {
                InsertSucc = true
            };
            PrintLog log = new PrintLog
            {
                PrintLogAdvId    = request.PrintLog.AdId,
                PrintLogIpAddr   = request.PrintLog.IpAddr,
                PrintLogPcName   = request.PrintLog.PcName,
                PrintLogMacAddr  = request.PrintLog.MacAddr,
                PrintLogDispTime = request.PrintLog.Disptime
            };
            PrintLogDao dao = new PrintLogDao();

            dao.Add(log);
            return(Task.FromResult(response));
        }