using MBDEVproAPI.Common.Models;
using MBDEVproAPI.Common.ViewModels;
using MBDEVproAPI.DataModel;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace MBDEVproAPI.Repository.Repositories
{
public class CustomerRepository : BaseRepository, ICustomerRepository
{
#region Private variables & constructors
///
/// Context
///
private readonly MBDEVproAPIDbContext _context;
///
/// Default contructor
///
///
public CustomerRepository(MBDEVproAPIDbContext context)
{
_context = context;
}
#endregion
#region Get All Customers Async
///
/// GET: Get All Customers Async
///
///
///
public async Task> GetAllCustomersAsync(int BusinessID)
{
var customers = await _context.Customers.Where(O => O.BusinessID == BusinessID).ToListAsync();
return customers;
}
#endregion
#region Get Customer by CustomerID Async
public async Task GetCustomerAsync(int CustomerID)
{
var customer = await _context.Customers.Where(O => O.CustomerID == CustomerID).FirstOrDefaultAsync();
if (customer == null)
{
Log.Error("Customer API: CustomerRepository(GetCustomerAsync); (customer == null)");
return new Customer();
}
else
{
return customer;
}
}
#endregion
#region other
public IEnumerable GetAll(int BusinessID)
{
var customers = _context.Customers.Where(O => O.BusinessID == BusinessID).ToList();
return customers;
}
/////
///// Get a single record by ID
/////
/////
/////
/////
public Customer GetByID(int BusinessID, int? id)
{
var customer = _context.Customers.Where(O => O.BusinessID == BusinessID && O.CustomerID == id).FirstOrDefault();
if (customer == null)
{
throw new Exception("Customer not found");
}
else
{
return customer;
}
}
public void Add(Customer obj)
{
throw new NotImplementedException();
}
public void Remove(int BusinessID, Customer obj)
{
throw new NotImplementedException();
}
public void SaveChanges()
{
throw new NotImplementedException();
}
#endregion
}
}