/// <summary> /// Sets the customer access for a user based on the customer IDs passed in /// </summary> /// <param name="userId">id of the user</param> /// <param name="customerIds">List of customerIDs to add tot he users access</param> public void SetCustomersIds(int userId, List <int> customerIds) { foreach (var customerId in customerIds) { var uca = new UserCustomerAccess { CustomerId = customerId, UserId = userId }; _rbacEntities.UserCustomerAccesses.Add(uca); } _rbacEntities.SaveChanges(); }
/// <summary> /// Adds the customer to the access table for a user /// </summary> /// <param name="userId">ID of hte user to add access for</param> /// <param name="customerId">ID of the customer to add to the user</param> public void AddCustomerAccess(int userId, int customerId) { var existingUca = _rbacEntities.UserCustomerAccesses.FirstOrDefault(x => x.UserId == userId && x.CustomerId == customerId); if (existingUca == null) { var uca = new UserCustomerAccess { CustomerId = customerId, UserId = userId }; _rbacEntities.UserCustomerAccesses.Add(uca); _rbacEntities.SaveChanges(); } }