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 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 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 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(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(); } }
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)); } }