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> 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 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 CreateProfile(ImportProfile profile) => await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Create); public async Task UpdateProfile(ImportProfile profile) => await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Update); public async Task DeleteProfile(ImportProfile profile) => await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Delete); private async Task 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; } } }