public void AddRole(Role role) { if (roles.Contains(role)) return; roles.Add(role); }
public bool AddRole(Role role) { logger.logInfo("Try to add a new role."); try { Role auxRole = this.GetRoleByName(role.Name); if (auxRole != null) throw new DuplicateException("You can not add two roles with the same name (" + role.Name + ")."); var validationResults = Validation.Validate<Role>(role); if (!validationResults.IsValid) { throw new ValidationException("Invalid role name {" + role.Name + "}"); } DataMapperFactoryMethod.GetCurrentFactory().RoleFactory.AddRole(role); logger.logInfo("The role with name "+role.Name+" was succesfully added."); return true; } catch(ValidationException validationException) { logger.logError(validationException); throw validationException; } catch (DuplicateException duplicateException) { logger.logError(duplicateException); throw duplicateException; } }
public void AddRole(Role role) { using(var context = new AuctionModelContainer()) { context.Roles.Add(role); context.SaveChanges(); } }
public void DropRole(Role role) { using (var context = new AuctionModelContainer()) { context.Roles.Attach(role); context.Roles.Remove(role); context.SaveChanges(); } }
public void UpdateRole(Role role) { using (var context = new AuctionModelContainer()) { context.Roles.Attach(role); var entry = context.Entry(role); entry.Property(r => r.Name).IsModified = true; context.SaveChanges(); } }
public void AddRoleToUser(User user,Role role) { using(var context = new AuctionModelContainer()) { context.setLazyFalse(); context.Users.Attach(user); context.Roles.Attach(role); context.Entry(user).Collection(u => u.Roles).Load(); user.Roles.Add(role); context.SaveChanges(); } }
public bool AddRoleToUser(String email,Role role) { try { User user = GetUserByEmail(email); if (user == null) throw new EntityDoesNotExistException("The user with email " + email + " does not exist."); logger.logInfo("Try to add role " +role.Name+" to user with email " + email); DataMapperFactoryMethod.GetCurrentFactory().UserFactory.AddRoleToUser(user,role); logger.logInfo("Role " + role.Name + " was succesfully assigned to user with email " + email); return true; } catch(EntityDoesNotExistException exc) { logger.logError(exc); throw exc; } }
public void TestAddLicitation() { User user1 = new User(); user1.FirstName = "AAA"; user1.LastName = "AAA"; user1.Email = "[email protected]"; User user2 = new User(); user2.FirstName = "BBB"; user2.LastName = "BBB"; user2.Email = "[email protected]"; Role role1 = new Role(); role1.Name = Constants.OWNER; Role role2 = new Role(); role2.Name = Constants.ACTIONEER; Category category = new Category(); category.Name = "category"; category.Description = "AAAAA"; categoryService.AddCategory(category); Product product = new Product(); product.Name = "AAA"; product.Description = "AAAAAAAA"; product.Categories.Add(category); userService.AddUser(user1); userService.AddUser(user2); productService.AddProduct(product); currencyService.AddCurrency("RON"); Currency currency = currencyService.GetCurrencyByName("RON"); roleService.AddRole(role1); roleService.AddRole(role2); userService.AddRoleToUser("[email protected]", role1); userService.AddRoleToUser("[email protected]", role2); auctionService.AddNewAuction(user1, product, currency, 100, DateTime.Now, DateTime.Now); productAuctionService.AddProductAuction(user2, product, 200, currency); userService.AddNoteToUser(user2, user1, 7); }
public void TestGetRolesFromAnUserWithRoles() { User user = new User(); user.FirstName = "AAA"; user.LastName = "BBB"; user.Email = "*****@*****.**"; userService.AddUser(user); Role role = new Role(); role.Name = "testrole"; roleService.AddRole(role); userService.AddRoleToUser("*****@*****.**", role); ICollection<Role> roles = roleService.GetRolesFromAnUser(userService.GetUserByEmail("*****@*****.**")); Assert.AreEqual(1, roles.Count); }
public void RemoveRoleFromUser(User user,Role role) { using (var context = new AuctionModelContainer()) { context.setLazyFalse(); context.Users.Attach(user); context.Roles.Attach(role); context.Entry(user).Collection(u => u.Roles).Load(); context.Entry(role).Collection(r => r.Users).Load(); if (!user.Roles.Contains(role)) throw new EntityDoesNotExistException("User with email "+user.Email+" hasn't the role with name "+role.Name+" so it can't be remove."); user.Roles.Remove(role); context.Entry(user).State = EntityState.Modified; context.SaveChanges(); } }
private void GetRole() { role = roleService.GetRoleByName("CCCC"); }