public ActionResult UpdateDrop(JsonComboUpdate update) { int success = 0; string message = "Unable to save in database"; Tasks task = db.Tasks.Find(update.TaskID); if (task == null) { message = "Task not found."; } else { switch (update.Operation) { case OperationType.SupportingIS: { int sisID = 0; int.TryParse(update.Value, out sisID); if (update.Value != null && db.SupportingIS.Where(x => sisID == x.SupportingISID).Count() <= 0) { message = "Unknown system."; } else { task.SupportingISID = sisID == 0 ? (int?)null : sisID; db.SaveChanges(); success = 1; message = ""; } break; } case OperationType.HRFunction: { int entityID = 0; int.TryParse(update.Value, out entityID); if (update.Value != null && db.Entities.Where(x => entityID == x.EntityID).Count() <= 0) { message = "Unknown HR Function."; } else { task.HRFunctionID = entityID == 0 ? (int?)null : entityID; db.SaveChanges(); success = 1; message = ""; } break; } case OperationType.OrganisationUnit: { int organisationUnitID = 0; int.TryParse(update.Value, out organisationUnitID); if (update.Value != null && db.Entities.Where(x => organisationUnitID == x.EntityID).Count() <= 0) { message = "Unknown Organisation."; } else { task.OrganisationUnitID = organisationUnitID == 0 ? (int?)null : organisationUnitID; db.SaveChanges(); success = 1; message = ""; } break; } case OperationType.Skills: { int skillsID = 0; int.TryParse(update.Value, out skillsID); if (update.Value != null && db.HRSkills.Where(x => skillsID == x.HRSkillsID).Count() <= 0) { message = "Unknown skill."; } else { task.HRSkillsID = skillsID == 0 ? (int?)null : skillsID; db.SaveChanges(); success = 1; message = ""; } break; } default: { success = 0; message = "Unknown option"; break; } } } return(Json(new { code = success, message = message }, "application/json")); }
public ActionResult Update(JsonComboUpdate psvm) { int success = 0; string message = "Unable to save in database"; switch (psvm.Operation) { case OperationType.Name: { ProcessModels processModels = db.ProcessModels.Find(psvm.Identifier); processModels.Name = psvm.Value; db.SaveChanges(); success = 1; message = ""; break; } case OperationType.Parent: { ProcessModels processModels = db.ProcessModels.Find(psvm.Identifier); ProcessModels tmp = null; processModels.ParentID = psvm.Value == null ? null : (int?)int.Parse(psvm.Value); if (processModels.ParentID == null) { processModels.Level = 0; TasksController.RemoveAllTasks(processModels.ProcessID); } else { tmp = db.ProcessModels.Find(processModels.ParentID); processModels.Level = tmp.Level + 1; if (db.Tasks.Where(x => x.ProcessID == processModels.ProcessID).Count() == 0) { TasksController.AddNewTask(processModels.ProcessID); } } db.SaveChanges(); success = 2; message = ""; break; } case OperationType.Procedure: { ProcessModels processModels = db.ProcessModels.Find(psvm.Identifier); processModels.ProcedureID = psvm.Value == null ? null : (int?)int.Parse(psvm.Value); db.SaveChanges(); success = 1; message = ""; break; } case OperationType.Manager: { ProcessModels processModels = db.ProcessModels.Find(psvm.Identifier); processModels.ManagerID = psvm.Value == null ? null : (int?)int.Parse(psvm.Value); db.SaveChanges(); success = 1; message = ""; break; } } return(Json(new { code = success, message = message }, "application/json")); }