public TaskItem InsertNewTask(string description, long createdDateTime) { string sql = "INSERT INTO Task (Description, CreatedDateTime) VALUES (@Description, @CreatedDateTime)"; _DBConnection.Execute(sql, new { Description = description, CreatedDateTime = createdDateTime }); sql = "SELECT * FROM Task LEFT JOIN " + "(SELECT DateTracked, TaskId, SUM(SecondsTracked) AS SecondsTracked FROM TaskHistory " + "GROUP BY DateTracked, TaskId) AS TH " + "ON Task.TaskId = TH.TaskId " + "WHERE Task.Description = @Description AND CreatedDateTime = @CreatedDateTime"; return(_DBConnection.QueryFirst <TaskItem>(sql, new { Description = description, CreatedDateTime = createdDateTime })); }
public WindowItem GetOrCreateWindowItemFromDB(int?appId, int?fileId, string windowText) { Dictionary <string, object> args = new Dictionary <string, object>(); args.Add("ApplicationId", appId); args.Add("FileId", fileId); args.Add("WindowText", windowText); string selectSql = $"SELECT * FROM Window { GenerateWhereClauseWithNull(args) }"; WindowItem windowItem = _DBConnection.QueryFirstOrDefault <WindowItem>(selectSql, new { ApplicationId = appId, FileId = fileId, WindowText = windowText }); if (windowItem == null) { string insertSql = $"INSERT INTO Window { GenerateInsertClauseWithNull(args) }"; _DBConnection.Execute(insertSql, new { ApplicationId = appId, FileId = fileId, WindowText = windowText }); windowItem = _DBConnection.QueryFirst <WindowItem>(selectSql, new { ApplicationId = appId, FileId = fileId, WindowText = windowText }); } return(windowItem); }