Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
selimaytac committed Aug 1, 2022
0 parents commit d596f17
Show file tree
Hide file tree
Showing 21 changed files with 1,254 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/

# Visual Studio Code
.vscode

# Rider
.idea

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn

# Visual Studio 2015
.vs/

appsettings.development.json
35 changes: 35 additions & 0 deletions DTPersonalInfoTracker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions DTPersonalInfoTracker.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTPersonalInfoTracker", "DTPersonalInfoTracker.csproj", "{6C5A039E-3A47-4CC7-9896-71E58B209014}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6C5A039E-3A47-4CC7-9896-71E58B209014}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C5A039E-3A47-4CC7-9896-71E58B209014}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C5A039E-3A47-4CC7-9896-71E58B209014}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C5A039E-3A47-4CC7-9896-71E58B209014}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions DbContexts/PITDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using DTPersonalInfoTracker.Helpers;
using DTPersonalInfoTracker.Models;
using Microsoft.EntityFrameworkCore;

namespace DTPersonalInfoTracker.DbContexts;

public class PITDbContext : DbContext
{
public DbSet<PersonelModel> Personels { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(SettingsHelper.GetConnectionString());
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<PersonelModel>().HasKey(p => p.RecordId);
}
}
64 changes: 64 additions & 0 deletions Helpers/DbHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using DTPersonalInfoTracker.DbContexts;
using DTPersonalInfoTracker.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;

namespace DTPersonalInfoTracker.Helpers;

public class DbHelper
{
public static IList<PersonelModel> ConvertData(IList<RootObject> rawList)
{
var result = new List<PersonelModel>();

foreach (var data in rawList)
{
var pModel = new PersonelModel
{
RecordId = data.RecordId!,
Ad = data.FieldList.FirstOrDefault(x => x?.LogicalName == "hs_name")?.Value,
Soyad = data.FieldList.FirstOrDefault(x => x?.LogicalName == "hs_surname")?.Value,
Grup = data.FieldList.FirstOrDefault(x => x?.LogicalName == "hs_parentunitid")?.Value,
PozisyonSeviyesi = data.FieldList.FirstOrDefault(x => x?.LogicalName == "hs_positionlevelid")?.Value,
Bolum = data.FieldList.FirstOrDefault(x => x?.LogicalName == "hs_pparentunitid")?.Value,
Pozisyon = data.FieldList.FirstOrDefault(x => x?.LogicalName == "hs_positionid")?.Value,
CepNumarasi = data.FieldList.FirstOrDefault(x => x?.LogicalName == "hs_companyphone")?.Value,
SirketEmail = data.FieldList.FirstOrDefault(x => x?.LogicalName == "emailaddress")?.Value,
SicilNo = data.FieldList.FirstOrDefault(x => x?.LogicalName == "hs_personnelno")?.Value,
Birim = data.FieldList.FirstOrDefault(x => x?.LogicalName == "hs_ppparentunitid")?.Value,
Yonetici = data.FieldList.FirstOrDefault(x => x?.LogicalName == "hs_reportmanagerid")?.Value
};

result.Add(pModel);
}

return result;
}

public static void AddFieldListsToDb(IList<PersonelModel> personelModels)
{
using var context = new PITDbContext();
InitializeDb(context);

TruncateTable(context);
context.Personels.AddRange(personelModels);
context.SaveChanges();
LoggerHelper.Information("Personel list successfully added to database.");
}

public static void InitializeDb(PITDbContext context)
{
if (context.Database.GetPendingMigrations().Any())
{
context.Database.Migrate();
LoggerHelper.Information("DTPIT db created and migrated.");
}
}

public static void TruncateTable(PITDbContext context)
{
context.Personels.RemoveRange(context.Personels);
LoggerHelper.Information("Personel table truncated.");
}
}
28 changes: 28 additions & 0 deletions Helpers/FetchDataHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace DTPersonalInfoTracker.Helpers;

public class FetchDataHelper
{
public static async Task<string> FetchXmlData(string url, string action, string fetchXml, string domainName)
{
var httpClient = new HttpClient();
try
{
var requestUri =
url
+ action
+ "?fetchXml=" + fetchXml
+ "&domainName=" + domainName;

var result = await httpClient.PostAsync(requestUri, null);

var response = await result.Content.ReadAsStringAsync();

return response;
}
catch (Exception e)
{
LoggerHelper.Error(e.Message);
return string.Empty;
}
}
}
36 changes: 36 additions & 0 deletions Helpers/LoggerHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Serilog;
using Serilog.Core;

namespace DTPersonalInfoTracker.Helpers;

public class LoggerHelper
{
static LoggerHelper()
{
DTLogger = InitilalizeLogger(SettingsHelper.GetLogPath());
}

public static Logger DTLogger { get; set; }

public static Logger InitilalizeLogger(string logPath)
{
return new LoggerConfiguration().WriteTo
.File(logPath + $"DTPIT/{DateTime.Today.ToShortDateString()}.txt")
.CreateLogger();
}

public static void Warning(string message)
{
DTLogger.Warning(message);
}

public static void Error(string message)
{
DTLogger.Error(message);
}

public static void Information(string message)
{
DTLogger.Information(message);
}
}
15 changes: 15 additions & 0 deletions Helpers/SerializerHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Newtonsoft.Json;

namespace DTPersonalInfoTracker.Helpers;

public class SerializerHelper
{
public static string Serialize<T>(T obj)
{
return JsonConvert.SerializeObject(obj);
}
public static T? Deserialize<T>(string json)
{
return JsonConvert.DeserializeObject<T>(json);
}
}
32 changes: 32 additions & 0 deletions Helpers/SettingsHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Reflection;
using DTPersonalInfoTracker.Models;
using Microsoft.Extensions.Configuration;

namespace DTPersonalInfoTracker.Helpers;

public class SettingsHelper
{
private static IConfigurationRoot? _configuration;

public static IConfigurationRoot Configuration =>
_configuration ?? (_configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build());

public static AppSettings GetSettings()
{
return Configuration.GetSection(AppSettings.Name).Get<AppSettings>();
}

public static string GetLogPath()
{
return Configuration.GetSection("LogPath").Value;
}

public static string GetConnectionString()
{
return Configuration.GetSection("ConnectionStrings").GetSection("DefaultConnectionString").Value;
}
}
Loading

0 comments on commit d596f17

Please sign in to comment.