Skip to content
Permalink
Browse files

Implement both repositores (GetEntityById, GetAll,Add)

Closes #2
Closes #1
  • Loading branch information...
gariasf committed Mar 8, 2019
1 parent 48b4330 commit ea0dc0b9ae957c924bb93decbbc2416c559e9abc
@@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Mvc;
using VuelingExam.Bussiness.Facade.Filters;
using VuelingExam.Bussiness.Logic.Interfaces;
using VuelingExam.Bussiness.Logic.Interfaces.Crud;
using VuelingExam.Common.Logic.Models;

namespace VuelingExam.Bussiness.Facade.Controllers
@@ -17,11 +18,15 @@ public class ExamController : ControllerBase
{
private readonly IHttpFetcher<Client> ClientFetcher;
private readonly IHttpFetcher<Policy> PolicyFetcher;
private readonly IBussinessCrud<Client> ClientRepositoryBL;
private readonly IBussinessCrud<Client> PolicyRepositoryBL;

public ExamController(IHttpFetcher<Client> clientFetcher, IHttpFetcher<Policy> policyFetcher)
public ExamController(IHttpFetcher<Client> clientFetcher, IHttpFetcher<Policy> policyFetcher, IBussinessCrud<Client> clientRepository, IBussinessCrud<Client> policyRepository)
{
ClientFetcher = clientFetcher;
PolicyFetcher = policyFetcher;
ClientRepositoryBL = clientRepository;
PolicyRepositoryBL = policyRepository;
FetchExternalData();
}

@@ -34,38 +39,16 @@ private void FetchExternalData()
// GET api/values
[ConnectionFilter]
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
public ActionResult<IEnumerable<Client>> GetAllClients()
{
return new string[] { "value1", "value2" };
return Ok(ClientRepositoryBL.GetAll());
}

// GET api/values/5
[ConnectionFilter]
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}

// POST api/values
[ConnectionFilter]
[HttpPost]
public void Post([FromBody] string value)
{
}

// PUT api/values/5
[ConnectionFilter]
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}

// DELETE api/values/5
[ConnectionFilter]
[HttpDelete("{id}")]
public void Delete(int id)
[HttpGet]
public ActionResult<IEnumerable<Policy>> GetAllPolicies()
{
return Ok(PolicyRepositoryBL.GetAll());
}
}
}
@@ -1,15 +1,47 @@
using System;
using Serilog;
using System;
using System.Collections.Generic;
using System.Transactions;
using VuelingExam.Bussiness.Logic.Exceptions;
using VuelingExam.Bussiness.Logic.Interfaces.Crud;
using VuelingExam.Bussiness.Logic.Resources;
using VuelingExam.Common.Logic.Models;
using VuelingExam.RepositoryLogic.Exceptions;
using VuelingExam.RepositoryLogic.Interfaces;

