Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4426 for trunk/sources


Ignore:
Timestamp:
09/18/10 04:03:28 (14 years ago)
Author:
swagner
Message:

Worked on OKB data model and services (#1174)

Location:
trunk/sources/HeuristicLab.Services.OKB/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Services.OKB/3.3/AdminService.cs

    r4407 r4426  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Data.Linq;
    2324using System.Linq;
     
    3132  [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    3233  public class AdminService : IAdminService {
    33     public void AddAlgorithmClass(AlgorithmClass algorithmClass) {
    34       using (OKBDataContext okb = new OKBDataContext()) {
    35         okb.AlgorithmClasses.InsertOnSubmit(new AlgorithmClass() {
    36           Name = algorithmClass.Name,
    37           Description = algorithmClass.Description
    38         });
    39         okb.SubmitChanges();
    40       }
    41     }
    42     public AlgorithmClass[] GetAlgorithmClasses() {
     34    public AlgorithmClass GetAlgorithmClass(long algorithmClassId) {
     35      using (OKBDataContext okb = new OKBDataContext()) {
     36        return okb.AlgorithmClasses.FirstOrDefault(a => a.Id == algorithmClassId);
     37      }
     38    }
     39    public IEnumerable<AlgorithmClass> GetAlgorithmClasses() {
    4340      using (OKBDataContext okb = new OKBDataContext()) {
    4441        return okb.AlgorithmClasses.ToArray();
    4542      }
    4643    }
    47     public void UpdateAlgorithmClass(AlgorithmClass algorithmClass) {
    48       using (OKBDataContext okb = new OKBDataContext()) {
    49         AlgorithmClass original = okb.AlgorithmClasses.First(a => a.Id == algorithmClass.Id);
    50         original.Name = algorithmClass.Name;
    51         original.Description = algorithmClass.Description;
     44    public void StoreAlgorithmClass(AlgorithmClass algorithmClass) {
     45      using (OKBDataContext okb = new OKBDataContext()) {
     46        AlgorithmClass original = okb.AlgorithmClasses.FirstOrDefault(a => a.Id == algorithmClass.Id);
     47        if (original == null) {
     48          okb.AlgorithmClasses.InsertOnSubmit(new AlgorithmClass() {
     49            Name = algorithmClass.Name,
     50            Description = algorithmClass.Description
     51          });
     52        } else {
     53          original.Name = algorithmClass.Name;
     54          original.Description = algorithmClass.Description;
     55        }
    5256        okb.SubmitChanges();
    5357      }
     
    6064    }
    6165
    62     public void AddAlgorithm(Algorithm algorithm) {
    63       using (OKBDataContext okb = new OKBDataContext()) {
    64         okb.Algorithms.InsertOnSubmit(new Algorithm() {
    65           AlgorithmClassId = algorithm.AlgorithmClassId,
    66           PlatformId = algorithm.PlatformId,
    67           Name = algorithm.Name,
    68           Description = algorithm.Description
    69         });
    70         okb.SubmitChanges();
    71       }
    72     }
    73     public Algorithm[] GetAlgorithms() {
     66    public Algorithm GetAlgorithm(long algorithmId) {
     67      using (OKBDataContext okb = new OKBDataContext()) {
     68        return okb.Algorithms.FirstOrDefault(a => a.Id == algorithmId);
     69      }
     70    }
     71    public IEnumerable<Algorithm> GetAlgorithms() {
    7472      using (OKBDataContext okb = new OKBDataContext()) {
    7573        return okb.Algorithms.ToArray();
    7674      }
    7775    }
    78     public void UpdateAlgorithm(Algorithm algorithm) {
    79       using (OKBDataContext okb = new OKBDataContext()) {
    80         Algorithm original = okb.Algorithms.First(a => a.Id == algorithm.Id);
    81         original.AlgorithmClassId = algorithm.AlgorithmClassId;
    82         original.PlatformId = algorithm.PlatformId;
    83         original.Name = algorithm.Name;
    84         original.Description = algorithm.Description;
     76    public void StoreAlgorithm(Algorithm algorithm) {
     77      using (OKBDataContext okb = new OKBDataContext()) {
     78        Algorithm original = okb.Algorithms.FirstOrDefault(a => a.Id == algorithm.Id);
     79        if (original == null) {
     80          okb.Algorithms.InsertOnSubmit(new Algorithm() {
     81            Name = algorithm.Name,
     82            Description = algorithm.Description
     83          });
     84        } else {
     85          original.Name = algorithm.Name;
     86          original.Description = algorithm.Description;
     87        }
    8588        okb.SubmitChanges();
    8689      }
  • trunk/sources/HeuristicLab.Services.OKB/3.3/Interfaces/IAdminService.cs

    r4407 r4426  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Net.Security;
    2324using System.ServiceModel;
     
    3132  public interface IAdminService {
    3233    [OperationContract]
    33     void AddAlgorithmClass(AlgorithmClass algorithmClass);
     34    AlgorithmClass GetAlgorithmClass(long algorithmClassId);
    3435    [OperationContract]
    35     AlgorithmClass[] GetAlgorithmClasses();
     36    IEnumerable<AlgorithmClass> GetAlgorithmClasses();
    3637    [OperationContract]
    37     void UpdateAlgorithmClass(AlgorithmClass algorithmClass);
     38    void StoreAlgorithmClass(AlgorithmClass algorithmClass);
    3839    [OperationContract]
    3940    void DeleteAlgorithmClass(long algorithmClassId);
    4041
    4142    [OperationContract]
    42     void AddAlgorithm(Algorithm algorithm);
     43    Algorithm GetAlgorithm(long algorithmId);
    4344    [OperationContract]
    44     Algorithm[] GetAlgorithms();
     45    IEnumerable<Algorithm> GetAlgorithms();
    4546    [OperationContract]
    46     void UpdateAlgorithm(Algorithm algorithm);
     47    void StoreAlgorithm(Algorithm algorithm);
    4748    [OperationContract]
    4849    void DeleteAlgorithm(long algorithmId);
Note: See TracChangeset for help on using the changeset viewer.