public TimeEntry GetLastTimeEntry(bool getInternal = false) { using (var cnn = GetConnection()) using (var cmd = cnn.CreateCommand()) { var internalWhere = (getInternal) ? "" : "WHERE Internal = 0"; cmd.CommandText = "SELECT * FROM TimeEntries " + internalWhere + " ORDER BY Id DESC LIMIT 1"; using (var reader = cmd.ExecuteReader()) { if (!reader.Read()) { return(null); } var timeEntry = new TimeEntry { TimeRecorded = DateTime.SpecifyKind(reader.GetDateTime(reader.GetOrdinal("TimeRecorded")), DateTimeKind.Local), Comment = reader.Get <string>("Comment"), Id = reader.Get <int>("Id"), Task = _localTaskRepository.GetTaskById(reader.Get <string>("TaskId")), AssociatedTask = _localTaskRepository.GetTaskById(reader.Get <string>("AssociatedTaskId")), Synced = reader.Get <bool>("Synced"), MinutesSpent = reader.Get <int>("MinutesSpent"), Internal = reader.Get <bool>("Internal"), Project = _localProjectRepository.GetProjectById(reader.Get <string>("ProjectId")) }; return(timeEntry); } } }
public IEnumerable <Task> GetTasks(string projectId = null, bool emptyProjectIdIsOk = false) { var tasks = new List <Task>(); using (var cnn = GetConnection()) using (var cmd = cnn.CreateCommand()) { cmd.CommandText = @"SELECT * FROM Tasks WHERE ParentId == ''"; if (emptyProjectIdIsOk || !string.IsNullOrEmpty(projectId)) { cmd.CommandText += " AND ProjectId = @projectId"; cmd.Prepare(); cmd.Parameters.AddWithValue("@projectId", projectId); } using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var task = new Task { Id = reader.Get <string>("Id"), Name = reader.Get <string>("Name"), Description = reader.Get <string>("Description"), Parent = GetTaskById(reader.Get <string>("ParentId")), Project = _localProjectRepository.GetProjectById(reader.Get <string>("ProjectId")) }; task.Tasks = GetTaskChildren(task); tasks.Add(task); } } } return(tasks); }
public Project GetProjectById(string id) { return(_localProjectRepository.GetProjectById(id)); }