Files
uWine/uWine.Core.Infrastructure/Services/VineyardService.cs
T

79 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using uWine.Core.Domain.Entities;
using uWine.Core.Domain.Repositories;
namespace uWine.Core.Infrastructure.Services
{
public class VineyardService
{
public IVineyardRepository _vineyardRepository;
public CoordinatesService _coordinatesService;
public VineyardService(IVineyardRepository vineyardRepository, CoordinatesService coordinatesService)
{
_vineyardRepository = vineyardRepository;
_coordinatesService = coordinatesService;
}
public void Insert(Vineyard vineyard, int ownerId)
{
if (vineyard == null)
{
throw new ArgumentNullException(nameof(vineyard), "Vineyard cannot be null");
}
_vineyardRepository.Insert(vineyard, ownerId);
if (vineyard.Area != null || vineyard.Area.Count >0)
{
_coordinatesService.SaveArea(vineyard.Id, vineyard.Area);
}
}
public List<Vineyard> User(int userId)
{
if (userId <= 0)
{
throw new ArgumentException("User ID must be greater than zero.", nameof(userId));
}
var vineyards = _vineyardRepository.GetUserVineyards(userId);
if (vineyards == null || !vineyards.Any())
{
return new List<Vineyard>();
}
foreach (var vineyard in vineyards)
{
vineyard.Area = _coordinatesService.GetArea(vineyard.Id);
}
return vineyards;
}
public List<Vineyard> Owner(int ownerId)
{
if (ownerId <= 0)
{
throw new ArgumentException("Owner ID must be greater than zero.", nameof(ownerId));
}
var vineyards = _vineyardRepository.GetOwnerVineyards(ownerId);
if (vineyards == null || !vineyards.Any())
{
return new List<Vineyard>();
}
foreach (var vineyard in vineyards)
{
vineyard.Area = _coordinatesService.GetArea(vineyard.Id);
}
return vineyards;
}
}
}