74 lines
2.9 KiB
C#
74 lines
2.9 KiB
C#
// 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);
|
|
}
|
|
}
|
|
} |