private async Task <UserSearchViewModel> SetupUserSearchViewModel(string userName = null, string departmentName = null) { var model = new UserSearchViewModel(); var branches = await _branchesService.GetAllBranches(); if (!string.IsNullOrWhiteSpace(userName)) { model.UserName = userName; } model.Departments = branches.Select(x => { var item = new SelectListItem() { Text = x.Name, Value = x.Name }; if (!string.IsNullOrWhiteSpace(departmentName) && item.Value == departmentName) { item.Selected = true; model.DepartmentAddress = x.Address?.Trim('"') ?? null; model.DepartmentName = departmentName; } return(item); }).ToList(); model.Departments.Insert(0, new SelectListItem() { Text = "Select a branch", Value = "" }); return(model); }
private static IQueryable<AppraisalCompanyBranchViewModel> BrancheForCompanyExistsQueryable(IBranchesService source, int companyId, string branchName) { if (source == null) throw new ArgumentNullException("source"); return source.GetAllBranches().Where(e => e.Name.ToUpper() == branchName.ToUpper() && e.CompanyId == companyId); }