public void Save(TaskResult taskResult) { using (var ctx = new PureDataContext(_pureDataConnectionString)) { var kfiId = taskResult.KfiId; var taskId = taskResult.TaskId; if (ctx.Set <TaskResult>().Any(ir => ir.KfiId == kfiId && ir.TaskId == taskId)) { throw new InvalidOperationException("The Task has already been completed."); } TaskResult instance = new TaskResult() { Body = taskResult.Body, Title = taskResult.Title, Created = DateTime.Now, CreatedBy = taskResult.CreatedBy, KfiId = kfiId, TaskId = taskId }; ctx.Set <TaskResult>().Add(instance); ctx.SaveChanges(); } }
public void Save(TaskConfiguration instance) { using (var ctx = new PureDataContext(_pureDataConnectionString)) { if ( ctx.Set <TaskConfiguration>().Any( c => c.TaskConfigurationId == instance.TaskConfigurationId)) { ctx.Set <TaskConfiguration>().Attach(instance); ctx.Entry(instance).State = EntityState.Modified; ctx.SaveChanges(); } else { var taskConfig = new TaskConfiguration { Body = instance.Body, Title = instance.Title, LeadTimeDays = instance.LeadTimeDays, Sequence = instance.Sequence, CaseStateId = instance.CaseStateId, IsManual = instance.IsManual }; ctx.Set <TaskConfiguration>().Add(taskConfig); ctx.SaveChanges(); } } }
public IResult AddManualTask(int nodeId, int nodeDepth, int rootCaseStateId) { try { const string title = "Task Configuration"; const string prompt = "Select a Task Configuration to include in the Case Filter."; var choices = _tasks.GetManualConfigurations(rootCaseStateId).OrderBy(x => x.Title).ToList(); if (!choices.Any()) { var message = $"You have no manual configuration tasks set-up for the CaseState: {_tasks.GetCaseStateName(rootCaseStateId)}"; return(new ResultFactory().ErrorMessage(message)); } TaskConfiguration chosenConfiguration; if (Coercion.TryCoerceChoice(title, prompt, choices, out chosenConfiguration)) { //Todo:take selected task config and add it to the selected node's children list. If it has no children add it as a row on the groups table before adding to sources. using (var ctx = new PureDataContext(DevDb)) { var nodeConfigGroupId = ctx .Set <TaskConfigGroup>().FirstOrDefault(x => x.ParentTaskConfigId == nodeId || x.ParentCaseStateId == nodeId); //This logic doesn't work. What is cs has same id as tc. //If it doesn't exist within the groups table, create it. if (nodeConfigGroupId == null) { var newConfigGroupRow = new TaskConfigGroup() { ParentTaskConfigId = nodeId, Depth = nodeDepth + 1, }; ctx.Set <TaskConfigGroup>().Add(newConfigGroupRow); ctx.SaveChanges(); //Duplicate nodeConfigGroupId line here when fixed. nodeConfigGroupId = ctx .Set <TaskConfigGroup>().FirstOrDefault(x => x.ParentTaskConfigId == nodeId || x.ParentCaseStateId == nodeId); } var newTaskConfigSource = new TaskConfigSource() { TaskConfigGroupId = nodeConfigGroupId.TaskConfigGroupId, TaskConfigurationId = chosenConfiguration.TaskConfigurationId }; ctx.Set <TaskConfigSource>().Add(newTaskConfigSource); ctx.SaveChanges(); } } return(new ResultFactory().Ok()); } catch (Exception ex) { return(new ResultFactory().Error(ex)); } }
public void Setup() { using (var ctx = new PureDataContext(DevDb)) { _allGroups = ctx.Set <TaskConfigGroup>() .Include(x => x.CaseState) .Include(x => x.TaskConfigSources) .ToList(); _allSources = ctx.Set <TaskConfigSource>() .Include(x => x.TaskConfigGroup) .Include(x => x.TaskConfiguration) .ToList(); } }
public IEnumerable <TaskResult> ForTask(Task task) { using (var ctx = new PureDataContext(_pureDataConnectionString)) { return(ctx.Set <TaskResult>().Where(i => i.TaskId == task.TaskId).ToList()); } }
public IResult SoftDelete(TaskConfiguration instance, string user) { try { using (var ctx = new PureDataContext(_pureDataConnectionString)) { var archive = new TaskConfigurationsArchived { TaskConfigurationId = instance.TaskConfigurationId, DeletedBy = user, IsDeleted = true, DeletedOn = DateTime.Now }; ctx.Set <TaskConfigurationsArchived>().Add(archive); instance.TaskConfigurationsArchived = archive; ctx.SaveChanges(); } return(new ResultFactory().Ok()); } catch (Exception ex) { return(new ResultFactory().Error(ex)); } }
public string GetCaseStateName(int caseStateId) { using (var ctx = new PureDataContext(_pureDataConnectionString)) { return(ctx.Set <CaseState>().SingleOrDefault(x => x.CaseStateId == caseStateId)?.Name); } }
public List <TreeParent> PopulateTree() { using (var ctx = new PureDataContext(DevDb)) { _allGroups = ctx.Set <TaskConfigGroup>() .Include(x => x.CaseState) .Include(x => x.TaskConfigSources) .ToList(); _allSources = ctx.Set <TaskConfigSource>() .Include(x => x.TaskConfigGroup) .Include(x => x.TaskConfiguration) .ToList(); } var rootParentConfigGroups = _allGroups.Where(x => x.ParentTaskConfigId == null).ToList(); var rootParents = new List <TreeParent>(); foreach (var rootParent in rootParentConfigGroups) { var caseState = new TreeParent { CaseState = rootParent.CaseState, Children = new List <TreeSiblings>() }; foreach (var source in rootParent.TaskConfigSources.ToList()) { var lvl1Children = new TreeSiblings { Depth = rootParent.Depth, CaseParent = caseState, Node = source, Children = new List <TreeSiblings>() }; caseState.Children.Add(lvl1Children); } GenerateNodeChildren(caseState.Children); rootParents.Add(caseState); } return(rootParents); }
public IEnumerable <TaskResult> ResultsForCase(int kfiId) { using (var ctx = new PureDataContext(_pureDataConnectionString)) { return(ctx.Set <TaskResult>(). Where(r => r.KfiId == kfiId). ToList()); } }
/// <summary> /// GetByTaskId is light EF method as in it does not pull in all of its related /// navigation properties. /// </summary> /// <param name="id">Id of task you want to find</param> /// <returns>Found Entity.</returns> public Task GetByTaskId(int id) { using (var ctx = new PureDataContext(_pureDataConnectionString)) { return(ctx.Set <Task>() .Include(x => x.TaskConfiguration) .Include(x => x.TaskResult) .SingleOrDefault(x => x.TaskId == id)); } }
public IResult HardDelete(TaskConfiguration instance) { try { using (var ctx = new PureDataContext(_pureDataConnectionString)) { ctx.Set <TaskConfiguration>().RemoveRange( from m in ctx.Set <TaskConfiguration>() where m.TaskConfigurationId == instance.TaskConfigurationId select m ); ctx.SaveChanges(); } return(new ResultFactory().Ok()); } catch (Exception ex) { return(new ResultFactory().Error(ex)); } }
private IEnumerable <Task> GetAllTasksThatAreTenDaysOld(int period) { var tenDaysFromNow = _time.Now.AddDays(-period); using (var ctx = new PureDataContext(_pureDataConnectionString)) { var results = from i in ctx.Set <Task>().Include(x => x.TaskResult) where i.Created <= tenDaysFromNow && i.TaskConfiguration.CaseStateId == 1 select i; return(results.ToList()); } }
public IEnumerable <TaskConfiguration> GetAllActiveConfigurations() { using (var ctx = new PureDataContext(_pureDataConnectionString)) { return(ctx.Set <TaskConfiguration>() .Include(i => i.CaseState) .Include(i => i.TaskConfigurationsArchived) .Where(x => x.TaskConfigurationsArchived == null) .OrderByDescending(c => c.TaskConfigurationId) .ToList()); } }
public int CountNecroMatches(int kfiId, TaskConfiguration configuration, DateTime dueDate) { using (var ctx = new PureDataContext(_pureDataConnectionString)) { return(ctx.Set <Task>().Count( x => x.KfiId == kfiId && x.TaskConfigurationId == configuration.TaskConfigurationId && x.DueDate == dueDate && x.Title == configuration.Title && x.Body == configuration.Body)); } }
public IEnumerable <Task> ForCase(int kfiId) { using (var ctx = new PureDataContext(_pureDataConnectionString)) { return(ctx.Set <Task>() .Include(i => i.TaskConfiguration) .Include(i => i.TaskConfiguration.TaskConfigurationsArchived) .Include(i => i.TaskResult) .Where(i => i.KfiId == kfiId && i.TaskConfiguration.TaskConfigurationsArchived == null) .ToList()); } }
public IEnumerable <Task> GetAllExpiredPendingTasks() { using (var ctx = new PureDataContext(_pureDataConnectionString)) { var qry = from hh in ctx.Set <CaseStateHistory>() group hh by hh.KfiId into histories let top = histories.OrderByDescending(h => h.Created) .ThenByDescending(h => h.CaseStateId) .FirstOrDefault() join i in ctx.Set <Task>() on top.KfiId equals i.KfiId join ic in ctx.Set <TaskConfiguration>() on i.TaskConfigurationId equals ic.TaskConfigurationId join ir in ctx.Set <TaskResult>() on new { i.KfiId, i.TaskId } equals new { ir.KfiId, ir.TaskId } into results from ir in results.DefaultIfEmpty() where ir == null && ic.CaseStateId < top.CaseStateId select i; return(qry.ToList()); } }
//Todo: //Not sure if this works as it pulls through the parent item too even if it isn't selected for removal. //Try doing it in the tests first. public void DeleteTreeNode(int nodeId, List <TreeSiblings> children) { using (var ctx = new PureDataContext(DevDb)) { _taskConfigIdList.Clear(); _taskConfigIdList.Add(nodeId); GetAllChildIds(children); var groupRowsToDelete = ctx.Set <TaskConfigGroup>() .Where(x => _taskConfigIdList.Contains(x.ParentTaskConfigId.Value)).ToList(); var sourceRowsToDelete = ctx.Set <TaskConfigSource>() .Where(x => _taskConfigIdList.Contains(x.TaskConfigurationId)).ToList(); if (!groupRowsToDelete.Any() || !sourceRowsToDelete.Any()) { return; } //ctx.Set<TaskConfigGroup>().RemoveRange(groupRowsToDelete); //ctx.Set<TaskConfigSource>().RemoveRange(sourceRowsToDelete); //ctx.SaveChanges(); } }
public void Save(Task toSet) { using (var ctx = new PureDataContext(_pureDataConnectionString)) { var task = new Task { Body = toSet.Body, DueDate = toSet.DueDate, TaskConfigurationId = toSet.TaskConfiguration.TaskConfigurationId, KfiId = toSet.KfiId, Sequence = toSet.Sequence, Title = toSet.Title, HasBeenDeferred = toSet.HasBeenDeferred, Created = DateTime.Now, CreatedBy = WindowsIdentity.GetCurrent().Name }; ctx.Set <Task>().Add(task); ctx.SaveChanges(); } }