Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/11/16 15:26:56 (9 years ago)
Author:
abeham
Message:

#2588: Added service/client methods to get a single solution by id

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

Legend:

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

    r13684 r13690  
    4848
    4949    [OperationContract]
     50    Solution GetSolution(long solutionId);
     51
     52    [OperationContract]
    5053    [FaultContract(typeof(MissingSolution))]
    5154    byte[] GetSolutionData(long solutionId);
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs

    r13684 r13690  
    148148    }
    149149
     150    public DataTransfer.Solution GetSolution(long solutionId) {
     151      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     152
     153      using (OKBDataContext okb = new OKBDataContext()) {
     154        // TODO: In case of multi-objective problems one has to check whether it contains single- or multi-objective problems
     155        var result = Convert.ToDto(okb.SingleObjectiveSolutions.SingleOrDefault(x => x.Id == solutionId));
     156        if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) {
     157          return result;
     158        } else {
     159          var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == result.ProblemId).ToList();
     160          if (problemUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers.Select(y => y.UserGroupId).ToList())) {
     161            return result;
     162          } else {
     163            return null;
     164          }
     165        }
     166      }
     167    }
     168
    150169    public byte[] GetSolutionData(long solutionId) {
    151170      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
Note: See TracChangeset for help on using the changeset viewer.