using Simple.OData.Client; using System.Dynamic; namespace JSONParser.Structure { public class Login : Entity { public string LoginName { get; set; } public string TypeAuthentication { get; set; } public bool Status { get; set; } public override string ToString() { return LoginName; } public override async Task Create(ODataClient client) { var newPerson = new { LoginName = $"{LoginName}", TypeAuthentication = TypeAuthentication, Status = "Active" }; var created = await client .For("ILogins") .Set(newPerson) .InsertEntryAsync(); this.DirectumId = (long)created["Id"]; return (long)created["Id"]; } public async override Task Update(ODataClient client, long id) { var newPerson = new { LoginName = LoginName, TypeAuthentication = TypeAuthentication, Status = "Active" }; var created = await client .For("ILogins") .Key(id) .Set(newPerson) .UpdateEntryAsync(); this.DirectumId = (long)created["Id"]; return (long)created["Id"]; } public bool IsEqual(IDictionary log) { bool result = false; if (LoginName == log["LoginName"] && TypeAuthentication == log["TypeAuthentication"]) { result = true; } return result; } public async Task GetIdBySid(ODataClient client) { long result = 0; if (!string.IsNullOrEmpty(LoginName)) { var log = await client .For("ILogins") .Filter($"tolower(LoginName) eq '{LoginName.ToLower()}'") .FindEntryAsync(); if (log != null) { result = (long)log["Id"]; } } return result; } public async void CloseLogin(ODataClient client, long id) { var closedLogin = new { Status = "Closed" }; await client .For("ILogins") .Key(id) .Set(closedLogin) .UpdateEntryAsync(); } public async void OpenLogin(ODataClient client, long id) { var openedLogin = new { Status = "Active" }; await client .For("ILogins") .Key(id) .Set(openedLogin) .UpdateEntryAsync(); } } }