public async Task <data.Task> Update(data.ToDoDbContext db, TaskUpdate update) { try { var taskToUpdate = await db.Tasks.FirstOrDefaultAsync(w => w.TaskId == update.TaskId); taskToUpdate.CompletedDate = update.CompletedDate; taskToUpdate.DueDate = update.DueDate; taskToUpdate.Name = update.Name; taskToUpdate.StartedDate = update.StartedDate; taskToUpdate.Status = update.Status; taskToUpdate.TaskId = update.TaskId; return(taskToUpdate); } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(null); } }
public IHttpActionResult UnsubscribeToUpdates(int taskId) { try { using (ApplicationDbContext context = new ApplicationDbContext()) { var task = context.Tasks.FirstOrDefault(t => t.TaskID == taskId); if (task != null) { if (IsAuthorized(task, context)) { ApplicationUser user = GetUser(context); TaskUpdate taskUpdate = context.TaskUpdates.First(tu => tu.UserID == user.Id && tu.TaskID == task.TaskID); context.TaskUpdates.Remove(taskUpdate); context.SaveChanges(); } return(Ok()); } return(NotFound()); } } catch (Exception e) { Console.WriteLine(e.Message); throw; } }
public static void AddUpdate(Task task, TaskUpdate func){ TaskUpdate update = task.update; task.update = delegate(float d){ update(d); func(d); }; }
public async Task <TaskView> Update(TaskUpdate data, CancellationToken cancellationToken = default) { if (data == null) { throw new ArgumentNullException(nameof(data)); } var oData = await _manager.Reader.BaseQuery().FirstOrDefaultAsync(x => x.TaskId.Equals(data.TaskId), cancellationToken); if (oData == null) { throw new Exception("Can not modify unregistered data."); } // map to entity model and set default value var tData = oData.CopyPropertiesToNewObject <Models.Task>(); tData.IsDeleted = false; // update change fields data.CopyPropertiesTo(tData); _manager.DbContext.Update(tData); await _manager.DbContext.SaveChangesAsync(cancellationToken); return(tData.CastToView()); }
public void AddTaskUpdate(TaskUpdate taskUpdate) { taskUpdate.RecordCreated = DateTime.Now; DBContext.TaskUpdates.Add(taskUpdate); DBContext.SaveChanges(); }
public RequestResponse UpdateTask(TaskUpdate model) { if (model == null) { return(BadResponse("Request Body was empty.")); } var taskEntity = _context.Tasks.Find(model.TaskId); if (taskEntity == null) { return(BadResponse("Invalid task ID.")); } if (!taskEntity.Group.GroupMembers.FirstOrDefault(m => m.UserId == _userId.ToString()).IsOfficer) { return(BadResponse("Invalid permissions.")); } taskEntity.TaskName = model.TaskName; taskEntity.Description = model.Description; taskEntity.GroupId = model.GroupId; taskEntity.RewardValue = model.RewardValue; if (_context.SaveChanges() != 1) { return(BadResponse("Cannot save changes.")); } return(OkResponse("Task updated")); }
/**/ /* * NAME: * GetUpdatedAttributeAndValue - takes a TaskUpdate object and determines what attributes were updated * SYNOPSIS: * GetUpdatedAttributeAndValue(TaskUpdate taskUpdate) * taskUpdate --> the TaskUpdate object used to determine what attributes of the task were updated * DESCRIPTION: * This function goes through all the attributes in the TaskUpdate object and figures out whether an attribute was * updated or not and also figures out the updated value * RETURNS * a list containin the updated attribute in the first index and the value of the attribute in the second index * returns null if the TaskUpdate represent the creation of a task * AUTHOR * Biplab Thapa Magar * DATE * 10/04/2020 * / * /**/ private List <string> GetUpdatedAttributeAndValue(TaskUpdate taskUpdate) { // this list stores two strings, the first one holding the attribute changed and the second one holding //the value of the attribute var updated = new List <string>(); //first check what task attribute was updated in the taskUpdate if (taskUpdate.Name != null) { updated.Add("name"); updated.Add(taskUpdate.Name); } else if (taskUpdate.TaskStatus != null) { updated.Add("task status"); updated.Add(taskUpdate.TaskStatus); } else if (taskUpdate.Urgency != null) { updated.Add("urgency"); updated.Add(taskUpdate.Urgency); } else if (taskUpdate.TaskTypeId != null) { updated.Add("task type"); updated.Add(_taskTypesRepo.GetTaskTypeById((int)taskUpdate.TaskTypeId).Name); } else { updated = null; } return(updated); }
/**/ /* * NAME: * AddTaskUpdate - adds a TaskUpdate entry to the database * SYNOPSIS: * AddTaskUpdate(TaskUpdate taskUpdate) * taskUpdate --> the taskUpdate object to be added to the database * DESCRIPTION: * Accesses the database context in order to add the new TaskUpdate object * RETURNS * AUTHOR * Biplab Thapa Magar * DATE * 09/12/2020 * / * /**/ public void AddTaskUpdate(TaskUpdate taskUpdate) { if (taskUpdate == null) { throw new ArgumentNullException(nameof(taskUpdate)); } _context.Add(taskUpdate); }
public void UpdateTaskUpdate(TaskUpdate taskUpdate) { TaskUpdate taskUpdateInDb = GetTaskUpdate(taskUpdate.Id); taskUpdateInDb.UpdateText = taskUpdate.UpdateText; DBContext.SaveChanges(); }
private List <TreeViewNode> GetFolderChilds(Folder folder, bool root, string userId, ApplicationDbContext context) { List <TreeViewNode> childs = new List <TreeViewNode>(); foreach (var childFolder in folder.ChildFolders) { childs.Add(new TreeViewNode() { id = "F" + childFolder.FolderID.ToString(), parent = (root ? "P" + folder.FolderID : "F" + folder.FolderID), text = childFolder.Name, icon = "", state = new State() { opened = false } }); childs.AddRange(GetFolderChilds(childFolder, false, userId, context)); } foreach (var childTask in folder.ChildTasks) { TaskUpdate taskUpdate = context.TaskUpdates.FirstOrDefault(tu => tu.TaskID == childTask.TaskID && tu.UserID == userId); string taskNameWithNotify = ""; if (taskUpdate != null) { if (taskUpdate.Count > 0) { taskNameWithNotify = childTask.Name + "<span style=\"margin-top:-2px;margin-left:10px\" class=\"badge\">" + taskUpdate.Count + "</span>"; } else { taskNameWithNotify = childTask.Name; } } else { taskNameWithNotify = childTask.Name; } string deadlineTask = childTask.Deadline.HasValue ? String.Format("{0:dd.MM.yyyy}", childTask.Deadline.Value) : ""; childs.Add(new TreeViewNode() { id = "T" + childTask.TaskID.ToString(), parent = (root ? "P" + folder.FolderID : "F" + folder.FolderID), text = taskNameWithNotify, icon = GetTaskIcon(childTask), state = new State() { opened = false }, deadline = deadlineTask }); } return(childs); }
public static void AddUpdate(Task task, TaskUpdate func) { TaskUpdate update = task.update; task.update = delegate(float d){ update(d); func(d); }; }
private async void StartListener() { try { while (_connected) { try { var ret = await _streamReader.ReadLineAsync(); if (ret == null) { Debug.WriteLine("Connection closed gracefully"); return; } Debug.WriteLine($"Got some text: {ret}"); _gotText?.Invoke(ret); if (ret.StartsWith("S:LOAD ") || ret.StartsWith("R:GETLOAD ")) { //LOAD 123 55.0 var(vid, percent) = ret.ParseLoad(); LoadUpdate?.Invoke(vid, percent); } else if (ret.StartsWith("S:TASK ") || ret.StartsWith("R:GETTASK ")) { var(vid, state) = ret.ParseTask(); TaskUpdate?.Invoke(vid, state); } else if (ret.StartsWith("S:BTN ")) { var(vid, mode) = ret.ParseButton(); ButtonUpdate?.Invoke(vid, mode); } else if (ret.StartsWith("S:LED ") || ret.StartsWith("R:GETLED ")) { var led = ret.ParseLed(); LedUpdate?.Invoke(led.Vid, led.State); } else if (ret.StartsWith("R:GETTHERMTEMP ")) { var t = ret.ParseThermTemp(); TemperatureSensorUpdate?.Invoke(t.Vid, t.Sensor, t.Temperature); } } catch { if (!_tcpClient.Connected) { Debug.WriteLine("disconnected"); _connected = false; } } } } finally { _gotText?.Invoke(null); } }
public ActionResult NewUpdate(int taskId) { TaskUpdate newTaskUpdate = new TaskUpdate() { TaskId = taskId }; return(View(newTaskUpdate)); }
public async Task <TaskView> Update(CancellationToken cancellationToken, [FromBody] TaskUpdate data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } using var mgr = new Manager(_emi); return(await mgr.Updater.Update(data, cancellationToken)); }
public ActionResult EditTaskUpdate(TaskUpdate taskUpdate) { // Validate model states if (!ModelState.IsValid) { return(View("EditTaskUpdate", taskUpdate)); } taskService.UpdateTaskUpdate(taskUpdate); return(RedirectToAction("Detail", new { Id = taskUpdate.TaskId })); }
public TaskUpdate GetTaskUpdate() { var result = new TaskUpdate(); result.CompletedDate = TaskView.CompletedDate; result.DueDate = TaskView.DueDate; result.Name = TaskView.Name; result.StartedDate = TaskView.StartedDate; result.Status = TaskView.Status; result.TaskId = TaskView.TaskId; return(result); }
public async Task <PartialViewResult> Update(TaskUpdate taskUpdate) { try { if (ModelState.IsValid) { var task = await db.Tasks.FindAsync(taskUpdate.TaskId); switch ((TaskStateEnum)taskUpdate.TaskStateId) { case TaskStateEnum.Doing: if (task.RemainingTime - taskUpdate.ElapsedTime > 0) { task.RemainingTime -= taskUpdate.ElapsedTime; } else { taskUpdate.ElapsedTime = task.RemainingTime; task.RemainingTime = 0; } break; case TaskStateEnum.ToDo: break; case TaskStateEnum.Done: taskUpdate.ElapsedTime = task.RemainingTime; task.RemainingTime = 0; break; } task.TaskStateId = taskUpdate.TaskStateId; db.Entry(taskUpdate).State = EntityState.Added; await db.SaveChangesAsync(); await db.Entry(taskUpdate).ReloadAsync(); return(PartialView("_CreateTaskUpdateSuccessfulModal", taskUpdate)); } } catch { ModelState.AddModelError(String.Empty, "Error en DB o excepción");//TODO Eliminar cuando estén las validaciones } return(PartialView("_CreateTaskUpdateModal", taskUpdate)); }
public IHttpActionResult UpdateTask(int id, TaskUpdate model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != model.TaskId) { return(BadRequest("Task ID mismatch.")); } var service = GetTaskService(); var updateResponse = service.UpdateTask(model); return(ValidateRequestResponse(updateResponse)); }
public ActionResult NewUpdate(TaskUpdate taskUpdate) { // Validate model state if (!ModelState.IsValid) { return(View("NewUpdate", taskUpdate)); } taskService.AddTaskUpdate(taskUpdate); // Update Task Task task = taskService.GetTask(taskUpdate.TaskId); taskService.UpdateTask(task); // Redirect to the Detail view return(RedirectToAction("Detail", new { Id = taskUpdate.TaskId })); }
public static IEnumerable UpdateTask(SqlString Host, SqlString SessionID, SqlInt32 id, SqlInt32? request_id, SqlInt32 element_id, SqlInt16 element_type, SqlInt16 status, SqlInt32 last_modified, SqlInt16 task_type, SqlString text, SqlInt32 complete_till ) { var provider = new Classes.AmoDownloaderCLR(); Task newTask = new Task(); newTask.request = new Request(); newTask.request.tasks = new Tasks(); newTask.request.tasks.update = new List<TaskUpdate>(); TaskUpdate UpdateTask = new TaskUpdate(); UpdateTask.id = (int)id; UpdateTask.request_id = (int?)request_id; UpdateTask.element_id = (Int32)element_id; UpdateTask.element_type = (int)element_type; UpdateTask.last_modified = (int)last_modified; UpdateTask.task_type = (int)task_type; UpdateTask.text = (string)text; UpdateTask.status = (int)status; UpdateTask.complete_till = (Int32)complete_till; newTask.request.tasks.update.Add(UpdateTask); Console.WriteLine("Start UpdateTask\n"); Console.WriteLine(JsonConvert.SerializeObject(newTask)); var ids = provider.SendQuery(Host, SessionID, newTask); Environment.ExitCode = Convert.ToInt16(provider.HadErrors); var i = JsonConvert.DeserializeObject<TaskResponseRoot>(ids); ArrayList list = new ArrayList(); foreach (var newTaskResponse in i.response.tasks.update) { TaskResponse newRec = new TaskResponse(); newRec.Id = newTaskResponse.id; newRec.AmoTime = i.response.Amo_time; newRec.ProgramTime = DateTime.Now; list.Add(newRec); } return list; }
public async Task <PartialViewResult> Update(int taskId, int nextStateId) { var task = await db.Tasks.FindAsync(taskId); var taskStates = await db.TaskStates.ToListAsync(); var taskUpdate = new TaskUpdate { PreviousTaskStateId = task.TaskStateId, TaskStateId = nextStateId, EventDate = DateTime.Now, TaskId = task.Id, Task = task, PreviousTaskState = taskStates.First(t => t.Id == task.TaskStateId), TaskState = taskStates.First(t => t.Id == nextStateId), }; return(PartialView("_CreateTaskUpdateModal", taskUpdate)); }
// Update Transaction Code public async Task <TaskView> Update(TaskUpdate update) { try { using (var db = new data.ToDoDbContext()) { var result = await Update(db, update); await db.SaveChangesAsync(); return((TaskView)result); } } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(null); } }
public ControlableTask(TaskUpdate updateFunc, TaskInit initFunc = null, TaskShutdown shutdownFunc = null, Action pauseFunc = null, Action continuePlayFunc = null) { _task.update = updateFunc; if (initFunc != null) { _task.init = initFunc; } if (shutdownFunc != null) { _task.shutdown = shutdownFunc; } if (pauseFunc != null) { onPause = pauseFunc; } if (continuePlayFunc != null) { onContiunePlay = continuePlayFunc; } }
public void GetXmlTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <update> <TASK> <RECORDNO>10</RECORDNO> <PROJECTID>P1234</PROJECTID> </TASK> </update> </function>"; TaskUpdate record = new TaskUpdate("unittest") { RecordNo = 10, ProjectId = "P1234" }; this.CompareXml(expected, record); }
/**/ /* * NAME: * CreateTask - adds a task entry to the database * SYNOPSIS: * CreateTask(Task task, string creatorId) * task --> the task to be added * creatorId --> the id of the user who created the task * DESCRIPTION: * Accesses the database context in order to add a new task entry. It also adds a TaskUpdate object * that describes the creation of the Task, so the web application can keep track of all the created tasks * RETURNS * the Task object that was added * AUTHOR * Biplab Thapa Magar * DATE * 09/15/2020 * / * /**/ public Task CreateTask(Task task, string creatorId) { if (task == null) { throw new ArgumentNullException(nameof(task)); } //add the new task to the context _context.Add(task); //build a TaskUpdate model TaskUpdate taskUpdate = new TaskUpdate { Task = task, TimeStamp = DateTime.Now, UpdaterId = creatorId, }; _context.Add(taskUpdate); return(task); }
public async Task <TaskView> TaskUpdate(TaskUpdate update) { try { string json = ""; var client = new HttpClient(); using (var ms = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof(TaskUpdate), new DataContractJsonSerializerSettings() { DateTimeFormat = new DateTimeFormat("yyyy-MM-dd'T'HH:mm:ss") }); serializer.WriteObject(ms, update); ms.Position = 0; StreamReader sr = new StreamReader(ms); json = sr.ReadToEnd(); } var stream = await client.PutAsync($"http://tododotnet.lan:9271/api/task/{update.TaskId}", new StringContent(json, Encoding.UTF8, "application/json")); using (var ms = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof(TaskView)); await stream.Content.CopyToAsync(ms); ms.Position = 0; var view = serializer.ReadObject(ms) as TaskView; return(view); } } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(null); } }
public void GetXmlTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <update> <TASK> <RECORDNO>10</RECORDNO> <PROJECTID>P1234</PROJECTID> </TASK> </update> </function>"; Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = Encoding.UTF8; xmlSettings.Indent = true; xmlSettings.IndentChars = " "; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); TaskUpdate record = new TaskUpdate("unittest"); record.RecordNo = 10; record.ProjectId = "P1234"; record.WriteXml(ref xml); xml.Flush(); stream.Position = 0; StreamReader reader = new StreamReader(stream); Diff xmlDiff = DiffBuilder.Compare(expected).WithTest(reader.ReadToEnd()) .WithDifferenceEvaluator(DifferenceEvaluators.Default) .Build(); Assert.IsFalse(xmlDiff.HasDifferences(), xmlDiff.ToString()); }
public async Task <data.Task> Update(TaskUpdate update) { try { TableOperation retrieveOperation = TableOperation.Retrieve <data.Task>("root", update.TaskId.ToString()); var taskIdTable = await data.Utils.GetTable("Task"); var result = await taskIdTable.ExecuteAsync(retrieveOperation); if (result.Result != null) { var taskToUpdate = (data.Task)result.Result; taskToUpdate.CompletedDate = update.CompletedDate; taskToUpdate.DueDate = update.DueDate; taskToUpdate.Name = update.Name; taskToUpdate.StartedDate = update.StartedDate; taskToUpdate.Status = update.Status; taskToUpdate.TaskId = update.TaskId; TableOperation updateOperation = TableOperation.Replace(taskToUpdate); // Execute the operation. await taskIdTable.ExecuteAsync(updateOperation); return(taskToUpdate); } } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); } return(null); }
protected virtual void OnTaskUpdate() { TaskUpdate?.Invoke(this); }
public void DeleteTaskUpdate(TaskUpdate taskUpdate) { DBContext.TaskUpdates.Remove(taskUpdate); DBContext.SaveChanges(); }
/**/ /* * NAME: * UpdateTask - updates a task and records the task update too * SYNOPSIS: * UpdateTask(Task task, string updaterId) * task --> the task that is to be updated (it must contain the updated values; taskId must stay the same) * updaterId --> the id of the user who made the update * DESCRIPTION: * Accesses the database context in order to update the task. Simultaneouslyk this function generates a TaskUpdate * entry from the given information, so that the program can keep track of activity * RETURNS * The updated task object * AUTHOR * Biplab Thapa Magar * DATE * 09/06/2020 * / * /**/ public Task UpdateTask(Task task, string updaterId) { if (task == null) { throw new ArgumentNullException(nameof(task)); } var taskToUpdate = _context.Tasks.Find(task.TaskId); //now, for each changed value, store a TaskUpdate record with the updated value //time of task update var timeStamp = DateTime.Now; //for every updateable field in the Task object, if there was a change, then add a TaskUpdate entry //if the name of the task was changed if (task.Name != taskToUpdate.Name) { //add the updated name to the taskUpdate object var taskNameUpdate = new TaskUpdate { TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId }; taskNameUpdate.Name = task.Name; _context.Add(taskNameUpdate); } //if the taskstatus of the task was changed if (task.TaskStatus != taskToUpdate.TaskStatus) { //add the updated TaskStatus to the taskUpdate object var taskStatusUpdate = new TaskUpdate { TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId }; taskStatusUpdate.TaskStatus = task.TaskStatus; _context.Add(taskStatusUpdate); } //if the Urgency of the task was changed if (task.Urgency != taskToUpdate.Urgency) { //add the updated Urgency to the taskUpdate object var taskUrgencyUpdate = new TaskUpdate { TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId }; taskUrgencyUpdate.Urgency = task.Urgency; _context.Add(taskUrgencyUpdate); } //if the TaskTypeId of the task was changed if (task.TaskTypeId != taskToUpdate.TaskTypeId) { //add the updated TaskTypeId to the taskUpdate object var taskTypeUpdate = new TaskUpdate { TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId }; taskTypeUpdate.TaskTypeId = task.TaskTypeId; _context.Add(taskTypeUpdate); } //update the task _context.Entry(taskToUpdate).CurrentValues.SetValues(task); return(task); }
public async Task<TaskUpdate.response> TaskUpdate(TaskUpdate.request request, CancellationToken? token = null) { return await SendAsync<TaskUpdate.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None)); }