narsil/Tanshu.Accounts.PointOfSale/User Management/AssignUserGroups.cs
tanshu 69617949bd Important! : Need to update to new schema using SQL Scripts
Important! : This version will not work.  It is pre-alpha and saved in case of catastrophic failure
Refactor: Remove dependency on Fluent Nhibernate.
Refactor: All Primary keys are now Guids.
Refactor: Class Mappings changed from AutoMap to Explicit Mappings.
Breakage: All Cascading is now disabled and entities must be explicitly saved/updated/deleted
Breakage: Auto Commiting is now off and "SaveChanges()" needs to be called on all BIs.
Refactor: Changed the pattern where all relevant db code for an operation is basically in the same function.
Chore: Removed Advance and Payments options.
2014-10-12 15:11:45 +05:30

121 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tanshu.Accounts.Helpers;
using System.Threading;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.PointOfSale
{
public partial class AssignUserGroups : Form
{
public AssignUserGroups()
{
InitializeComponent();
}
private void AssignRoles_Load(object sender, EventArgs e)
{
FillUsers();
}
private void FillUsers()
{
cmbUsers.DisplayMember = "Name";
cmbUsers.ValueMember = "UserID";
using (var bi = new UserBI())
cmbUsers.DataSource = bi.List();
}
private void cmbUsers_SelectedIndexChanged(object sender, EventArgs e)
{
GetLists();
}
private void GetLists()
{
IList<Group> groups;
IList<Group> userGroups;
if (cmbUsers.SelectedValue == null)
{
groups = MembershipBI.GetGroups();
userGroups = new List<Group>();
}
else
{
var userid = (Guid)cmbUsers.SelectedValue;
groups = MembershipBI.GetGroupsNotOfUser(userid);
userGroups = MembershipBI.GetGroupsOfUser(userid);
}
RefreshRoles(groups, userGroups);
}
private void RefreshRoles(IList<Group> groups, IList<Group> userGroups)
{
lstGroups.DisplayMember = "Name";
lstGroups.ValueMember = "GroupID";
lstGroups.DataSource = groups;
lstUserGroups.DisplayMember = "Name";
lstUserGroups.ValueMember = "GroupID";
lstUserGroups.DataSource = userGroups;
btnAddAll.Enabled = btnAddSelected.Enabled = groups.Count > 0;
btnRemoveAll.Enabled = btnRemoveSelected.Enabled = userGroups.Count > 0;
}
private void btnAddSelected_Click(object sender, EventArgs e)
{
if (lstGroups.SelectedItem != null)
{
var userID = (Guid)cmbUsers.SelectedValue;
var groupID = (Guid)lstGroups.SelectedValue;
MembershipBI.AddUserToGroup(userID, groupID);
GetLists();
}
}
private void btnRemoveSelected_Click(object sender, EventArgs e)
{
if (lstUserGroups.SelectedItem != null)
{
Guid userID = (Guid)cmbUsers.SelectedValue;
Guid groupID = (Guid)lstUserGroups.SelectedValue;
MembershipBI.RemoveUserFromGroup(userID, groupID);
GetLists();
}
}
private void btnAddAll_Click(object sender, EventArgs e)
{
var userID = (Guid)cmbUsers.SelectedValue;
Guid groupID;
for (var i = 0; i <= lstGroups.Items.Count - 1; i++)
{
groupID = ((Group)lstGroups.Items[i]).GroupID;
MembershipBI.AddUserToGroup(userID, groupID);
}
GetLists();
}
private void btnRemoveAll_Click(object sender, EventArgs e)
{
var userID = (Guid)cmbUsers.SelectedValue;
Guid groupID;
for (var i = 0; i <= lstUserGroups.Items.Count - 1; i++)
{
groupID = ((Group)lstUserGroups.Items[i]).GroupID;
MembershipBI.RemoveUserFromGroup(userID, groupID);
}
GetLists();
}
}
}