Adress und shipping
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Webshop.Infrastructure.Repositories
|
||||
{
|
||||
internal class AdminShippingMethodsRepository
|
||||
{
|
||||
}
|
||||
}
|
||||
56
Webshop.Infrastructure/Repositories/AdressRepository.cs
Normal file
56
Webshop.Infrastructure/Repositories/AdressRepository.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
// src/Webshop.Infrastructure/Repositories/AddressRepository.cs
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Domain.Entities;
|
||||
using Webshop.Domain.Interfaces;
|
||||
using Webshop.Infrastructure.Data;
|
||||
|
||||
namespace Webshop.Infrastructure.Repositories
|
||||
{
|
||||
public class AddressRepository : IAddressRepository
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public AddressRepository(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Address>> GetAllForCustomerAsync(Guid customerId)
|
||||
{
|
||||
return await _context.Addresses
|
||||
.Where(a => a.CustomerId == customerId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<Address?> GetByIdAsync(Guid id)
|
||||
{
|
||||
return await _context.Addresses.FindAsync(id);
|
||||
}
|
||||
|
||||
public async Task AddAsync(Address address)
|
||||
{
|
||||
_context.Addresses.Add(address);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(Address address)
|
||||
{
|
||||
_context.Addresses.Update(address);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(Guid id)
|
||||
{
|
||||
var address = await _context.Addresses.FindAsync(id);
|
||||
if (address != null)
|
||||
{
|
||||
_context.Addresses.Remove(address);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Webshop.Infrastructure.Repositories
|
||||
{
|
||||
internal class CustomerAddressesRepository
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,7 @@ namespace Webshop.Infrastructure.Repositories
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ShippingMethod>> GetAllAsync() => await _context.ShippingMethods.ToListAsync();
|
||||
|
||||
public async Task<ShippingMethod?> GetByIdAsync(Guid id) // << HINZUFÜGEN >>
|
||||
{
|
||||
return await _context.ShippingMethods.FindAsync(id);
|
||||
}
|
||||
|
||||
public async Task<ShippingMethod?> GetByIdAsync(Guid id) => await _context.ShippingMethods.FindAsync(id);
|
||||
public async Task AddAsync(ShippingMethod shippingMethod) { _context.ShippingMethods.Add(shippingMethod); await _context.SaveChangesAsync(); }
|
||||
public async Task UpdateAsync(ShippingMethod shippingMethod) { _context.ShippingMethods.Update(shippingMethod); await _context.SaveChangesAsync(); }
|
||||
public async Task DeleteAsync(Guid id) { var entity = await _context.ShippingMethods.FindAsync(id); if (entity != null) { _context.ShippingMethods.Remove(entity); await _context.SaveChangesAsync(); } }
|
||||
|
||||
Reference in New Issue
Block a user