using Simple.OData.Client; using System.Text.Json; 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 string Serialize() { return JsonSerializer.Serialize(this); } public override async Task 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 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 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 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; } } }