public ClientUserViewModel(ClientUser clientUser, string companyState = null, string branchState = null) { User = new UserViewModel(); User.Email = clientUser.User.Email; User.FirstName = clientUser.User.FirstName; User.LastName = clientUser.User.LastName; RoleType = clientUser.User.PrimaryRole.RoleType; Status = clientUser.Status; PhoneNumber = clientUser.PhoneNumber; IsViewAllCompanyOrders = clientUser.IsViewAllCompanyOrders; IsUserLocked = clientUser.IsUserLocked; if (clientUser.Company != null) { Company = new ClientCompanyViewModel(clientUser.Company, companyState); CompanyName = clientUser.Company.CompanyName; CompanyID = clientUser.Company.Id; if (clientUser.Branch != null) { Branch = new BrancheViewModel(clientUser.Branch, clientUser.Company.Status, branchState, false, null); BranchID = clientUser.Branch.Id; } } }
public void CreateClientUser(ClientUserViewModel model) { if (model == null) throw new ArgumentNullException("model"); if (_userManagement.IsExistsUser(model.User.Email)) throw new Exception(string.Format("User with email {0} already exists", model.User.Email)); var user = _userManagement.CreateUser(model.User, model.RoleType); var company = _clientCompanyManager.GetClientCompanyById(model.CompanyID); var branch = _clientBranchManager.GetClientBranchById(model.BranchID); var clientUser = new ClientUser(); clientUser.User = user; clientUser.Branch = branch; clientUser.Company = company; clientUser.Status = model.Status; clientUser.PhoneNumber = model.PhoneNumber; clientUser.IsViewAllCompanyOrders = model.IsViewAllCompanyOrders; _clientUserManager.CreateUser(clientUser); }
public void CreateEmptyOrder_should_prepopulate_default_values() { var datetime = DateTime.Now.ToShortDateString(); var defaultAppraiserDeliveryType = (int)AppraiserOrderDeliveryType.SMS + (int)AppraiserOrderDeliveryType.Email; var defaultClientUser = new ClientUser() { Id = 1 }; var defaultUser = new User() { Roles = new Role[] { new Role() { Id = (int)RoleType.SuperUser } } }; defaultClientUser.Company = new ClientCompany() { Id = 2 }; defaultClientUser.Branch = new ClientCompanyBranche() { Id = 3 }; _clientUserRepository.GetByUserId(Arg.Any<int>()).Returns(defaultClientUser); var act = _target.CreateNewOrder(default(int), defaultClientUser.Company.Id, defaultClientUser.Branch.Id); act.OrderStatus.Should().Be(OrderStatus.CreationProcess); act.OrderPublicId.Should().NotBeNullOrEmpty(); act.CreationDate.ToShortDateString().Should().BeEquivalentTo(datetime); act.AppraiserOrderDeliveryType.Should().Be(defaultAppraiserDeliveryType); act.CreatedByClientUserId.Should().Be(defaultClientUser.Id); act.ClientCompanyBrancheId.Should().Be(defaultClientUser.Branch.Id); act.ClientCompanyId.Should().Be(defaultClientUser.Company.Id); }
public Expression<Func<Order, bool>> HasClientUserAccessToOrder(ClientUser client) { var result = PredicateBuilder.True<Order>(); if (client.Company.Profile.IsLender && client.Company.Profile.IsWholesale) { if (client.IsViewAllCompanyOrders) { result = result.AndAlso(o => o.CreatedByClientUser.Company.Id == client.Company.Id || (o.ClientCompany != null && o.ClientCompany.Id == client.Company.Id)); } else { result = result.AndAlso(o => o.CreatedByClientUser.Branch.Id == client.Branch.Id || (o.ClientCompany != null && o.ClientCompany.Id == client.Company.Id && o.ClientCompanyBranche != null && o.ClientCompanyBranche.Id == client.Branch.Id)); } } else { result = client.IsViewAllCompanyOrders ? result.AndAlso(o => o.CreatedByClientUser.Company.Id == client.Company.Id) : result.AndAlso(o => o.CreatedByClientUser.Branch.Id == client.Branch.Id); } return result; }
private ClientUser GetClientUser() { var clientUser = new ClientUser(); clientUser.User = new User(); clientUser.User.Email = "*****@*****.**"; clientUser.User.FirstName = "FTest"; clientUser.User.LastName = "LTest"; clientUser.User.Roles = new Role[] { new Role() { DisplayName = "Test Role", Id = (int)RoleType.SuperUser } }; clientUser.Status = ClientUserStatus.Active; return clientUser; }
private static Expression<Func<ActiveOrderItem, bool>> GetActiveFilter(ClientDashboardFilter filter, ClientUser client) { var result = HasClientUserAccessToActiveOrder(client); if (!string.IsNullOrWhiteSpace(filter.Fragment)) { var fragmentTrimmed = filter.Fragment.Trim(); result = result.AndAlso(o => o.Order.GeneralInfo.BorrowerFirstName.Contains(fragmentTrimmed) || o.Order.GeneralInfo.BorrowerLastName.Contains(fragmentTrimmed) || o.Order.GeneralInfo.LoanNumber.Contains(fragmentTrimmed) || o.Order.OrderPublicId.Contains(fragmentTrimmed)); } if (filter.DateFrom.HasValue) { result = result.AndAlso(o => EntityFunctions.TruncateTime(o.Order.CreationDate) >= EntityFunctions.TruncateTime(filter.DateFrom)); } if (filter.DateTo.HasValue) { result = result.AndAlso(o => EntityFunctions.TruncateTime(o.Order.CreationDate) <= EntityFunctions.TruncateTime(filter.DateTo)); } result = result.AndAlso(o => !o.Order.IsTestOrder); return result; }
private ClientUser GetClientUser() { if (_clientUser == null) _clientUser = _clientUserManager.GetByUserId(_currentUser.Id); if (_clientUser == null) throw new ApplicationException(String.Format("User [{0}] is not dvs user", _currentUser.Email)); return _clientUser; }
public void HasClientUserAccessToOrder_should_return_correct_permissions_for_Lender_and_Wholesale_client_company_when_user_can_see_all_company_orders() { // arrange var client = new ClientUser() { Company = new ClientCompany() { Id = 1, Profile = new ClientCompanyProfile() { IsLender = true, IsWholesale = true } }, IsViewAllCompanyOrders = true, Branch = new ClientCompanyBranche() { Id = 1 }, User = new User() { Roles = new List<Role>(new Role[] { new Role() { Id = (int)RoleType.LoanOfficer } }) } }; var orderCreatedBySameCompanySameBranch_valid = new Order() { GeneralInfo = new OrderGeneralInfo(), CreatedByClientUser = new ClientUser() { Company = new ClientCompany() { Profile = new ClientCompanyProfile(), Id = 1 }, Branch = new ClientCompanyBranche() { Id = 1 } } }; var orderCreatedBySameCompanyAnotherBranch_valid = new Order() { GeneralInfo = new OrderGeneralInfo(), CreatedByClientUser = new ClientUser() { Company = new ClientCompany() { Profile = new ClientCompanyProfile(), Id = 1 }, Branch = new ClientCompanyBranche() { Id = 2 } } }; var orderCreatedByAnotherCompany_invalid = new Order() { GeneralInfo = new OrderGeneralInfo(), CreatedByClientUser = new ClientUser() { Company = new ClientCompany() { Profile = new ClientCompanyProfile(), Id = 2 } } }; var orderCreatedForSameCompanySameBranch_valid = new Order() { GeneralInfo = new OrderGeneralInfo(), CreatedByClientUser = new ClientUser() { Company = new ClientCompany() { Profile = new ClientCompanyProfile(), }, }, ClientCompany = new ClientCompany() { Id = 1 }, ClientCompanyBranche = new ClientCompanyBranche() { Id = 1 } }; var orderCreatedForSameCompanyAnotherBranch_valid = new Order() { GeneralInfo = new OrderGeneralInfo(), CreatedByClientUser = new ClientUser() { Company = new ClientCompany() { Profile = new ClientCompanyProfile(), }, }, ClientCompany = new ClientCompany() { Id = 1 }, ClientCompanyBranche = new ClientCompanyBranche() { Id = 2 } }; var orderCreatedForAnotherCompany_invalid = new Order() { GeneralInfo = new OrderGeneralInfo(), CreatedByClientUser = new ClientUser() { Company = new ClientCompany() { Profile = new ClientCompanyProfile(), }, }, ClientCompany = new ClientCompany() { Id = 2 } }; // act var actual = _target.HasClientUserAccessToOrder(client).Compile(); // assert actual(orderCreatedByAnotherCompany_invalid).Should().BeFalse(); actual(orderCreatedBySameCompanySameBranch_valid).Should().BeTrue(); actual(orderCreatedBySameCompanyAnotherBranch_valid).Should().BeTrue(); actual(orderCreatedForAnotherCompany_invalid).Should().BeFalse(); actual(orderCreatedForSameCompanySameBranch_valid).Should().BeTrue(); actual(orderCreatedForSameCompanyAnotherBranch_valid).Should().BeTrue(); }
public void Update(ClientUser user) { if (user == null) throw new ArgumentNullException("user"); _clientUserRepository.Update(user); }
public void CreateUser(ClientUser user) { if (user == null) throw new ArgumentNullException("user"); _clientUserRepository.Add(user); }
private ClientUser GetClientUser() { var clientUser = new ClientUser(); clientUser.User = new User(); clientUser.User.Email = "*****@*****.**"; clientUser.User.FirstName = "FTest"; clientUser.User.LastName = "LTest"; clientUser.User.Roles = new List<Role> { new Role() { DisplayName = "Test Role", Id = (int)RoleType.SuperUser } }; clientUser.Company = new ClientCompany(); clientUser.Company.Profile = new ClientCompanyProfile(); clientUser.Company.Profile.Address = new Address(); clientUser.Company.Status = ClientCompanyStatus.Active; clientUser.Branch = new ClientCompanyBranche(); clientUser.Branch.Address = new Address(); clientUser.Branch.Status = ClientCompanyBrancheStatus.Active; clientUser.Status = ClientUserStatus.Active; return clientUser; }