public void DeleteGroup_Users(List <int> groupUserIDsToDelete)
        {
            //Validate Input
            foreach (int groupUserID in groupUserIDsToDelete)
            {
                if (groupUserID.IsInvalidKey())
                {
                    BusinessLayerHelper.ThrowErrorForInvalidDataKey("GroupUserID");
                }
            }

            List <Group_Users> group_UserssToBeDeleted = new List <Group_Users>();

            foreach (int groupUserID in groupUserIDsToDelete)
            {
                Group_Users group_Users = new Group_Users {
                    GroupUserID = groupUserID
                };
                _DatabaseContext.Group_Users.Attach(group_Users);
                _DatabaseContext.Group_Users.DeleteObject(group_Users);
                group_UserssToBeDeleted.Add(group_Users);
                OnGroup_UsersDeleting(group_Users);
            }

            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows != groupUserIDsToDelete.Count)
            {
                throw new DataNotUpdatedException("One or more group_Users records have not been deleted.");
            }
            foreach (Group_Users group_UsersToBeDeleted in group_UserssToBeDeleted)
            {
                OnGroup_UsersDeleted(group_UsersToBeDeleted);
            }
        }
        public void DeleteGroup_Users(Group_Users group_UsersToBeDeleted)
        {
            //Validate Input
            if (group_UsersToBeDeleted == null)
            {
                throw (new ArgumentNullException("group_UsersToBeDeleted"));
            }

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

            OnGroup_UsersSaving(group_UsersToBeDeleted);
            OnGroup_UsersDeleting(group_UsersToBeDeleted);

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

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

            OnGroup_UsersDeleted(group_UsersToBeDeleted);
            OnGroup_UsersSaved(group_UsersToBeDeleted);
        }
        public void UpdateGroup_Users(Group_Users updatedGroup_Users)
        {
            // Validate Parameters
            if (updatedGroup_Users == null)
            {
                throw (new ArgumentNullException("updatedGroup_Users"));
            }

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

            // Apply business rules
            OnGroup_UsersSaving(updatedGroup_Users);
            OnGroup_UsersUpdating(updatedGroup_Users);

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

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

            //Apply business workflow
            OnGroup_UsersUpdated(updatedGroup_Users);
            OnGroup_UsersSaved(updatedGroup_Users);
        }
        public virtual int CreateNewGroup_Users(Group_Users newGroup_Users)
        {
            // Validate Parameters
            if (newGroup_Users == null)
            {
                throw (new ArgumentNullException("newGroup_Users"));
            }

            // Apply business rules
            OnGroup_UsersSaving(newGroup_Users);
            OnGroup_UsersCreating(newGroup_Users);

            _DatabaseContext.Group_Users.AddObject(newGroup_Users);
            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

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

            // Apply business workflow
            OnGroup_UsersCreated(newGroup_Users);
            OnGroup_UsersSaved(newGroup_Users);

            return(newGroup_Users.GroupUserID);
        }
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
        public bool updatePGroupUser(int ID, User[] UserList)
        {
            try
            {
                if (getGroupById(ID) != null)
                {
                    List <Group_Users> select = base.db.Group_Users.Where(g => g.GroupID == ID).ToList();
                    if (select.Count <= 0)
                    {
                        foreach (User item in UserList)
                        {
                            Group_Users addItem = new Group_Users();
                            if (item.Checked == true)
                            {
                                addItem.GroupID = ID;
                                addItem.UserID  = item.ID;
                                select.Add(addItem);
                            }
                        }
                        base.db.Group_Users.AddRange(select);
                        base.db.SaveChanges();
                    }
                    else
                    {
                        foreach (User item in UserList)
                        {
                            Group_Users addItem = new Group_Users();
                            if (item.Checked == false && select.Where(g => g.UserID == item.ID).Count() == 1)
                            {
                                base.db.Group_Users.Remove(select.Where(g => g.UserID == item.ID).FirstOrDefault());
                            }

                            if (item.Checked == true && select.Where(g => g.UserID == item.ID).Count() == 0)
                            {
                                addItem.GroupID = ID;
                                addItem.UserID  = item.ID;
                                base.db.Group_Users.Add(addItem);
                            }
                        }
                        base.db.SaveChanges();
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Group_Users EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToGroup_Users(Group_Users group_Users)
 {
     base.AddObject("Group_Users", group_Users);
 }
 partial void OnGroup_UsersDeleted(Group_Users group_Users);
 partial void OnGroup_UsersDeleting(Group_Users group_Users);
 partial void OnGroup_UsersSaved(Group_Users group_Users);
 partial void OnGroup_UsersUpdated(Group_Users group_Users);
 partial void OnGroup_UsersUpdating(Group_Users group_Users);
 partial void OnGroup_UsersCreated(Group_Users group_Users);
 partial void OnGroup_UsersCreating(Group_Users group_Users);
 partial void OnGroup_UsersSaving(Group_Users group_Users);