Jonathan Jenne 0a25b0925c 08-12-2022
2022-12-08 16:43:22 +01:00

68 lines
2.3 KiB
C#

using DigitalData.Modules.Logging;
using ECM.JobRunner.Common.JobRunnerReference;
namespace ECM.JobRunner.Web.Data
{
public class ImportService
{
private readonly Logger logger;
private readonly IEDMIServiceChannel channel;
public ImportService(LoggingService Logging, WcfService Wcf)
{
logger = Logging.LogConfig.GetLogger();
channel = Wcf.Channel;
}
public async Task<List<ImportProfile>> GetProfiles()
{
var resp = await channel.GetJobConfigAsync();
if (resp == null) return new();
if (resp.OK == false) return new();
var profiles = resp.ProfileDefinitions.ImportProfiles.ToList();
return profiles;
}
public async Task<ImportProfile?> GetProfile(int pProfileId)
{
var resp = await channel.GetJobConfigAsync();
if (resp == null) return new();
if (resp.OK == false) return new();
var jobs = resp.JobDefinitions.ToList();
var profiles = resp.ProfileDefinitions.ImportProfiles.ToList();
return profiles.
Where(p => p.Id == pProfileId).
SingleOrDefault();
}
public async Task<bool> CreateProfile(ImportProfile profile) =>
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Create);
public async Task<bool> UpdateProfile(ImportProfile profile) =>
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Update);
public async Task<bool> DeleteProfile(ImportProfile profile) =>
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Delete);
private async Task<bool> DoUpdateProfile(ImportProfile profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction action)
{
var req = new UpdateProfileUpdateProfileRequest()
{
ImportProfile = profile,
Action = action
};
var resp = await channel.UpdateProfileAsync(req);
if (resp == null) return false;
if (resp.OK == false) return false;
return true;
}
}
}