Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/22/10 05:55:19 (14 years ago)
Author:
swagner
Message:

Worked on OKB (#1174)

File:
1 edited

Legend:

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

    r4455 r4467  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    110111        DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == id);
    111112        if (entity != null) okb.Algorithms.DeleteOnSubmit(entity);
     113        okb.SubmitChanges();
     114      }
     115    }
     116    public IEnumerable<Guid> GetAlgorithmUsers(long algorithmId) {
     117      using (OKBDataContext okb = new OKBDataContext()) {
     118        return okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId).Select(x => x.UserId).ToArray();
     119      }
     120    }
     121    public void StoreAlgorithmUsers(long algorithmId, IEnumerable<Guid> users) {
     122      using (OKBDataContext okb = new OKBDataContext()) {
     123        okb.AlgorithmUsers.DeleteAllOnSubmit(okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId));
     124        okb.AlgorithmUsers.InsertAllOnSubmit(users.Select(x => new DataAccess.AlgorithmUser { AlgorithmId = algorithmId, UserId = x }));
     125        okb.SubmitChanges();
     126      }
     127    }
     128    #endregion
     129
     130    #region AlgorithmData Methods
     131    public DataTransfer.AlgorithmData GetAlgorithmData(long algorithmId) {
     132      using (OKBDataContext okb = new OKBDataContext()) {
     133        return Convert.ToDto(okb.AlgorithmDatas.FirstOrDefault(x => x.AlgorithmId == algorithmId));
     134      }
     135    }
     136    public void StoreAlgorithmData(DataTransfer.AlgorithmData dto) {
     137      using (OKBDataContext okb = new OKBDataContext()) {
     138        DataAccess.AlgorithmData entity = okb.AlgorithmDatas.FirstOrDefault(x => x.AlgorithmId == dto.AlgorithmId);
     139        if (entity == null) okb.AlgorithmDatas.InsertOnSubmit(Convert.ToEntity(dto));
     140        else Convert.ToEntity(dto, entity);
     141        okb.SubmitChanges();
     142      }
     143    }
     144    #endregion
     145
     146    #region DataType Methods
     147    public DataTransfer.DataType GetDataType(long id) {
     148      using (OKBDataContext okb = new OKBDataContext()) {
     149        return Convert.ToDto(okb.DataTypes.FirstOrDefault(x => x.Id == id));
     150      }
     151    }
     152    public IEnumerable<DataTransfer.DataType> GetDataTypes() {
     153      using (OKBDataContext okb = new OKBDataContext()) {
     154        return okb.DataTypes.Select(x => Convert.ToDto(x)).ToArray();
     155      }
     156    }
     157    public void StoreDataType(DataTransfer.DataType dto) {
     158      using (OKBDataContext okb = new OKBDataContext()) {
     159        DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == dto.Id);
     160        if (entity == null) okb.DataTypes.InsertOnSubmit(Convert.ToEntity(dto));
     161        else Convert.ToEntity(dto, entity);
     162        okb.SubmitChanges();
     163      }
     164    }
     165    public void DeleteDataType(long id) {
     166      using (OKBDataContext okb = new OKBDataContext()) {
     167        DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == id);
     168        if (entity != null) okb.DataTypes.DeleteOnSubmit(entity);
    112169        okb.SubmitChanges();
    113170      }
Note: See TracChangeset for help on using the changeset viewer.