public async Task <User> FindByNameAsync(string userName, string sessionId) { if (String.IsNullOrEmpty(userName)) { return(null); } await DataSyncService.SynchronizeDataWithSmg(sessionId); return(await FindByNameAsync(userName)); }
public async Task <User> FindByNameAsync(string userName, EmployeesAccessRules?accessRule = null, bool skipSync = false) { accessRule = accessRule ?? (EmployeesAccessRules?)ApplicationSettingsService.Instance.Settings.EmployeesAccessRule; if (!skipSync) { await DataSyncService.SynchronizeDataWithSmg(); } IQueryable <User> users; if ((int)accessRule.Value != ApplicationSettingsService.Instance.Settings.EmployeesAccessRule) { if (accessRule.Value == EmployeesAccessRules.AllEmployees) { users = unitOfWork.UsersRepository.Query(); } else { var departmentId = SessionHelper.GetUserDepartmentIdFromOwinContext(); if (departmentId != Guid.Empty) { users = unitOfWork.UsersRepository.QueryInDepartment(departmentId); } else { throw new ApplicationException("User's department not found"); } } } else { users = Users; } var lowerUserName = userName.ToLower(); return(await users.FirstOrDefaultAsync(x => x.UserName.ToLower() == lowerUserName)); }