/* * Description: This is the call DAO class. It contains the async methods GetById, GetAll, Add, Update, and Delete */ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace HelpdeskDAL { public class CallDAO { //Using Repository readonly IRepository<Call> _repo; public CallDAO() { _repo = new HelpdeskRepository<Call>(); } // // Retrieve Call by Id // public async Task<Call> GetById(int id) { Call? selectedCall; try { selectedCall = await _repo.GetOne(call => call.Id == id); } catch (Exception ex) { Debug.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod()!.Name + " " + ex.Message); throw; } return selectedCall!; } // // Retrieve All Calls // public async Task<List<Call>> GetAll() { List<Call> allCalls; try { allCalls = await _repo.GetAll(); } catch (Exception ex) { Debug.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod()!.Name + " " + ex.Message); throw; } return allCalls; } // // Add a Call // public async Task<int> Add(Call newCall) { try { await _repo.Add(newCall); } catch (Exception ex) { Debug.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod()!.Name + " " + ex.Message); throw; } return newCall.Id; } // // Update a Call // public async Task<UpdateStatus> Update(Call updatedCall) { UpdateStatus status; try { status = await _repo.Update(updatedCall); } catch (Exception ex) { Debug.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod()!.Name + " " + ex.Message); throw; } return status; } // // Delete a Call // public async Task<int> Delete(int? id) { int CallsDeleted; try { CallsDeleted = await _repo.Delete((int)id!); } catch (Exception ex) { Debug.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod()!.Name + " " + ex.Message); throw; } return CallsDeleted; } } }