public async Task <RegudoEmployee> SaveEmployee(RegudoEmployee Employee) { if (TokenData == null) { await this.Login(this.Config.UserName, this.Config.Password); } var employeeId = await this.EmployeeExist(Employee); if (string.IsNullOrEmpty(employeeId)) { return(await this.CreateEmployee(Employee)); } Employee.Id = employeeId; return(await this.UpdateEmployee(Employee)); }
public async Task <string> EmployeeExist(RegudoEmployee Employee) { if (TokenData == null) { await this.Login(this.Config.UserName, this.Config.Password); } var endpoint = $"{this.Config.Server}{this.TokenData.ActiveUser.OrganizationId}/{this.TokenData.ActiveUser.Id}/checkIfEmployeeExist"; LoggerSingleton.Instance.Info(endpoint); var result = await this.HttpServiceHelper.POST_ASYNC(endpoint, Employee, null, new Dictionary <string, string> { ["Content-Type"] = "application/json", ["Authorization"] = $"JWT {this.TokenData.Token}" }); // try to refresh token if (!result.Success) { /// var statusCode = this.ParseErrorStatusCode(result.Content); var statusCode = (int)result.StatusCode; if (statusCode == 403 || statusCode == 401) { await this.RefreshToken(); result = await this.HttpServiceHelper.POST_ASYNC(endpoint, Employee, null, new Dictionary <string, string> { ["Content-Type"] = "application/json", ["Authorization"] = $"JWT {this.TokenData.Token}" }); } } if (!result.Success) { throw new Exception(result.Content); } return(this.ParseEmployeeId(result.Content)); }