using CMSDAL.DTO.LearningPath; using CMSDAL.Query.LearningPath; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using Newtonsoft.Json; namespace CMSDAL.CustomCode.LearningPath; public class LearningPathDAL : ILearningPathDAL { private readonly IQueryExecutor _qe; public LearningPathDAL(IQueryExecutor qe) => _qe = qe; public async Task GetListAsync(LoginDTO loginDTO, CancellationToken ct) { var result = await _qe.QueryAsync(loginDTO, LearningPathQB.GET_LIST, new { TenantId = loginDTO.ClientId }, cancellationToken: ct).ConfigureAwait(false); return JsonConvert.SerializeObject(result); } public async Task GetItemsAsync(int learningPathId, LoginDTO loginDTO, CancellationToken ct) { var result = await _qe.QueryAsync(loginDTO, LearningPathQB.GET_ITEMS, new { LearningPathId = learningPathId, TenantId = loginDTO.ClientId }, cancellationToken: ct).ConfigureAwait(false); return JsonConvert.SerializeObject(result); } public async Task SaveAsync(LearningPathDTO dto, LoginDTO loginDTO, CancellationToken ct) { if (dto.LearningPathId == 0) { await _qe.ExecuteAsync(loginDTO, LearningPathQB.INSERT, new { dto.PathCode, dto.PathName, dto.Description, dto.Status, TenantId = loginDTO.ClientId, CreatedById = loginDTO.UserId, ModifiedById = loginDTO.UserId }, cancellationToken: ct).ConfigureAwait(false); } else { await _qe.ExecuteAsync(loginDTO, LearningPathQB.UPDATE, new { dto.LearningPathId, dto.PathName, dto.Description, dto.Status, TenantId = loginDTO.ClientId, ModifiedById = loginDTO.UserId }, cancellationToken: ct).ConfigureAwait(false); await _qe.ExecuteAsync(loginDTO, LearningPathQB.DELETE_ITEMS, new { dto.LearningPathId, TenantId = loginDTO.ClientId }, cancellationToken: ct).ConfigureAwait(false); } foreach (var item in dto.Items) { await _qe.ExecuteAsync(loginDTO, LearningPathQB.INSERT_ITEM, new { dto.LearningPathId, item.ContentId, item.PositionNo, item.IsRequired, item.MinSecs, TenantId = loginDTO.ClientId }, cancellationToken: ct).ConfigureAwait(false); } return dto.LearningPathId == 0 ? SuccessResponse.SaveSuccessMessage : SuccessResponse.UpdateSuccessMessage; } }