#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Data.Linq; using System.Linq; using System.ServiceModel; using HeuristicLab.Services.OKB.DataAccess; namespace HeuristicLab.Services.OKB { /// /// Implementation of the OKB service (interface ). /// [ServiceBehavior(IncludeExceptionDetailInFaults = true)] public class OKBService : IOKBService { #region Platform Methods public DataTransfer.Platform GetPlatform(long id) { using (OKBDataContext okb = new OKBDataContext()) { return Convert.ToDto(okb.Platforms.FirstOrDefault(x => x.Id == id)); } } public IEnumerable GetPlatforms() { using (OKBDataContext okb = new OKBDataContext()) { return okb.Platforms.Select(x => Convert.ToDto(x)).ToArray(); } } public long AddPlatform(DataTransfer.Platform dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Platform entity = Convert.ToEntity(dto); entity.Id = 0; okb.Platforms.InsertOnSubmit(entity); okb.SubmitChanges(); return entity.Id; } } public void UpdatePlatform(DataTransfer.Platform dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == dto.Id); Convert.ToEntity(dto, entity); okb.SubmitChanges(); } } public void DeletePlatform(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == id); if (entity != null) okb.Platforms.DeleteOnSubmit(entity); okb.SubmitChanges(); } } #endregion #region DataType Methods public DataTransfer.DataType GetDataType(long id) { using (OKBDataContext okb = new OKBDataContext()) { return Convert.ToDto(okb.DataTypes.FirstOrDefault(x => x.Id == id)); } } public IEnumerable GetDataTypes() { using (OKBDataContext okb = new OKBDataContext()) { return okb.DataTypes.Select(x => Convert.ToDto(x)).ToArray(); } } public long AddDataType(DataTransfer.DataType dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.DataType entity = Convert.ToEntity(dto); entity.Id = 0; okb.DataTypes.InsertOnSubmit(entity); okb.SubmitChanges(); return entity.Id; } } public void UpdateDataType(DataTransfer.DataType dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == dto.Id); Convert.ToEntity(dto, entity); okb.SubmitChanges(); } } public void DeleteDataType(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == id); if (entity != null) okb.DataTypes.DeleteOnSubmit(entity); okb.SubmitChanges(); } } #endregion #region AlgorithmClass Methods public DataTransfer.AlgorithmClass GetAlgorithmClass(long id) { using (OKBDataContext okb = new OKBDataContext()) { return Convert.ToDto(okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id)); } } public IEnumerable GetAlgorithmClasses() { using (OKBDataContext okb = new OKBDataContext()) { return okb.AlgorithmClasses.Select(x => Convert.ToDto(x)).ToArray(); } } public long AddAlgorithmClass(DataTransfer.AlgorithmClass dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.AlgorithmClass entity = Convert.ToEntity(dto); entity.Id = 0; okb.AlgorithmClasses.InsertOnSubmit(entity); okb.SubmitChanges(); return entity.Id; } } public void UpdateAlgorithmClass(DataTransfer.AlgorithmClass dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.AlgorithmClass entity = okb.AlgorithmClasses.FirstOrDefault(x => x.Id == dto.Id); Convert.ToEntity(dto, entity); okb.SubmitChanges(); } } public void DeleteAlgorithmClass(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.AlgorithmClass entity = okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id); if (entity != null) okb.AlgorithmClasses.DeleteOnSubmit(entity); okb.SubmitChanges(); } } #endregion #region Algorithm Methods public DataTransfer.Algorithm GetAlgorithm(long id) { using (OKBDataContext okb = new OKBDataContext()) { return Convert.ToDto(okb.Algorithms.FirstOrDefault(x => x.Id == id)); } } public IEnumerable GetAlgorithms() { using (OKBDataContext okb = new OKBDataContext()) { return okb.Algorithms.Select(x => Convert.ToDto(x)).ToArray(); } } public long AddAlgorithm(DataTransfer.Algorithm dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Algorithm entity = Convert.ToEntity(dto); entity.Id = 0; okb.Algorithms.InsertOnSubmit(entity); okb.SubmitChanges(); return entity.Id; } } public void UpdateAlgorithm(DataTransfer.Algorithm dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == dto.Id); Convert.ToEntity(dto, entity); okb.SubmitChanges(); } } public void DeleteAlgorithm(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == id); if (entity != null) okb.Algorithms.DeleteOnSubmit(entity); okb.SubmitChanges(); } } public IEnumerable GetAlgorithmUsers(long algorithmId) { using (OKBDataContext okb = new OKBDataContext()) { return okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId).Select(x => x.UserId).ToArray(); } } public void UpdateAlgorithmUsers(long algorithmId, IEnumerable users) { using (OKBDataContext okb = new OKBDataContext()) { okb.AlgorithmUsers.DeleteAllOnSubmit(okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId)); okb.AlgorithmUsers.InsertAllOnSubmit(users.Select(x => new DataAccess.AlgorithmUser { AlgorithmId = algorithmId, UserId = x })); okb.SubmitChanges(); } } #endregion #region AlgorithmData Methods public DataTransfer.AlgorithmData GetAlgorithmData(long algorithmId) { using (OKBDataContext okb = new OKBDataContext()) { return Convert.ToDto(okb.AlgorithmDatas.FirstOrDefault(x => x.AlgorithmId == algorithmId)); } } public void UpdateAlgorithmData(DataTransfer.AlgorithmData dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.AlgorithmData entity = okb.AlgorithmDatas.FirstOrDefault(x => x.AlgorithmId == dto.AlgorithmId); if (entity == null) okb.AlgorithmDatas.InsertOnSubmit(Convert.ToEntity(dto)); else Convert.ToEntity(dto, entity); okb.SubmitChanges(); } } #endregion #region AlgorithmParameter Methods public DataTransfer.AlgorithmParameter GetAlgorithmParameter(long id) { using (OKBDataContext okb = new OKBDataContext()) { return Convert.ToDto(okb.AlgorithmParameters.FirstOrDefault(x => x.Id == id)); } } public IEnumerable GetAlgorithmParameters(long algorithmId) { using (OKBDataContext okb = new OKBDataContext()) { return okb.AlgorithmParameters.Where(x => x.AlgorithmId == algorithmId).Select(x => Convert.ToDto(x)).ToArray(); } } public long AddAlgorithmParameter(DataTransfer.AlgorithmParameter dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.AlgorithmParameter entity = Convert.ToEntity(dto); entity.Id = 0; okb.AlgorithmParameters.InsertOnSubmit(entity); okb.SubmitChanges(); return entity.Id; } } public void UpdateAlgorithmParameter(DataTransfer.AlgorithmParameter dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.AlgorithmParameter entity = okb.AlgorithmParameters.FirstOrDefault(x => x.Id == dto.Id); Convert.ToEntity(dto, entity); okb.SubmitChanges(); } } public void DeleteAlgorithmParameter(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.AlgorithmParameter entity = okb.AlgorithmParameters.FirstOrDefault(x => x.Id == id); if (entity != null) okb.AlgorithmParameters.DeleteOnSubmit(entity); okb.SubmitChanges(); } } #endregion #region ProblemClass Methods public DataTransfer.ProblemClass GetProblemClass(long id) { using (OKBDataContext okb = new OKBDataContext()) { return Convert.ToDto(okb.ProblemClasses.FirstOrDefault(x => x.Id == id)); } } public IEnumerable GetProblemClasses() { using (OKBDataContext okb = new OKBDataContext()) { return okb.ProblemClasses.Select(x => Convert.ToDto(x)).ToArray(); } } public long AddProblemClass(DataTransfer.ProblemClass dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.ProblemClass entity = Convert.ToEntity(dto); entity.Id = 0; okb.ProblemClasses.InsertOnSubmit(entity); okb.SubmitChanges(); return entity.Id; } } public void UpdateProblemClass(DataTransfer.ProblemClass dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.ProblemClass entity = okb.ProblemClasses.FirstOrDefault(x => x.Id == dto.Id); Convert.ToEntity(dto, entity); okb.SubmitChanges(); } } public void DeleteProblemClass(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.ProblemClass entity = okb.ProblemClasses.FirstOrDefault(x => x.Id == id); if (entity != null) okb.ProblemClasses.DeleteOnSubmit(entity); okb.SubmitChanges(); } } #endregion #region Problem Methods public DataTransfer.Problem GetProblem(long id) { using (OKBDataContext okb = new OKBDataContext()) { return Convert.ToDto(okb.Problems.FirstOrDefault(x => x.Id == id)); } } public IEnumerable GetProblems() { using (OKBDataContext okb = new OKBDataContext()) { return okb.Problems.Select(x => Convert.ToDto(x)).ToArray(); } } public long AddProblem(DataTransfer.Problem dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Problem entity = Convert.ToEntity(dto); entity.Id = 0; okb.Problems.InsertOnSubmit(entity); okb.SubmitChanges(); return entity.Id; } } public void UpdateProblem(DataTransfer.Problem dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == dto.Id); Convert.ToEntity(dto, entity); okb.SubmitChanges(); } } public void DeleteProblem(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == id); if (entity != null) okb.Problems.DeleteOnSubmit(entity); okb.SubmitChanges(); } } public IEnumerable GetProblemUsers(long problemId) { using (OKBDataContext okb = new OKBDataContext()) { return okb.ProblemUsers.Where(x => x.ProblemId == problemId).Select(x => x.UserId).ToArray(); } } public void UpdateProblemUsers(long problemId, IEnumerable users) { using (OKBDataContext okb = new OKBDataContext()) { okb.ProblemUsers.DeleteAllOnSubmit(okb.ProblemUsers.Where(x => x.ProblemId == problemId)); okb.ProblemUsers.InsertAllOnSubmit(users.Select(x => new DataAccess.ProblemUser { ProblemId = problemId, UserId = x })); okb.SubmitChanges(); } } #endregion #region ProblemData Methods public DataTransfer.ProblemData GetProblemData(long problemId) { using (OKBDataContext okb = new OKBDataContext()) { return Convert.ToDto(okb.ProblemDatas.FirstOrDefault(x => x.ProblemId == problemId)); } } public void UpdateProblemData(DataTransfer.ProblemData dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.ProblemData entity = okb.ProblemDatas.FirstOrDefault(x => x.ProblemId == dto.ProblemId); if (entity == null) okb.ProblemDatas.InsertOnSubmit(Convert.ToEntity(dto)); else Convert.ToEntity(dto, entity); okb.SubmitChanges(); } } #endregion #region ProblemParameter Methods public DataTransfer.ProblemParameter GetProblemParameter(long id) { using (OKBDataContext okb = new OKBDataContext()) { return Convert.ToDto(okb.ProblemParameters.FirstOrDefault(x => x.Id == id)); } } public IEnumerable GetProblemParameters(long problemId) { using (OKBDataContext okb = new OKBDataContext()) { return okb.ProblemParameters.Where(x => x.ProblemId == problemId).Select(x => Convert.ToDto(x)).ToArray(); } } public long AddProblemParameter(DataTransfer.ProblemParameter dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.ProblemParameter entity = Convert.ToEntity(dto); entity.Id = 0; okb.ProblemParameters.InsertOnSubmit(entity); okb.SubmitChanges(); return entity.Id; } } public void UpdateProblemParameter(DataTransfer.ProblemParameter dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.ProblemParameter entity = okb.ProblemParameters.FirstOrDefault(x => x.Id == dto.Id); Convert.ToEntity(dto, entity); okb.SubmitChanges(); } } public void DeleteProblemParameter(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.ProblemParameter entity = okb.ProblemParameters.FirstOrDefault(x => x.Id == id); if (entity != null) okb.ProblemParameters.DeleteOnSubmit(entity); okb.SubmitChanges(); } } #endregion #region Result Methods public DataTransfer.Result GetResult(long id) { using (OKBDataContext okb = new OKBDataContext()) { return Convert.ToDto(okb.Results.FirstOrDefault(x => x.Id == id)); } } public IEnumerable GetResults(long algorithmId) { using (OKBDataContext okb = new OKBDataContext()) { return okb.Results.Where(x => x.AlgorithmId == algorithmId).Select(x => Convert.ToDto(x)).ToArray(); } } public long AddResult(DataTransfer.Result dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Result entity = Convert.ToEntity(dto); entity.Id = 0; okb.Results.InsertOnSubmit(entity); okb.SubmitChanges(); return entity.Id; } } public void UpdateResult(DataTransfer.Result dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Result entity = okb.Results.FirstOrDefault(x => x.Id == dto.Id); Convert.ToEntity(dto, entity); okb.SubmitChanges(); } } public void DeleteResult(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Result entity = okb.Results.FirstOrDefault(x => x.Id == id); if (entity != null) okb.Results.DeleteOnSubmit(entity); okb.SubmitChanges(); } } #endregion #region Experiment Methods public DataTransfer.Experiment GetExperiment(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith(x => x.AlgorithmParameterBlobValues); dlo.LoadWith(x => x.AlgorithmParameterBoolValues); dlo.LoadWith(x => x.AlgorithmParameterFloatValues); dlo.LoadWith(x => x.AlgorithmParameterIntValues); dlo.LoadWith(x => x.AlgorithmParameterStringValues); dlo.LoadWith(x => x.ProblemParameterBlobValues); dlo.LoadWith(x => x.ProblemParameterBoolValues); dlo.LoadWith(x => x.ProblemParameterFloatValues); dlo.LoadWith(x => x.ProblemParameterIntValues); dlo.LoadWith(x => x.ProblemParameterStringValues); okb.LoadOptions = dlo; return Convert.ToDto(okb.Experiments.FirstOrDefault(x => x.Id == id)); } } public IEnumerable GetExperiments(long algorithmId, long problemId) { using (OKBDataContext okb = new OKBDataContext()) { DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith(x => x.AlgorithmParameterBlobValues); dlo.LoadWith(x => x.AlgorithmParameterBoolValues); dlo.LoadWith(x => x.AlgorithmParameterFloatValues); dlo.LoadWith(x => x.AlgorithmParameterIntValues); dlo.LoadWith(x => x.AlgorithmParameterStringValues); dlo.LoadWith(x => x.ProblemParameterBlobValues); dlo.LoadWith(x => x.ProblemParameterBoolValues); dlo.LoadWith(x => x.ProblemParameterFloatValues); dlo.LoadWith(x => x.ProblemParameterIntValues); dlo.LoadWith(x => x.ProblemParameterStringValues); okb.LoadOptions = dlo; if ((algorithmId != 0) && (problemId != 0)) return okb.Experiments.Where(x => (x.AlgorithmId == algorithmId) && (x.ProblemId == problemId)).Select(x => Convert.ToDto(x)).ToArray(); else if (algorithmId != 0) return okb.Experiments.Where(x => x.AlgorithmId == algorithmId).Select(x => Convert.ToDto(x)).ToArray(); else if (problemId != 0) return okb.Experiments.Where(x => x.ProblemId == problemId).Select(x => Convert.ToDto(x)).ToArray(); else return okb.Experiments.Select(x => Convert.ToDto(x)).ToArray(); } } public long AddExperiment(DataTransfer.Experiment dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Experiment entity = Convert.ToEntity(dto); entity.Id = 0; DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith(x => x.AlgorithmParameterBlobValues); dlo.LoadWith(x => x.AlgorithmParameterBoolValues); dlo.LoadWith(x => x.AlgorithmParameterFloatValues); dlo.LoadWith(x => x.AlgorithmParameterIntValues); dlo.LoadWith(x => x.AlgorithmParameterStringValues); dlo.LoadWith(x => x.ProblemParameterBlobValues); dlo.LoadWith(x => x.ProblemParameterBoolValues); dlo.LoadWith(x => x.ProblemParameterFloatValues); dlo.LoadWith(x => x.ProblemParameterIntValues); dlo.LoadWith(x => x.ProblemParameterStringValues); okb.LoadOptions = dlo; var experiments = okb.Experiments.Where(x => ((x.AlgorithmId == entity.AlgorithmId) && (x.ProblemId == entity.ProblemId))).ToArray(); ExperimentEqualityComparer comparer = new ExperimentEqualityComparer(); Experiment exp = experiments.FirstOrDefault(x => comparer.Equals(x, entity)); if (exp != null) { return exp.Id; } else { okb.Experiments.InsertOnSubmit(entity); okb.SubmitChanges(); return entity.Id; } } } public void DeleteExperiment(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Experiment entity = okb.Experiments.FirstOrDefault(x => x.Id == id); if (entity != null) okb.Experiments.DeleteOnSubmit(entity); okb.SubmitChanges(); } } #endregion #region Run Methods public DataTransfer.Run GetRun(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith(x => x.ResultBlobValues); dlo.LoadWith(x => x.ResultBoolValues); dlo.LoadWith(x => x.ResultFloatValues); dlo.LoadWith(x => x.ResultIntValues); dlo.LoadWith(x => x.ResultStringValues); okb.LoadOptions = dlo; return Convert.ToDto(okb.Runs.FirstOrDefault(x => x.Id == id)); } } public IEnumerable GetRuns(long experimentId) { using (OKBDataContext okb = new OKBDataContext()) { DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith(x => x.ResultBlobValues); dlo.LoadWith(x => x.ResultBoolValues); dlo.LoadWith(x => x.ResultFloatValues); dlo.LoadWith(x => x.ResultIntValues); dlo.LoadWith(x => x.ResultStringValues); okb.LoadOptions = dlo; return okb.Runs.Where(x => x.ExperimentId == experimentId).Select(x => Convert.ToDto(x)).ToArray(); } } public long AddRun(DataTransfer.Run dto) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Run entity = Convert.ToEntity(dto); entity.Id = 0; okb.Runs.InsertOnSubmit(entity); okb.SubmitChanges(); return entity.Id; } } public void DeleteRun(long id) { using (OKBDataContext okb = new OKBDataContext()) { DataAccess.Run entity = okb.Runs.FirstOrDefault(x => x.Id == id); if (entity != null) okb.Runs.DeleteOnSubmit(entity); okb.SubmitChanges(); } } #endregion /* /// /// Gets the complete algorithm object graph up to the following entities: /// /// Parameter /// Algorithm_Paramters.Parameter.DataType /// Algorithm_Results.Result.DataType /// /// /// The algorithm id. /// An public Algorithm GetCompleteAlgorithm(int id) { using (OKBDataContext okb = new OKBDataContext()) { var dlo = new DataLoadOptions(); dlo.LoadWith(a => a.AlgorithmClass); dlo.LoadWith(a => a.Platform); dlo.LoadWith(a => a.AlgorithmUsers); dlo.LoadWith(u => u.User); okb.LoadOptions = dlo; return okb.Algorithms.Single(a => a.Id == id); } } /// /// Gets the complete problem object graph up to the following entities: /// /// Platform /// SolutionRepresentation /// Problem_Parameters.Parameter /// IntProblemCharacteristicValues.ProblemCharacteristic.DataType /// FloatProblemCharacteristicValues.ProblemCharacteristic.DataType /// CharProblemCharacteristicValues.ProblemCharacteristic.DataType /// /// /// The problem id. /// A public Problem GetCompleteProblem(int id) { using (OKBDataContext okb = new OKBDataContext()) { var dlo = new DataLoadOptions(); dlo.LoadWith(p => p.ProblemClass); dlo.LoadWith(p => p.Platform); dlo.LoadWith(p => p.ProblemUsers); dlo.LoadWith(u => u.User); okb.LoadOptions = dlo; return okb.Problems.Single(p => p.Id == id); } } /// /// Updates the algorithm object graph including the following properties and linked entitites: /// /// Name /// Description /// AlgorithmClassId /// PlatformId /// Algorithm_Parameters /// Algorithm_Results /// /// /// New s or s will not be /// created but have to be pre-existing. /// /// /// The algorithm. public void UpdateCompleteAlgorithm(Algorithm algorithm) { using (OKBDataContext okb = new OKBDataContext()) { Algorithm original = okb.Algorithms.Single(a => a.Id == algorithm.Id); UpdateAlgorithmData(algorithm, original, okb); okb.SubmitChanges(); } } /// /// Updates the problem object graph including the following properties and linked entities: /// /// Name /// Description /// ProblemClassId /// PlatformId /// SolutionRepresentationId /// IntProblemCharacteristicValues.Value /// FloatProblemCharacteristicValues.Value /// CharProblemCharacteristicValues.Value /// Problem_Parameters /// /// /// New s or s will /// not be created but have to be pre-existing. /// /// /// The problem. public void UpdateCompleteProblem(Problem problem) { using (OKBDataContext okb = new OKBDataContext()) { Problem originalProblem = okb.Problems.Single(p => p.Id == problem.Id); UpdateProblemData(problem, originalProblem, okb); okb.SubmitChanges(); } } private static void UpdateAlgorithmData(Algorithm algorithm, Algorithm original, OKBDataContext okb) { original.Name = algorithm.Name; original.Description = algorithm.Description; original.AlgorithmClassId = algorithm.AlgorithmClassId; original.PlatformId = algorithm.PlatformId; okb.AlgorithmUsers.DeleteAllOnSubmit(original.AlgorithmUsers); original.AlgorithmUsers.Clear(); foreach (var u in algorithm.AlgorithmUsers) { original.AlgorithmUsers.Add(new AlgorithmUser() { AlgorithmId = original.Id, UserId = u.UserId }); } } private static void UpdateProblemData(Problem problem, Problem original, OKBDataContext okb) { original.Name = problem.Name; original.Description = problem.Description; original.ProblemClassId = problem.ProblemClassId; original.SolutionRepresentationId = problem.SolutionRepresentationId; original.PlatformId = problem.PlatformId; okb.ProblemUsers.DeleteAllOnSubmit(original.ProblemUsers); original.ProblemUsers.Clear(); foreach (var u in problem.ProblemUsers) { original.ProblemUsers.Add(new ProblemUser() { ProblemId = original.Id, UserId = u.UserId }); } }*/ } }