This commit is contained in:
Paul Schneider 2017-06-08 00:26:29 +02:00
commit a120dae977
144 changed files with 10574 additions and 1527 deletions

View file

@ -0,0 +1,62 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Data.Entity;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Yavsc.Billing;
using Yavsc.Models;
namespace Yavsc.Services
{
public class BillingService : IBillingService
{
public ApplicationDbContext DbContext { get; private set; }
private ILogger logger;
public BillingService(ILoggerFactory loggerFactory, ApplicationDbContext dbContext)
{
logger = loggerFactory.CreateLogger<BillingService>();
DbContext = dbContext;
}
public async Task<IQueryable<ISpecializationSettings>> GetPerformersSettings(string activityCode)
{
logger.LogDebug("searching for "+activityCode);
var activity = await DbContext.Activities.SingleAsync(a=>a.Code == activityCode);
logger.LogDebug(JsonConvert.SerializeObject(activity));
if (activity.SettingsClassName==null) return null;
var dbSetPropInfo = Startup.UserSettings.SingleOrDefault(s => s.PropertyType.GenericTypeArguments[0].FullName == activity.SettingsClassName);
if (dbSetPropInfo == null) return null;
// var settingType = dbSetPropInfo.PropertyType;
// var dbSetType = typeof(DbSet<>).MakeGenericType(new Type[] { settingType } );
// avec une info method Remove et Update, ça le ferait ...
return (IQueryable<ISpecializationSettings>) dbSetPropInfo.GetValue(DbContext);
}
public async Task<IBillable> GetBillAsync(string billingCode, long queryId)
{
var dbFunc = Startup.Billing[billingCode];
IBillable query = null;
await Task.Run(()=> dbFunc(DbContext, queryId));
return query;
}
public async Task<ISpecializationSettings> GetPerformerSettingsAsync(string activityCode, string userId)
{
return await (await GetPerformersSettings(activityCode)).SingleOrDefaultAsync(s=> s.UserId == userId);
}
public Task<IQueryable<ISpecializationSettings>> GetPerformersSettingsAsync(string activityCode)
{
throw new NotImplementedException();
}
}
}

View file

@ -0,0 +1,26 @@
namespace Yavsc.Services
{
using System.Linq;
using System.Threading.Tasks;
using Billing;
public interface IBillingService
{
/// <summary>
/// Renvoye la facture associée à une clé de facturation:
/// le couple suivant :
///
/// * un code de facturation
/// (identifiant associé à un type de facturation d'un flux de travail)
/// * un entier long identifiant la demande du client
/// (à une demande, on associe au maximum une seule facture)
/// </summary>
/// <param name="billingCode">Identifiant du type de facturation</param>
/// <param name="queryId">Identifiant de la demande du client</param>
/// <returns>La facture</returns>
Task<IBillable> GetBillAsync(string billingCode, long queryId);
Task<IQueryable<ISpecializationSettings>> GetPerformersSettingsAsync(string activityCode);
Task<ISpecializationSettings> GetPerformerSettingsAsync(string activityCode, string userId);
}
}