/// <summary> /// deleted task base on task track id /// </summary> /// <param name="id"></param> /// <returns></returns> public int DeleteTaskBaseOnId(string id) { int isDeleteRecord = 0; DayTask taskToBeDeleted = databaseHelper.GetDayTaskByTrackId(id); List <DayTask> allTasks = databaseHelper.GetAllDayTasksBaseOnDayMonth(taskToBeDeleted.CreatedAt); //date int tasksToBeDeletedTaskIndex = allTasks.FindIndex(x => x.DayTaskTrackId == id); isDeleteRecord = allTasks.Count; if (tasksToBeDeletedTaskIndex == 0) { // if task was top most in list isDeleteRecord = databaseHelper.DeleteDayTaskByTrackId(id); } else if (tasksToBeDeletedTaskIndex == allTasks.Count - 1) {// if bottom most task is about to delete DayTask prevTask = allTasks[tasksToBeDeletedTaskIndex - 1]; prevTask.SpentTime = null; string isUpdated = databaseHelper.AddDayTask(prevTask); if (isUpdated != null) { isDeleteRecord = databaseHelper.DeleteDayTaskByTrackId(id); } } else {// if any inbetween item is about to delete DayTask prevTask = allTasks[tasksToBeDeletedTaskIndex - 1]; DayTask afterTask = allTasks[tasksToBeDeletedTaskIndex + 1]; prevTask.SpentTime = AppUtil.AppUtil.CalculateSpendedTime(Convert.ToDateTime(prevTask.TaskStartedAt), Convert.ToDateTime(afterTask.TaskStartedAt)); string isUpdated = databaseHelper.AddDayTask(prevTask); if (isUpdated != null) { isDeleteRecord = databaseHelper.DeleteDayTaskByTrackId(id); } } return(isDeleteRecord); }