namespace VuelingExam.Bussiness.Logic
{
public class ClientBussinessCrudBL : IBussinessCrud<Client>
{
private readonly IRepository<Client> Repository;
private readonly ILogger Logger;

public ClientBussinessCrudBL(IRepository<Client> repository, ILogger logger)
{
Repository = repository;
Logger = logger;
}

public Client Add(Client model)
{
throw new NotImplementedException();

Logger.Debug(StringResources.DebugMethod + System.Reflection.MethodBase.GetCurrentMethod().Name +
StringResources.DebugClass + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

Client result = null;

try
{
result = Repository.Add(model);
}
catch (VuelingDaoException e)
{
Logger.Error(e.Message);
Logger.Information(e.StackTrace);
throw new VuelingBussinessException(e.Message, e.InnerException);
}

return result;
}

public bool Delete(Guid id)
@@ -19,12 +51,42 @@ public bool Delete(Guid id)

public List<Client> GetAll()
{
throw new NotImplementedException();
Logger.Debug(StringResources.DebugMethod + System.Reflection.MethodBase.GetCurrentMethod().Name +
StringResources.DebugClass + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

List<Client> clientList;
try
{
clientList = Repository.GetAll();
}
catch (VuelingDaoException e)
{
Logger.Error(e.Message);
Logger.Information(e.StackTrace);
throw new VuelingBussinessException(e.Message, e.InnerException);
}

return clientList;
}

public Client GetEntityById(Guid id)
{
throw new NotImplementedException();
Logger.Debug(StringResources.DebugMethod + System.Reflection.MethodBase.GetCurrentMethod().Name +
StringResources.DebugClass + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

Client foundClient;
try
{
foundClient = Repository.GetEntityById(id);
}
catch (VuelingDaoException e)
{
Logger.Error(e.Message);
Logger.Information(e.StackTrace);
throw new VuelingBussinessException(e.Message, e.InnerException);
}

return foundClient;
}

public Client Update(Guid id, Client entity)
@@ -63,6 +63,7 @@ public void StoreListToDatabase()

ClientList.ForEach(client =>
{
Logger.Debug(client.ToString());
Repository.Add(client);
});
}
@@ -9,18 +9,19 @@
using VuelingExam.Bussiness.Logic.Resources;
using VuelingExam.Common.Logic;
using VuelingExam.Common.Logic.Models;
using VuelingExam.RepositoryLogic.Interfaces;

namespace VuelingExam.Bussiness.Logic
{
public class HttpPolicyFetcherBL : IHttpFetcher<Policy>
{
private readonly static string ExternalApiEndpoint = ConfigHelper.Config["externalApiEndpoint"];
private readonly static string ExternalApiPolicyPath = ConfigHelper.Config["externalApiPolicyPath"];
private readonly IBussinessCrud<Policy> Repository;
private readonly IRepository<Policy> Repository;
private List<Policy> PolicyList = null;
private readonly ILogger Logger;

public HttpPolicyFetcherBL(IBussinessCrud<Policy> repository, ILogger logger)
public HttpPolicyFetcherBL(IRepository<Policy> repository, ILogger logger)
{
Repository = repository;
Logger = logger;
@@ -1,15 +1,48 @@
using System;
using Serilog;
using System;
using System.Collections.Generic;
using System.Transactions;
using VuelingExam.Bussiness.Logic.Exceptions;
using VuelingExam.Bussiness.Logic.Interfaces.Crud;
using VuelingExam.Bussiness.Logic.Resources;
using VuelingExam.Common.Logic.Models;
using VuelingExam.RepositoryLogic.Exceptions;
using VuelingExam.RepositoryLogic.Interfaces;

namespace VuelingExam.Bussiness.Logic
{
public class PolicyBussinessCrudBL : IBussinessCrud<Policy>
{
private readonly IRepository<Policy> Repository;
private readonly ILogger Logger;

public PolicyBussinessCrudBL(IRepository<Policy> repository, ILogger logger)
{
Repository = repository;
Logger = logger;
}

public Policy Add(Policy model)
{
throw new NotImplementedException();
Logger.Debug(StringResources.DebugMethod + System.Reflection.MethodBase.GetCurrentMethod().Name +
StringResources.DebugClass + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

Policy result = null;

try
{
result = Repository.Add(model);


}
catch (VuelingDaoException e)
{
Logger.Error(e.Message);
Logger.Information(e.StackTrace);
throw new VuelingBussinessException(e.Message, e.InnerException);
}

return result;
}

public bool Delete(Guid id)
@@ -19,12 +52,42 @@ public bool Delete(Guid id)

public List<Policy> GetAll()
{
throw new NotImplementedException();
Logger.Debug(StringResources.DebugMethod + System.Reflection.MethodBase.GetCurrentMethod().Name +
StringResources.DebugClass + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

List<Policy> policyList;
try
{
policyList = Repository.GetAll();
}
catch (VuelingDaoException e)
{
Logger.Error(e.Message);
Logger.Information(e.StackTrace);
throw new VuelingBussinessException(e.Message, e.InnerException);
}

return policyList;
}

public Policy GetEntityById(Guid id)
{
throw new NotImplementedException();
Logger.Debug(StringResources.DebugMethod + System.Reflection.MethodBase.GetCurrentMethod().Name +
StringResources.DebugClass + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

Policy foundPolicy;
try
{
foundPolicy = Repository.GetEntityById(id);
}
catch (VuelingDaoException e)
{
Logger.Error(e.Message);
Logger.Information(e.StackTrace);
throw new VuelingBussinessException(e.Message, e.InnerException);
}

return foundPolicy;
}

public Policy Update(Guid id, Policy entity)
@@ -5,27 +5,28 @@ namespace VuelingExam.Common.Logic.Models
public class Policy
{
public Guid Id { get; set; }
public decimal InsuredAmmount { get; set; }
public decimal AmountInsured { get; set; }
public string Email { get; set; }
public DateTime InstallmentDate { get; set; }
public DateTime InceptionDate { get; set; }
public bool InstallmentPayment { get; set; }
public Guid ClientId { get; set; }
public virtual Client PolicyClient { get; set; }

public Policy(Guid id, decimal insuredAmount, string email, DateTime installmentDate, bool installmentPayment, Guid clientId)
public Policy(Guid id, decimal insuredAmount, string email, DateTime inceptionDate, bool installmentPayment, Guid clientId)
{
Id = id;
InsuredAmmount = insuredAmount;
AmountInsured = insuredAmount;
Email = email;
InstallmentDate = installmentDate;
InceptionDate = inceptionDate;
InstallmentPayment = installmentPayment;
ClientId = clientId;
}

public Policy(decimal insuredAmount, string email, DateTime installmentDate, bool installmentPayment, Guid clientId)
public Policy(decimal insuredAmount, string email, DateTime inceptionDate, bool installmentPayment, Guid clientId)
{
InsuredAmmount = insuredAmount;
AmountInsured = insuredAmount;
Email = email;
InstallmentDate = installmentDate;
InceptionDate = inceptionDate;
InstallmentPayment = installmentPayment;
ClientId = clientId;
}
@@ -4,5 +4,6 @@ namespace VuelingExam.RepositoryLogic.Interfaces
{
public interface IRepository<T> : IAdd<T>, IDelete, IGetAll<T>, IGetEntityById<T>, IUpdate<T>
{

}
}
Oops, something went wrong.

0 comments on commit ea0dc0b

Please sign in to comment.
You can’t perform that action at this time.