namespace LaaProduction.Personalization { using LaaProduction.Personalization.Interfaces; using LaaProduction.Personalization.Models; using LaaProduction.Personalization.Repositories.Interfaces; using LaaProductionDI; using System; using System.Collections.Generic; public class SoftwareManager : ISoftwareManager { private readonly IFunctionsRepository functionsRepository; private readonly ISoftwareRepository softwareRepository; public SoftwareManager() { this.functionsRepository = LaaServiceProvider.GetService(); this.softwareRepository = LaaServiceProvider.GetService(); } public void AddVersion(short softwareId, string assemblyName, int majorV, int minorV, int buildV, DateTime validUntil, string description) => this.softwareRepository.AddVersion(softwareId, assemblyName, majorV, minorV, buildV, validUntil, description); public void DeleteVersion(int versionId) => this.softwareRepository.Delete(versionId); public void EditVersion(int versionId, DateTime? validUntil, string description) => this.softwareRepository.EditVersion(versionId, validUntil, description); public IEnumerable GetFunctions() => this.functionsRepository.All() ?? Array.Empty(); public IEnumerable GetFunctions(string token) => this.functionsRepository.Find(token) ?? Array.Empty(); public IEnumerable ListSoftwares() => this.softwareRepository.List() ?? Array.Empty(); public object SoftwareDeteils(int versionId) { var softwareDetails = this.softwareRepository.Details(versionId); if (softwareDetails != null) { softwareDetails.Versions = this.softwareRepository.Versions(softwareDetails.SoftwareId); softwareDetails.Functions = this.softwareRepository.Functions(softwareDetails.SoftwareId); } return softwareDetails; } public void UpdateFunction(short softwareId, int functionId, string function, IEnumerable employees) { if (this.functionsRepository.Exists(softwareId, functionId)) { this.functionsRepository.DeleteEmployeesFunctions(functionId); if (string.IsNullOrWhiteSpace(function)) { this.functionsRepository.DeleteFunction(functionId); } else { this.functionsRepository.UpdateFunction(functionId, function); this.functionsRepository.AddEmployeesFunctions(functionId, employees); } } else { if (!string.IsNullOrWhiteSpace(function)) { functionId = this.functionsRepository.AddFunction(softwareId, function); if (functionId > 0) { this.functionsRepository.AddEmployeesFunctions(functionId, employees); } } } } } }