using System; using System.Collections.Generic; using System.Linq; using System.Web; using HLWebOKBAdminPlugin.OKBAdministrationService; using HLWebOKBAdminPlugin.Helpers; namespace HLWebOKBAdminPlugin.Models { public class AdminModel { //member var private IList algorithmClassList; public String SelectedSubMenu { get; set; } public IList AlgorithmClassProp { get { return AlgorithmClassGetAll(); } set { ;} } //***************************************Algorithm Class******************************************** //get all algorithm classes private IList AlgorithmClassGetAll() { AdministrationServiceClient adminClient = Admin.GetClientFactory(); algorithmClassList = new List(); if (adminClient != null) { AlgorithmClass[] algorithmClasses = adminClient.GetAlgorithmClasses(); foreach (AlgorithmClass ac in algorithmClasses) { algorithmClassList.Add(ac); } }//if (adminClient != null) return algorithmClassList; }//AlgorithmClassGetAll private long AddAlgorithmClass(AlgorithmClass algorithmClass) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { return adminClient.AddAlgorithmClass(algorithmClass); } return 0; }//AddAlgorithmClass public void DeleteAlgorithmClass(long id) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { adminClient.DeleteAlgorithmClass(id); } }//DeleteAlgorithmClass public long SaveAlgorithmClass(AlgorithmClass algorithmClass) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { if (algorithmClass.Id == 0) { return AddAlgorithmClass(algorithmClass); } else { AlgorithmClass ac = adminClient.GetAlgorithmClass(algorithmClass.Id); if (ac != null) { adminClient.UpdateAlgorithmClass(algorithmClass); return algorithmClass.Id; } } } return 0; }//SaveAlgorithmClass //***************************************Algorithms************************************************* //get all algorithms public IList AlgorithmsGetAll() { AdministrationServiceClient adminClient = Admin.GetClientFactory(); IList algorithmList = new List(); if (adminClient != null) { Algorithm[] algorithm = adminClient.GetAlgorithms(); foreach (Algorithm al in algorithm) { algorithmList.Add(al); } }//if (adminClient != null) return algorithmList; }//AlgorithmsGetAll private long AddAlgorithm(Algorithm algorithm) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { return adminClient.AddAlgorithm(algorithm); } return 0; }//AddAlgorithm public void DeleteAlgorithm(long id) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { adminClient.DeleteAlgorithm(id); } }//DeleteAlgorithm public long SaveAlgorithm(Algorithm algorithm) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { if (algorithm.Id == 0) { return AddAlgorithm(algorithm); } else { Algorithm al = adminClient.GetAlgorithm(algorithm.Id); if (al != null) { adminClient.UpdateAlgorithm(algorithm); return algorithm.Id; } } } return 0; }//SaveAlgorithm //***************************************Problem Class********************************************** public IList ProblemClassGetAll() { AdministrationServiceClient adminClient = Admin.GetClientFactory(); IList problemClassList = new List(); if (adminClient != null) { ProblemClass[] problemClasses = adminClient.GetProblemClasses(); foreach (ProblemClass pc in problemClasses) { problemClassList.Add(pc); } }//if (adminClient != null) return problemClassList; }//ProblemClassGetAll private long AddProblemClass(ProblemClass problemClass) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { return adminClient.AddProblemClass(problemClass); } return 0; }//AddProblemClass public void DeleteProblemClass(long id) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { adminClient.DeleteProblemClass(id); } }//DeleteProblemClass public long SaveProblemClass(ProblemClass problemClass) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { if (problemClass.Id == 0) { return AddProblemClass(problemClass); } else { ProblemClass pc = adminClient.GetProblemClass(problemClass.Id); if (pc != null) { adminClient.UpdateProblemClass(problemClass); return problemClass.Id; } } } return 0; }//SaveProblemClass //***************************************Problems*************************************************** public IList ProblemsGetAll() { AdministrationServiceClient adminClient = Admin.GetClientFactory(); IList problemList = new List(); if (adminClient != null) { Problem[] problem = adminClient.GetProblems(); foreach (Problem pr in problem) { problemList.Add(pr); } }//if (adminClient != null) return problemList; }//ProblemsGetAll private long AddProblem(Problem problem) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { return adminClient.AddProblem(problem); } return 0; }//AddProblem public void DeleteProblem(long id) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { adminClient.DeleteProblem(id); } }//DeleteProblem public long SaveProblem(Problem problem) { AdministrationServiceClient adminClient = Admin.GetClientFactory(); if (adminClient != null) { if (problem.Id == 0) { return AddProblem(problem); } else { Problem pr = adminClient.GetProblem(problem.Id); if (pr != null) { adminClient.UpdateProblem(problem); return problem.Id; } } } return 0; }//SaveProblem } }