shop info
This commit is contained in:
74
Webshop.Application/Services/Admin/AdminShopInfoService.cs
Normal file
74
Webshop.Application/Services/Admin/AdminShopInfoService.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
// src/Webshop.Application/Services/Admin/AdminShopInfoService.cs
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Shop;
|
||||
using Webshop.Domain.Entities;
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public class AdminShopInfoService : IAdminShopInfoService
|
||||
{
|
||||
private readonly IShopInfoRepository _shopInfoRepository;
|
||||
|
||||
public AdminShopInfoService(IShopInfoRepository shopInfoRepository)
|
||||
{
|
||||
_shopInfoRepository = shopInfoRepository;
|
||||
}
|
||||
|
||||
public async Task<AdminShopInfoDto> GetShopInfoAsync()
|
||||
{
|
||||
var shopInfo = await _shopInfoRepository.GetAsync();
|
||||
|
||||
if (shopInfo == null)
|
||||
{
|
||||
// Erstelle einen Standardeintrag, falls keiner existiert
|
||||
shopInfo = new ShopInfo { Id = Guid.NewGuid(), ShopName = "Mein Webshop", ContactEmail = "admin@example.com" };
|
||||
await _shopInfoRepository.AddAsync(shopInfo);
|
||||
}
|
||||
|
||||
return new AdminShopInfoDto
|
||||
{
|
||||
ShopName = shopInfo.ShopName,
|
||||
Slogan = shopInfo.Slogan,
|
||||
ContactEmail = shopInfo.ContactEmail,
|
||||
PhoneNumber = shopInfo.PhoneNumber,
|
||||
Street = shopInfo.Street,
|
||||
City = shopInfo.City,
|
||||
PostalCode = shopInfo.PostalCode,
|
||||
Country = shopInfo.Country,
|
||||
VatNumber = shopInfo.VatNumber,
|
||||
CompanyRegistrationNumber = shopInfo.CompanyRegistrationNumber,
|
||||
FacebookUrl = shopInfo.FacebookUrl,
|
||||
InstagramUrl = shopInfo.InstagramUrl,
|
||||
TwitterUrl = shopInfo.TwitterUrl
|
||||
};
|
||||
}
|
||||
|
||||
public async Task UpdateShopInfoAsync(AdminShopInfoDto shopInfoDto)
|
||||
{
|
||||
var shopInfo = await _shopInfoRepository.GetAsync();
|
||||
if (shopInfo == null)
|
||||
{
|
||||
throw new InvalidOperationException("ShopInfo entity does not exist and cannot be updated.");
|
||||
}
|
||||
|
||||
// Mappe die Werte vom DTO auf die Entität
|
||||
shopInfo.ShopName = shopInfoDto.ShopName;
|
||||
shopInfo.Slogan = shopInfoDto.Slogan;
|
||||
shopInfo.ContactEmail = shopInfoDto.ContactEmail;
|
||||
shopInfo.PhoneNumber = shopInfoDto.PhoneNumber;
|
||||
shopInfo.Street = shopInfoDto.Street;
|
||||
shopInfo.City = shopInfoDto.City;
|
||||
shopInfo.PostalCode = shopInfoDto.PostalCode;
|
||||
shopInfo.Country = shopInfoDto.Country;
|
||||
shopInfo.VatNumber = shopInfoDto.VatNumber;
|
||||
shopInfo.CompanyRegistrationNumber = shopInfoDto.CompanyRegistrationNumber;
|
||||
shopInfo.FacebookUrl = shopInfoDto.FacebookUrl;
|
||||
shopInfo.InstagramUrl = shopInfoDto.InstagramUrl;
|
||||
shopInfo.TwitterUrl = shopInfoDto.TwitterUrl;
|
||||
|
||||
await _shopInfoRepository.UpdateAsync(shopInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// src/Webshop.Application/Services/Admin/IAdminShopInfoService.cs
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Shop;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public interface IAdminShopInfoService
|
||||
{
|
||||
Task<AdminShopInfoDto> GetShopInfoAsync();
|
||||
Task UpdateShopInfoAsync(AdminShopInfoDto shopInfoDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// src/Webshop.Application/Services/Public/IShopInfoService.cs
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Shop;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public interface IShopInfoService
|
||||
{
|
||||
Task<PublicShopInfoDto> GetPublicShopInfoAsync();
|
||||
}
|
||||
}
|
||||
43
Webshop.Application/Services/Public/ShopInfoService.cs
Normal file
43
Webshop.Application/Services/Public/ShopInfoService.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
// src/Webshop.Application/Services/Public/ShopInfoService.cs
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Shop;
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public class ShopInfoService : IShopInfoService
|
||||
{
|
||||
private readonly IShopInfoRepository _shopInfoRepository;
|
||||
|
||||
public ShopInfoService(IShopInfoRepository shopInfoRepository)
|
||||
{
|
||||
_shopInfoRepository = shopInfoRepository;
|
||||
}
|
||||
|
||||
public async Task<PublicShopInfoDto> GetPublicShopInfoAsync()
|
||||
{
|
||||
var shopInfo = await _shopInfoRepository.GetAsync();
|
||||
|
||||
if (shopInfo == null)
|
||||
{
|
||||
// Gib Standardwerte zurück, wenn nichts konfiguriert ist
|
||||
return new PublicShopInfoDto { ShopName = "Webshop" };
|
||||
}
|
||||
|
||||
return new PublicShopInfoDto
|
||||
{
|
||||
ShopName = shopInfo.ShopName,
|
||||
Slogan = shopInfo.Slogan,
|
||||
ContactEmail = shopInfo.ContactEmail,
|
||||
PhoneNumber = shopInfo.PhoneNumber,
|
||||
Street = shopInfo.Street,
|
||||
City = shopInfo.City,
|
||||
PostalCode = shopInfo.PostalCode,
|
||||
Country = shopInfo.Country,
|
||||
FacebookUrl = shopInfo.FacebookUrl,
|
||||
InstagramUrl = shopInfo.InstagramUrl,
|
||||
TwitterUrl = shopInfo.TwitterUrl
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user