public bool UsersGroup(Client client, out UGroup group) { if(Convert.ToInt32(client.Session["GroupOwnerID"]) >= 0) { XUser user; return Helper.GroupHelper.SelectByID(Convert.ToUInt32(client.Session["GroupOwnerID"]), out group, out user, client); } group = null; return false; }
private void SetRight_Click(object sender, EventArgs e) { if (txtGr != null && dgvPermission.Rows.Count > 0) { if (SetRight.Text == "Add New") { //check there isn't another group with the same name var group = _UnitOfWork.UGroup .AllGroups().Count(c => c.Name == txtGr.Text); if (group == 0) { //create new group first UGroup gr = new UGroup { Name = txtGr.Text }; _UnitOfWork.UGroup.InsertOrUpdate(gr); foreach (DataGridViewRow r in dgvPermission.Rows) { // foreach row we insert the hidden permission Id and newly created user group UGroupPermission ugp = new UGroupPermission { Group = gr, PermissionId = Convert.ToInt32(r.Cells[0].Value) }; _UnitOfWork.GroupPermission.InsertOrUpdate(ugp); } _UnitOfWork.Complete(); MessageBox.Show("You've Successfully created a new user Group and set its rights", "Success"); this.Hide(); } else { MessageBox.Show("this group already exist", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Hide(); } } else if (SetRight.Text == "Set Rights") { try { var grp = _UnitOfWork.UGroup.Find(ugId); var f = _UnitOfWork.GroupPermission.AllGroupPermissions().Where(c => c.GroupId == grp.Id); _UnitOfWork.GroupPermission.RemoveRange(f); grp.Name = txtGr.Text; _UnitOfWork.UGroup.InsertOrUpdate(grp); foreach (DataGridViewRow r in dgvPermission.Rows) { UGroupPermission ugp = new UGroupPermission { GroupId = grp.Id, PermissionId = Convert.ToInt32(r.Cells[0].Value) }; _UnitOfWork.GroupPermission.InsertOrUpdate(ugp); } _UnitOfWork.Complete(); MessageBox.Show("You've Successfully Updated this user group rights", "Success"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show("Hint : Check that your group name field isn't blank and it has at least one right" , "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool SelectByID(uint id, out UGroup group, out XUser Owner, Client client) { XUser user; if(Helper.UserHelper.Table.SelectByID(id, out user)) { group = new UGroup(); group.ID = user.ID; group.Name = user.GroupName != null && user.GroupName != "" ? user.GroupName : user.Name; group.Users = this.GetUsers(user.ID); group.UserCount = group.Users.Count(); group.Winrate = this.CalcWinrate(group.ID); group.BetItemsCount = user.DOTA_GroupTotalBetItemsCount + user.CSGO_GroupTotalBetItemsCount; ushort currency = Helper.UserHelper.GetCurrency(client); if (currency == 1) { group.BetPrice = user.DOTA_RUB_GroupTotalBetPrice + user.CSGO_RUB_GroupTotalBetPrice; group.BetItemsPrice_Str = group.BetPrice.ToString("###,###,##0"); group.GotPriceFromGroup = user.DOTA_RUB_GotPriceFromGroup + user.CSGO_RUB_GotPriceFromGroup; group.GotPriceFromGroup_Str = group.GotPriceFromGroup.ToString("###,###,##0"); } else { group.BetPrice = user.DOTA_GroupTotalBetPrice + user.CSGO_GroupTotalBetPrice; group.BetItemsPrice_Str = group.BetPrice.ToString("###,##0.00"); group.GotPriceFromGroup = user.DOTA_GotPriceFromGroup + user.CSGO_GotPriceFromGroup; group.GotPriceFromGroup_Str = group.GotPriceFromGroup.ToString("###,##0.00"); } group.GotItemsFromGroup = user.DOTA_GotItemsFromGroup + user.CSGO_GotItemsFromGroup; Owner = user; return true; } group = null; Owner = new XUser(); return false; }