public void DeleteRole_Users(List <int> roleUserIDsToDelete)
        {
            //Validate Input
            foreach (int roleUserID in roleUserIDsToDelete)
            {
                if (roleUserID.IsInvalidKey())
                {
                    BusinessLayerHelper.ThrowErrorForInvalidDataKey("RoleUserID");
                }
            }

            List <Role_Users> role_UserssToBeDeleted = new List <Role_Users>();

            foreach (int roleUserID in roleUserIDsToDelete)
            {
                Role_Users role_Users = new Role_Users {
                    RoleUserID = roleUserID
                };
                _DatabaseContext.Role_Users.Attach(role_Users);
                _DatabaseContext.Role_Users.DeleteObject(role_Users);
                role_UserssToBeDeleted.Add(role_Users);
                OnRole_UsersDeleting(role_Users);
            }

            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows != roleUserIDsToDelete.Count)
            {
                throw new DataNotUpdatedException("One or more role_Users records have not been deleted.");
            }
            foreach (Role_Users role_UsersToBeDeleted in role_UserssToBeDeleted)
            {
                OnRole_UsersDeleted(role_UsersToBeDeleted);
            }
        }
        public void DeleteRole_Users(Role_Users role_UsersToBeDeleted)
        {
            //Validate Input
            if (role_UsersToBeDeleted == null)
            {
                throw (new ArgumentNullException("role_UsersToBeDeleted"));
            }

            // Validate Primary key value
            if (role_UsersToBeDeleted.RoleUserID.IsInvalidKey())
            {
                BusinessLayerHelper.ThrowErrorForInvalidDataKey("RoleUserID");
            }

            OnRole_UsersSaving(role_UsersToBeDeleted);
            OnRole_UsersDeleting(role_UsersToBeDeleted);

            if (role_UsersToBeDeleted.EntityState == EntityState.Detached)
            {
                _DatabaseContext.Role_Users.Attach(role_UsersToBeDeleted);
            }
            _DatabaseContext.Role_Users.DeleteObject(role_UsersToBeDeleted);
            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows == 0)
            {
                throw new DataNotUpdatedException("No Role_Users deleted!");
            }

            OnRole_UsersDeleted(role_UsersToBeDeleted);
            OnRole_UsersSaved(role_UsersToBeDeleted);
        }
        public void UpdateRole_Users(Role_Users updatedRole_Users)
        {
            // Validate Parameters
            if (updatedRole_Users == null)
            {
                throw (new ArgumentNullException("updatedRole_Users"));
            }

            // Validate Primary key value
            if (updatedRole_Users.RoleUserID.IsInvalidKey())
            {
                BusinessLayerHelper.ThrowErrorForInvalidDataKey("RoleUserID");
            }

            // Apply business rules
            OnRole_UsersSaving(updatedRole_Users);
            OnRole_UsersUpdating(updatedRole_Users);

            //attaching and making ready for parsistance
            if (updatedRole_Users.EntityState == EntityState.Detached)
            {
                _DatabaseContext.Role_Users.Attach(updatedRole_Users);
            }
            _DatabaseContext.ObjectStateManager.ChangeObjectState(updatedRole_Users, System.Data.EntityState.Modified);            //this line makes the code un-testable!
            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows == 0)
            {
                throw new DataNotUpdatedException("No role_Users updated!");
            }

            //Apply business workflow
            OnRole_UsersUpdated(updatedRole_Users);
            OnRole_UsersSaved(updatedRole_Users);
        }
        public virtual int CreateNewRole_Users(Role_Users newRole_Users)
        {
            // Validate Parameters
            if (newRole_Users == null)
            {
                throw (new ArgumentNullException("newRole_Users"));
            }

            // Apply business rules
            OnRole_UsersSaving(newRole_Users);
            OnRole_UsersCreating(newRole_Users);

            _DatabaseContext.Role_Users.AddObject(newRole_Users);
            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows == 0)
            {
                throw new DataNotUpdatedException("No role_Users created!");
            }

            // Apply business workflow
            OnRole_UsersCreated(newRole_Users);
            OnRole_UsersSaved(newRole_Users);

            return(newRole_Users.RoleUserID);
        }
Beispiel #5
0
    protected void FormViewUser_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        TextBox          txtUser = (TextBox)formViewUser.FindControl("txtUser");
        UserActionStatus status  = Validate(txtUser.Text, actionType.update);

        if (status == UserActionStatus.Success)
        {
            User user = new UserBLL().GetUserByUserID((Guid)e.Keys["UserId"]);

            using (DatabaseContext _DatabaseContext = new DatabaseContext())
            {
                int roleID  = Convert.ToInt32(((DropDownList)formViewUser.FindControl("ddlRoles")).SelectedValue);
                int groupID = Convert.ToInt32(((DropDownList)formViewUser.FindControl("ddlGroups")).SelectedValue);

                Role_Users role_Users = _DatabaseContext.Role_Users.First(instance => instance.UserID == user.UserID);
                Role       role       = _DatabaseContext.Roles.First(instance => instance.RoleID == roleID);
                role_Users.RoleID = role.RoleID;
                role_Users.RoleReference.EntityKey = role.EntityKey;

                Group_Users group_Users = _DatabaseContext.Group_Users.First(instance => instance.UserID == user.UserID);
                Group       group       = _DatabaseContext.Groups.First(instance => instance.GroupID == groupID);
                group_Users.GroupID = group.GroupID;
                group_Users.GroupReference.EntityKey = group.EntityKey;

                _DatabaseContext.SaveChanges();
            }

            Type           myType = (typeof(User));
            PropertyInfo[] props  = myType.GetProperties();

            string[] arrNewValues = new string[e.NewValues.Keys.Count];
            e.NewValues.Keys.CopyTo(arrNewValues, 0);

            foreach (var prop in props)
            {
                if (("System.String,System.Int,System.DateTime,System.Guid").IndexOf((prop.PropertyType).FullName) >= 0) // Si la propiedad es de tipo Guid, String, Int o DateTime
                {
                    if (!arrNewValues.Contains(prop.Name))
                    {
                        e.NewValues[prop.Name] = prop.GetValue(user, null);
                    }
                }
            }

            User editor = new UserBLL().GetUserByUserName((HttpContext.Current.User.Identity).Name);

            e.NewValues["EditorUserId"] = editor.UserID.ToString();
            e.NewValues["EditedDate"]   = DateTime.Now;
        }
        else
        {
            ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status));
            e.Cancel        = true;
        }
    }
Beispiel #6
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Role_Users EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRole_Users(Role_Users role_Users)
 {
     base.AddObject("Role_Users", role_Users);
 }
 partial void OnRole_UsersDeleted(Role_Users role_Users);
 partial void OnRole_UsersDeleting(Role_Users role_Users);
 partial void OnRole_UsersSaved(Role_Users role_Users);
 partial void OnRole_UsersUpdated(Role_Users role_Users);
 partial void OnRole_UsersUpdating(Role_Users role_Users);
 partial void OnRole_UsersCreated(Role_Users role_Users);
 partial void OnRole_UsersCreating(Role_Users role_Users);
 partial void OnRole_UsersSaving(Role_Users role_Users);