83 lines
2.4 KiB
C#
83 lines
2.4 KiB
C#
|
|
using Simple.OData.Client;
|
|
|
|
namespace JSONParser.Structure
|
|
{
|
|
public class JobTitle : Entity
|
|
{
|
|
public string Name { get; set; }
|
|
public Department Department { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return Name;
|
|
}
|
|
|
|
public override async Task<long> Create(ODataClient client)
|
|
{
|
|
var newJobTitle = new
|
|
{
|
|
Name = Name,
|
|
Department = new { Id = Department.DirectumId },
|
|
Status = "Active"
|
|
};
|
|
var created = await client
|
|
.For("IJobTitles")
|
|
.Set(newJobTitle)
|
|
.InsertEntryAsync();
|
|
this.DirectumId = (long)created["Id"];
|
|
return (long)created["Id"];
|
|
}
|
|
public async override Task<long> Update(ODataClient client, long id)
|
|
{
|
|
var newJobTitle = new
|
|
{
|
|
Name = Name,
|
|
Department = new { Id = Department.DirectumId },
|
|
Status = "Active"
|
|
};
|
|
var updated = await client
|
|
.For("IJobTitles")
|
|
.Key(id)
|
|
.Set(newJobTitle)
|
|
.UpdateEntryAsync();
|
|
this.DirectumId = (long)updated["Id"];
|
|
return (long)updated["Id"];
|
|
}
|
|
|
|
public bool IsEqual(IDictionary<string, dynamic> job)
|
|
{
|
|
bool result = false;
|
|
long? jobTitleId = null;
|
|
if (job["Department"] != null)
|
|
{
|
|
jobTitleId = job["Department"]["Id"];
|
|
}
|
|
if (Name == (string)job["Name"] &&
|
|
Department?.DirectumId == jobTitleId)
|
|
{
|
|
result = true;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public async Task<long> GetIdBySid(ODataClient client)
|
|
{
|
|
long result = 0;
|
|
if (!string.IsNullOrEmpty(Name) && Department != null)
|
|
{
|
|
var job = await client
|
|
.For("IJobTitles")
|
|
.Expand("Department")
|
|
.Filter($"Name eq '{Name}' and Department/ExternalId eq '{Department.Sid}'")
|
|
.FindEntryAsync();
|
|
if (job != null)
|
|
{
|
|
result = (long)job["Id"];
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|