public ActionResult _EditTaskChange(Model.EditTaskChangeModel pModel) { if (ModelState.IsValid) { CategorieProvider categorieProvider = new CategorieProvider(); TaskChangeDTO taskChange = new TaskChangeDTO(); taskChange.id_taskChange = pModel.id_taskChange; AttributeTypeDTO typeDTO; if (pModel.attribute_id.Substring(0, 1) == "l") { taskChange.attributeList_id = pModel.attribute_id.Substring(1); typeDTO = categorieProvider.getAttributeType(pModel.attributeList_type).Result; } else { taskChange.attribute_id = pModel.attribute_id.Substring(1); typeDTO = categorieProvider.getAttributeType(pModel.attribute_type).Result; } if (!(typeDTO.reg_expr == "" || new Regex(typeDTO.reg_expr).Match(pModel.value).Success)) { return(new HttpStatusCodeResult(404, "Error, el campo valor debe ser de tipo: " + typeDTO.type)); } taskChange.operation_id = pModel.operation_id; taskChange.value = pModel.value.ToString(); taskChange.userLog = Request.Cookies["user_id"].Value; if (taskProvider.putTaskChange(taskChange).Result) { return(new HttpStatusCodeResult(200)); } } return(new HttpStatusCodeResult(404, "Error, no se puede editar el cambio de dato")); }
public ActionResult _AddTaskChange(Model.TaskChangesModel pModel) { if (ModelState.IsValid) { CategorieProvider categorieProvider = new CategorieProvider(); TaskChangeDTO taskChange = new TaskChangeDTO(); taskChange.task_id = pModel.task_idA; AttributeTypeDTO typeDTO; if (pModel.attribute_idA.Substring(0, 1) == "l") { taskChange.attributeList_id = pModel.attribute_idA.Substring(1); AttributeListDTO attributeListDTO = categorieProvider.getAttributeList(taskChange.attributeList_id).Result; typeDTO = categorieProvider.getAttributeType(attributeListDTO.type_id).Result; } else { taskChange.attribute_id = pModel.attribute_idA.Substring(1); GeneralAttributeDTO generalAttributeDTO = categorieProvider.getGeneralAttribute(taskChange.attribute_id).Result; typeDTO = categorieProvider.getAttributeType(generalAttributeDTO.type_id).Result; } if (!(typeDTO.reg_expr == "" || new Regex(typeDTO.reg_expr).Match(pModel.valueA).Success)) { return(new HttpStatusCodeResult(404, "Error, el campo valor debe ser de tipo: " + typeDTO.type)); } taskChange.operation_id = pModel.operation_idA; taskChange.value = pModel.valueA.ToString(); taskChange.userLog = Request.Cookies["user_id"].Value; if (taskProvider.postTaskChange(taskChange).Result) { return(_TaskDataChangesList(taskChange.task_id)); } } return(new HttpStatusCodeResult(404, "Error, no se puede agregar el cambio de dato")); }
protected CategorieProvider GetCategorieProvider() { CategorieProvider categorie = null; if (categorie == null) { return(new CategorieProvider()); } return(categorie); }
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 } } }