I have these classes TypeOfVehicle, Vehicle and manufacture. My service layer looks like this now.
public partial interface ITypeOfVehicleService
{
TypeOfVehicleRecord GetTypeOfVehicleById(int id);
void DeleteTypeOfVehicle(TypeOfVehicleRecord typeOfVehicle);
void UpdateTypeOfVehicle(TypeOfVehicleRecord typeOfVehicle);
void InsertTypeOfVehicle(TypeOfVehicleRecord typeOfVehicle);
IPagedList<TypeOfVehicleRecord> GetAllTypeOfVehicles(string typeOfVehicleName = "",
int pageIndex = 0, int pageSize = int.MaxValue);
}
My service class looks like this.
public partial class TypeOfVehicleService : ITypeOfVehicleService
{
private readonly IRepository<TypeOfVehicleRecord> _typeOfVehicleRepository;
private readonly IEventPublisher _eventPublisher;
public TypeOfVehicleService(IRepository<TypeOfVehicleRecord> typeOfVehicleRepository, IEventPublisher eventPublisher)
{
this._typeOfVehicleRepository = typeOfVehicleRepository;
this._eventPublisher = eventPublisher;
}
public virtual IPagedList<TypeOfVehicleRecord> GetAllTypeOfVehicles(string typeOfVehicleName = "",
int pageIndex = 0, int pageSize = int.MaxValue)
{
var query = _typeOfVehicleRepository.Table;
query = query.OrderBy(x => x.TypeOfVehicleName);
var typeOfVehicles = new PagedList<TypeOfVehicleRecord>(query, pageIndex, pageSize);
return typeOfVehicles;
}
public virtual void InsertTypeOfVehicle(TypeOfVehicleRecord typeOfVehicle)
{
if (typeOfVehicle == null) { throw new ArgumentNullException("typeOfVehicle"); }
_typeOfVehicleRepository.Insert(typeOfVehicle);
_eventPublisher.EntityInserted(typeOfVehicle);
}
public virtual void UpdateTypeOfVehicle(TypeOfVehicleRecord typeOfVehicle)
{
if (typeOfVehicle == null) { throw new ArgumentNullException("typeOfVehicle"); }
_typeOfVehicleRepository.Update(typeOfVehicle);
_eventPublisher.EntityUpdated(typeOfVehicle);
}
public virtual void DeleteTypeOfVehicle(TypeOfVehicleRecord typeOfVehicle)
{
if (typeOfVehicle == null) { throw new ArgumentNullException("typeOfVehicle"); }
_typeOfVehicleRepository.Delete(typeOfVehicle);
_eventPublisher.EntityDeleted(typeOfVehicle);
}
public virtual TypeOfVehicleRecord GetTypeOfVehicleById(int id)
{
if (id == 0)
return null;
return _typeOfVehicleRepository.GetById(id);
}
}
Do I need to write service and Iservice for all my entities or can I use the same? If I can use the same, how will I do that?