114 lines
3.9 KiB
C#
114 lines
3.9 KiB
C#
using Microsoft.Azure.CosmosDB.Table;
|
|
using Microsoft.Azure.Storage;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using taloyhtio.idp.parser.common.model;
|
|
using unesMdb.model;
|
|
|
|
namespace unesMdb
|
|
{
|
|
class Program
|
|
{
|
|
private static CloudTableClient tableClient;
|
|
private static List<UserData> users;
|
|
private static List<FlatData> flats;
|
|
private static Dictionary<string, Guid> flatsAzure;
|
|
private static CondoMapping condo;
|
|
|
|
private const string CONDONAME = "itapuisto7";
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
DbUtils.ConnectionString = $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={args[0]}\\Kirjos.mdb";
|
|
users = DbUtils.CollectUsers();
|
|
flats = DbUtils.CollectFlats(users);
|
|
DbUtils.CollectLinks(users);
|
|
DbUtils.CollectFees(users);
|
|
|
|
InitClient();
|
|
condo = GetCondo(CONDONAME)[0];
|
|
if (condo == null)
|
|
{
|
|
return;
|
|
}
|
|
flatsAzure = GetFlats(condo.TaloyhtioPMCId, CONDONAME).ToDictionary(x => x.FlatTitle, x => x.Id);
|
|
SaveFees();
|
|
}
|
|
|
|
private static void InitClient()
|
|
{
|
|
var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings[Constants.KEY_AZURE_STORAGE].ConnectionString);
|
|
tableClient = storageAccount.CreateCloudTableClient(
|
|
new TableConnectionPolicy()
|
|
{
|
|
UseDirectMode = false
|
|
});
|
|
}
|
|
|
|
private static List<CondoMapping> GetCondo(string condoName)
|
|
{
|
|
var table = tableClient.GetTableReference("mdbCondoMappings");
|
|
table.CreateIfNotExists();
|
|
|
|
var allCondos = table.CreateQuery<CondoMapping>().ToList();
|
|
|
|
if (condoName != null)
|
|
{
|
|
return allCondos.Where(x => condoName.Contains(x.PMSCondoName)).ToList();
|
|
}
|
|
return allCondos;
|
|
}
|
|
|
|
private static List<Flat> GetFlats(Guid taloyhtioPMCId, string pmsCondoName)
|
|
{
|
|
if (Guid.Empty.Equals(taloyhtioPMCId) || string.IsNullOrEmpty(pmsCondoName))
|
|
{
|
|
return null;
|
|
}
|
|
var table = tableClient.GetTableReference("mdbFlats");
|
|
table.CreateIfNotExists();
|
|
|
|
var query = table.CreateQuery<Flat>()
|
|
.Where(d => d.PMCTaloyhtioId == taloyhtioPMCId && d.CondoPMS == pmsCondoName)
|
|
.ToArray()
|
|
.OrderBy(o => o.FlatTitle);
|
|
|
|
return query.ToList();
|
|
}
|
|
|
|
private static void SaveFees()
|
|
{
|
|
var table = tableClient.GetTableReference("mdbMaintenanceFees");
|
|
table.CreateIfNotExists();
|
|
|
|
flats.Where(flat => flatsAzure.ContainsKey(flat.Title)).ToList().ForEach(flat =>
|
|
{
|
|
flat.Users.ForEach(user =>
|
|
{
|
|
user.Fees.ForEach(feeRec =>
|
|
{
|
|
var fee = new MaintenanceFee(Guid.NewGuid())
|
|
{
|
|
Payer = user.Name,
|
|
FlatTitle = flat.Title,
|
|
FlatId = flatsAzure[flat.Title],
|
|
PaymentType = feeRec.Name,
|
|
PMSCondoName = condo.PMSCondoName,
|
|
PMCTaloyhtioId = condo.TaloyhtioPMCId,
|
|
PeriodOfTime = "201911",
|
|
Fee = Convert.ToDouble(feeRec.Amount),
|
|
|
|
PartitionKey = user.Name,
|
|
};
|
|
|
|
var result = table.Execute(TableOperation.InsertOrReplace(fee));
|
|
Console.WriteLine(result.HttpStatusCode);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|