//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.1
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

// 
// This code was auto-generated by AFNOR StoredProcedureSystem, version 1.0
// 

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Activation;
using AutoMapper;
using EspaceClient.BackOffice.Infrastructure.Context;
using EspaceClient.BackOffice.Services.Contracts;
using EspaceClient.BackOffice.Services.Implementations.Helpers;
using EspaceClient.FrontOffice.Business.Depots;
using EspaceClient.FrontOffice.Domaine;
using Castle.Core.Logging;
 
namespace EspaceClient.BackOffice.Services.Implementations
{
    /// <summary>
    /// Service des utilisateurs.
    /// </summary>
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public partial class ServiceTraductionEntite : IServiceTraductionEntite 
    {
        private readonly IDepotTraductionEntite _traductionentites;
 
		private readonly IDepotLangue _langues;
 
        private ILogger _logger = NullLogger.Instance;
		
        /// <summary>
        /// Initialise une nouvelle instance du service des traductionentites.
        /// </summary>
        /// <param name="traductionentites">Dépôt des traductionentites.</param>
        public ServiceTraductionEntite(IDepotTraductionEntite traductionentites,IDepotLangue langues  )
        {
            _traductionentites = traductionentites;
            _langues = langues ;
        }
 
        /// <summary>
        /// Instance du logger.
        /// </summary>
        public ILogger Logger
        {
            get { return _logger; }
            set { _logger = value; }
        }
        
        
        public IEnumerable<TraductionEntiteDto> GetAll(WebContext context)
        {
        	try
			{
				var cache = Memoizer.Memoize<WebContext, IEnumerable<TraductionEntiteDto>>(CacheTraductionEntites);

				return cache(context);
			}
            catch (Exception e)
            {
                LoggerHelper.Fatal(Logger, e, "SERVICE_CRITICAL_FAILED");
            }

            return null;
        }

        private IEnumerable<TraductionEntiteDto> CacheTraductionEntites(WebContext context)
        {
            try
            {
                var traductionentites = _traductionentites.GetAll(context.LangueID);

                List<TraductionEntiteDto> traductionentitesDto = new List<TraductionEntiteDto>();

                foreach (var ob in traductionentites.ToList())
                {
                    var dto = Mapper.Map<TraductionEntite, TraductionEntiteDto>(ob);

                    traductionentitesDto.Add(dto);
                }

                return traductionentitesDto;
            }
            catch (Exception e)
            {
                LoggerHelper.Fatal(Logger, e, "SERVICE_CRITICAL_FAILED");
            }

            return null;
        }
    
    }
}
