using System; using System.Collections.Generic; using System.Threading.Tasks; using FrameworkDAL.CustomCode.Comment; using FrameworkDAL.DTO.Comment; using GB5Shared.DTO.Framework.AutoNumber; using GB5Shared.DTO.Framework.Login; using GB5Shared.GenerateAutoNumber; using GB5Shared.ResponseStandard; namespace FrameworkBLL.Comment { public class CommentBLL : ICommentBLL { private readonly ICommentDAL _commentDAL; private readonly AutoNumber _autoNumber; public CommentBLL(ICommentDAL commentDAL, AutoNumber autoNumber) { _commentDAL = commentDAL; _autoNumber = autoNumber; } public async Task GetComment(int CommentId, LoginDTO LoginDTO) { try { return await _commentDAL.GetComment(CommentId, LoginDTO); } catch (Exception) { throw; } } public async Task SaveComment(CommentDTO CommentDTO, LoginDTO LoginDTO) { try { int initialId = CommentDTO.CommentId; int count = 1 + initialId; if (initialId == 0) { AutoNumberDTO autoNumberDTO = await _autoNumber.GetNumberAsync(count, "COMMENT", LoginDTO); CommentDTO.CommentId = autoNumberDTO.StartNumber; await _commentDAL.SaveComment(CommentDTO, LoginDTO); return $"Comment saved successfully with CommentId {CommentDTO.CommentId}"; } else { await _commentDAL.UpdateComment(CommentDTO, LoginDTO); return $"Comment updated successfully with CommentId {CommentDTO.CommentId}"; } } catch (Exception) { throw; } } public async Task> DeleteComment(int CommentId, LoginDTO LoginDTO) { try { return await _commentDAL.DeleteComment(CommentId, LoginDTO); } catch (Exception) { throw; } } } }