ASP.NET / ASP.NET E-commerce Website Using Vue / DAL / DAO / CustomerDAO.cs
CustomerDAO.cs
Raw
using Casestudy.DAL.DomainClasses;
using Microsoft.EntityFrameworkCore;
namespace Casestudy.DAL.DAO
{
    public class CustomerDAO
    {
        private readonly AppDbContext _db;
        public CustomerDAO(AppDbContext ctx)
        {
            _db = ctx;
        }
        public async Task<List<Customer>> GetAll()
        {
            return await _db.Customers!.ToListAsync();
        }

        public async Task<Customer> Register(Customer customer)
        {
            await _db.Customers!.AddAsync(customer);
            await _db.SaveChangesAsync();
            return customer;
        }
        public async Task<Customer?> GetByEmail(string? email)
        {
            Customer? user = await _db.Customers!.FirstOrDefaultAsync(u => u.Email == email);
            return user;
        }
    }
}