/// <summary>
 /// Does this instance.
 /// </summary>
 public override void PerformAction()
 {
     EmailInRole addRole = new EmailInRole{
         Email = this.emailInRole.Email,
         RoleId = this.emailInRole.RoleId
     };
     this.isAdded = this.Repository.CreateEmailInRole(addRole);
 }
 /// <summary>
 /// Creates the email in role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public override bool CreateEmailInRole(EmailInRole emailInRole)
 {
     bool isCreated = false;
     using (this.dbContext = new BuildMotionDb(this.connectionStringName))
     {
         this.dbContext.EmailInRoles.Add(emailInRole);
         int result = this.dbContext.SaveChanges();
         isCreated = result > 0;
     }
     return isCreated;
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="EmailInRoleIsValidRule" /> class.
        /// </summary>
        /// <param name="name"> The name. </param>
        /// <param name="message"> The message. </param>
        /// <param name="target"></param>
        public EmailInRoleIsValidRule(string name, string message, EmailInRole target)
            : base(name, message)
        {
            this.RenderType = RenderType.EvaluateAllRules;

            this.Rules.Add(new IsNotNullRule("EmailInRoleIsNotNull", "The EmailInRole object cannot be null.", target));
            if (target != null)
            {
                this.Rules.Add(new Range<int>("RoleIdIsValid", "The roleId is not valid.", target.RoleId, 1, int.MaxValue));
                this.Rules.Add(new StringIsNotEmptySpace("EmailAddressIsValidString",
                                                         "The email address cannot be empty or null string.", target.Email));
            }
        }
        /// <summary>
        /// Does this instance.
        /// </summary>
        public override void PerformAction()
        {
            // retrieve all roles for the current user;
            List<EmailInRole> currentRoles = this.Repository.RetrieveUserRoles(this.email);

            // check for duplicate roles; only add distinct roles;
            var duplicate = (from cr in currentRoles
                             where cr.RoleId == this.roleId
                             select cr).FirstOrDefault();

            if (duplicate == null)
            {
                // add new role if not already exists;
                EmailInRole emailInRole = new EmailInRole{
                    Email = this.email,
                    RoleId = this.roleId
                };
                this.isAdded = this.Repository.CreateEmailInRole(emailInRole);
            }
        }
        public void CanRemoveAndAddUserRoleForUser()
        {
            EmailInRoles emailInRoles = this.membershipService.RetrieveEmailInRoles(this.emailAddress);
            Assert.IsNotNull(emailInRoles);
            Assert.Greater(emailInRoles.Count, 0);

            foreach(EmailInRole emailInRole in emailInRoles)
            {
                EmailInRole addRole = new EmailInRole{
                    Email = emailInRole.Email,
                    RoleId = emailInRole.RoleId
                };
                Console.WriteLine(emailInRole.ToString());

                bool isRemoved = this.membershipService.RemoveUserInRole(emailInRole);
                Assert.IsTrue(isRemoved);

                bool isAdded = this.membershipService.AddUserToRole(addRole);
                Assert.IsTrue(isAdded);
            }
        }
 /// <summary>
 ///     Removes the user in role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public override bool RemoveUserInRole(EmailInRole emailInRole)
 {
     bool isRemoved = false;
     RemoveUserInRoleAction action = new RemoveUserInRoleAction(emailInRole, this);
     action.Execute();
     if (action.Result == ActionResult.Success)
     {
         isRemoved = action.IsRemoved;
     }
     return isRemoved;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AddUserToRoleAction"/> class.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <param name="membershipProvider">The membership provider.</param>
 public AddUserToRoleAction(EmailInRole emailInRole, MembershipProviderBase membershipProvider)
     : base(membershipProvider)
 {
     this.emailInRole = emailInRole;
 }
 /// <summary>
 /// Creates the email in role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public abstract bool CreateEmailInRole(EmailInRole emailInRole);
 /// <summary>
 /// Removes the user in role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public bool RemoveUserInRole(EmailInRole emailInRole)
 {
     return this.dataAccessContext.EntityFrameworkDataAccess.RemoveUserInRole(emailInRole);
 }
 /// <summary>
 /// Removes the user in role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public abstract bool RemoveUserInRole(EmailInRole emailInRole);
 /// <summary>
 /// Removes the user in role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public bool RemoveUserInRole(EmailInRole emailInRole)
 {
     return this.provider.RemoveUserInRole(emailInRole);
 }
 /// <summary>
 /// Creates the email in role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public bool CreateEmailInRole(EmailInRole emailInRole)
 {
     return this.dataAccessContext.EntityFrameworkDataAccess.CreateEmailInRole(emailInRole);
 }
 /// <summary>
 /// Adds the user to role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public abstract bool AddUserToRole(EmailInRole emailInRole);
 /// <summary>
 /// Removes the user in role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public override bool RemoveUserInRole(EmailInRole emailInRole)
 {
     bool isRemoved = false;
     using (dbContext = new BuildMotionDb(this.connectionStringName))
     {
         this.dbContext.EmailInRoles.Attach(emailInRole);
         this.dbContext.Entry(emailInRole).State = EntityState.Deleted;
         int result = this.dbContext.SaveChanges();
         isRemoved = result > 0;
     }
     return isRemoved;
 }
 /// <summary>
 ///     Adds the user to role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public override bool AddUserToRole(EmailInRole emailInRole)
 {
     bool isAdded = false;
     AddUserToRoleAction action = new AddUserToRoleAction(emailInRole, this);
     action.Execute();
     if (action.Result == ActionResult.Success)
     {
         isAdded = action.IsAdded;
     }
     return isAdded;
 }
 /// <summary>
 /// Removes the user in role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public bool RemoveUserInRole(EmailInRole emailInRole)
 {
     return this.adaptor.RemoveUserInRole(emailInRole);
 }
 /// <summary>
 /// Creates the email in role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public bool CreateEmailInRole(EmailInRole emailInRole)
 {
     return this.adaptor.CreateEmailInRole(emailInRole);
 }
 /// <summary>
 /// Adds the user to role.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <returns></returns>
 public bool AddUserToRole(EmailInRole emailInRole)
 {
     return this.provider.AddUserToRole(emailInRole);
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="RemoveUserInRoleAction" /> class.
 /// </summary>
 /// <param name="emailInRole">The email in role.</param>
 /// <param name="membershipProvider">The membership provider.</param>
 public RemoveUserInRoleAction(EmailInRole emailInRole, MembershipProviderBase membershipProvider)
     : base(membershipProvider)
 {
     this.emailInRole = emailInRole;
 }