public async Task InsertLogAsync(ClickLog log) { if (log != null) { using (IDbConnection conn = DBConnection.CreateConnection()) { conn.Open(); log.ClickTime = DateTime.Now; await conn.InsertAsync <ClickLog>(log); } } }
//[ApiAuthorize] public async Task <IActionResult> Post([FromBody] ClickLog log) { try { _log.Info($"[ClickLogController]点击日志:{JsonConvert.SerializeObject(log)}"); await _clickLogService.InsertLogAsync(log); return(Ok("request success")); } catch (Exception ex) { _log.Error($"[ClickLogController]点击日志记录失败,错误信息:{ex.Message}"); return(BadRequest("request failed")); } }
public async Task <ClickLog> CreateAsync(ClickLog model) { try { this.Context.ClickLog.Add(model); await this.Context.SaveChangesAsync(); return(model); } catch (Exception ex) { Log.Fatal(ex); throw new Exception("DB error", ex.InnerException); } }