public ActionResult _EditStage(string name, string id_stage, string stagePosition) { if (ModelState.IsValid) { StageDTO stageDTO = new StageDTO(); stageDTO.id_stage = id_stage; stageDTO.name = name; stageDTO.stagePosition = stagePosition; stageDTO.userLog = Request.Cookies["user_id"].Value; if (processManagmentProvider.putStage(stageDTO).Result) { var result = new { name = name, id_stage = id_stage }; return(Json(result)); } } 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 } } }