public ActionResult _EditTask(Model.EditTaskInfo model) { if (ModelState.IsValid) { TaskDTO taskDTO = new TaskDTO(); taskDTO.name = model.nameE; taskDTO.description = model.descriptionE; taskDTO.id_task = model.id_taskE; if (model.timeSelectedE == "time") { taskDTO.daysAvailable = model.daysAvailableE; taskDTO.hoursAvailable = model.hoursAvailableE; } else if (model.timeSelectedE == "date") { taskDTO.finishDate = model.finishDateE + " " + model.finishTimeE; } taskDTO.userLog = Request.Cookies["user_id"].Value; if (taskProvider.putTask(taskDTO).Result) { TaskDTO editedTask = taskProvider.getTask(taskDTO.id_task).Result; StageDTO stage = new ProcessManagmentProvider().getStage(editedTask.stage_id).Result; if (taskProvider.putRefreshTaskTimes(stage.processManagment_id).Result) { return(PartialView("/Views/Tasks/_Tasks/_TaskDetails/_TaskInfo.cshtml", new Model.TaskDetailsModel(taskDTO.id_task))); } } } return(new HttpStatusCodeResult(404, "Can't find that")); }
public ActionResult _RefreshStageTimes(string id_stage) { if (ModelState.IsValid) { StageDTO stage = new ProcessManagmentProvider().getStage(id_stage).Result; if (new TaskProvider().putRefreshTaskTimes(stage.processManagment_id).Result) { return(new HttpStatusCodeResult(200)); } } return(new HttpStatusCodeResult(404, "Can't find that")); }
public ActionResult _RefreshTaskTimes(string id_task) { if (ModelState.IsValid) { TaskDTO task = taskProvider.getTask(id_task).Result; StageDTO stage = new ProcessManagmentProvider().getStage(task.stage_id).Result; if (taskProvider.putRefreshTaskTimes(stage.processManagment_id).Result) { return(new HttpStatusCodeResult(200)); } } return(new HttpStatusCodeResult(404, "Can't find that")); }
public ActionResult _DeleteTask(string id_task) { TaskDTO taskDTO = taskProvider.getTask(id_task).Result; StageDTO stage = new ProcessManagmentProvider().getStage(taskDTO.stage_id).Result; if (taskProvider.deleteTask(id_task, Request.Cookies["user_id"].Value).Result) { if (taskProvider.putRefreshTaskTimes(stage.processManagment_id).Result) { return(new HttpStatusCodeResult(200)); } } return(new HttpStatusCodeResult(404, "Can't find that")); }
private void completeTask(string id_task) { // update completed task TaskDTO completedTask = new TaskDTO(); TaskDTO completedTaskTemporal = taskProvider.getTask(id_task).Result; completedTask.id_task = id_task; completedTask.taskState_id = "2"; completedTask.completedDate = DateTime.Now.ToString(); completedTask.taskPosition = completedTaskTemporal.taskPosition; completedTask.stage_id = completedTaskTemporal.stage_id; completedTask.userLog = Request.Cookies["user_id"].Value; bool isSuccess = taskProvider.putTask(completedTask).Result; ProcessDTO actualProcess = new ProcessProvider().getProcess(new ProcessProvider().getStage(completedTask.stage_id).Result.processManagment_id).Result; //update next task TaskDTO nextTask = new TaskDTO(); List <TaskDTO> tasks = taskProvider.getTasks(completedTaskTemporal.stage_id).Result; foreach (var task in tasks) { if (Int32.Parse(task.taskPosition) == (Int32.Parse(completedTask.taskPosition)) + 1) { nextTask.id_task = task.id_task; break; } } //update actual stage if is final task if (nextTask.id_task == null) { // completes actual stage ProcessManagmentProvider processManagmentProvider = new ProcessManagmentProvider(); StageDTO actualStage = new StageDTO(); actualStage.id_stage = completedTask.stage_id; actualStage.isCompleted = "True"; actualStage.completedDate = DateTime.Now.ToString(); actualStage.userLog = Request.Cookies["user_id"].Value; actualStage.processManagment_id = processManagmentProvider.getStage(actualStage.id_stage).Result.processManagment_id; bool isStageUpdated = processManagmentProvider.putStage(actualStage).Result; bool isFirstTaskSuccess = false; List <StageDTO> stages = processManagmentProvider.getStages(actualStage.processManagment_id).Result; foreach (var stage in stages) { if (stage.isCompleted == "False") { List <TaskDTO> stageTasks = taskProvider.getTasks(stage.id_stage).Result; if (stageTasks.Count >= 1) { // change state of first task on next stage TaskDTO firstTask = new TaskDTO(); firstTask.taskState_id = "1"; firstTask.id_task = stageTasks[0].id_task; firstTask.userLog = Request.Cookies["user_id"].Value; isFirstTaskSuccess = taskProvider.putTask(firstTask).Result; break; } else { // completes next stage StageDTO emtpyStage = new StageDTO(); emtpyStage.id_stage = stage.id_stage; emtpyStage.isCompleted = "True"; emtpyStage.completedDate = DateTime.Now.ToString(); emtpyStage.userLog = Request.Cookies["user_id"].Value; bool isEmptyStageUpdated = processManagmentProvider.putStage(actualStage).Result; } } } // completes process if (!isFirstTaskSuccess) { ProcessProvider processProvider = new ProcessProvider(); ProcessDTO editedProcess = new ProcessDTO(); editedProcess.id_processManagment = actualProcess.id_processManagment; editedProcess.state_id = "2"; editedProcess.userLog = Request.Cookies["user_id"].Value; bool isProcessEdited = processProvider.putProcess(editedProcess).Result; } } //update next task if is not final task else { nextTask.userLog = Request.Cookies["user_id"].Value; List <TaskResponsableDTO> nextResponsables = taskProvider.getTaskResponsables(nextTask.id_task).Result; if (nextResponsables.Count == 0) { completeTask(nextTask.id_task); } else { nextTask.taskState_id = "1"; bool isNextSuccess = taskProvider.putTask(nextTask).Result; } } //send notifications List <TaskNotificationDTO> notifications = taskProvider.getTaskNotifications(id_task).Result; foreach (var notification in notifications) { TaskNotificationTypeDTO taskNotificationType = new TaskNotificationTypeDTO(); taskNotificationType.notification_id = notification.id_notification; taskNotificationType.userLog = Request.Cookies["user_id"].Value; taskNotificationType.isSended = "True"; List <TaskNotificationUserDTO> notificationUsers = taskProvider.getTaskNotificationUsers(notification.id_notification).Result; string msgHeader = "Gestión #" + actualProcess.id_processManagment + " " + actualProcess.name + ", Tarea " + completedTaskTemporal.name; //email if (notification.isEmail == "True") { taskNotificationType.type_id = "1"; foreach (var user in notificationUsers) { if (!String.IsNullOrEmpty(user.email)) { Tools.EmailService.sendEmail(user.email, msgHeader, notification.message); } } } //Telegram if (notification.isTelegram == "True") { taskNotificationType.type_id = "2"; foreach (var user in notificationUsers) { if (!String.IsNullOrEmpty(user.telegram_id)) { TelegramService.sendMessage(user.telegram_id, msgHeader + "\nMensaje:" + notification.message); } } } if (notification.isIntern == "True") { taskNotificationType.type_id = "0"; } bool isTypeUpdated = taskProvider.putTaskNotificationType(taskNotificationType).Result; } // apply changes List <TaskChangeDTO> changes = taskProvider.getTaskChanges(id_task).Result; List <OperationTypeDTO> operations = taskProvider.getOperationTypes().Result; foreach (var change in changes) { string operatorString = ""; foreach (var operation in operations) { if (operation.id_operationType == change.operation_id) { operatorString = operation.operation; } } if (String.IsNullOrEmpty(change.attributeList_id)) { GeneralAttributeDTO attribute = new CategorieProvider().getGeneralAttribute(change.attribute_id).Result; GeneralAttributeDTO editAttribute = new GeneralAttributeDTO(); editAttribute.id_attribute = change.attribute_id; editAttribute.value = change.value; DataTable dt = new DataTable(); var v = dt.Compute(attribute.value + operatorString + change.value, ""); //var v = dt.Compute("3 * (2+4)",""); change.operation_id } } }
public ActionResult _AddTask(Model.AddTaskModel model) { if (ModelState.IsValid) { List <TaskDTO> tasks = taskProvider.getTasks(model.id_stage).Result; TaskDTO taskDTO = new TaskDTO(); taskDTO.name = model.name; taskDTO.description = model.description; taskDTO.stage_id = model.id_stage; taskDTO.type_id = model.selected_taskType; if (tasks.Count == 0) { taskDTO.taskPosition = "0"; } else { taskDTO.taskPosition = (Int32.Parse(tasks[tasks.Count - 1].taskPosition) + 1).ToString(); } if (model.timeSelected == "time") { taskDTO.daysAvailable = model.daysAmount; taskDTO.hoursAvailable = model.hoursAmount; } else if (model.timeSelected == "date") { taskDTO.finishDate = model.timeDatePicker + " " + model.timeHour; } taskDTO.userLog = Request.Cookies["user_id"].Value; string id_task; if ((id_task = taskProvider.postTask(taskDTO).Result) != null) { id_task = id_task.Replace("\"", ""); bool isSuccess = false; TaskTypeDTO taskType = taskProvider.getTaskType(taskDTO.type_id).Result; if (taskType.formNeeded == "True") { TaskFormDTO taskForm = new TaskFormDTO(); taskForm.id_task = id_task; taskForm.description = ""; taskForm.userLog = taskDTO.userLog; if (taskProvider.postTaskForm(taskForm).Result) { isSuccess = true; } } else { isSuccess = true; } if (isSuccess) { StageDTO stageDTO = new ProcessManagmentProvider().getStage(taskDTO.stage_id).Result; if (taskProvider.putRefreshTaskTimes(stageDTO.processManagment_id).Result) { var result = new { id_task = id_task, viewHtml = PartialView("/Views/Tasks/_Tasks/_TasksList.cshtml", new Model.TasksModel(taskDTO.stage_id)).RenderToString() }; return(Json(result)); } } } } return(new HttpStatusCodeResult(404, "Can't find that")); }