protected void btnSave_Click(object sender, EventArgs e) { if (btnSave.Text == "Save") { mode = "Save"; CheckUserAuthentication(mode); } else { mode = "Update"; CheckUserAuthentication(mode); } bool msg = false; string message = string.Empty; try { GroupUserProvider GroupUserProvider = GenerateGroupUserProvider(); List <GroupUserProvider> UserList = GenerateUserList(); List <GroupUserProvider> RoleList = GenerateRoleList(); msg = provider.Save(GroupUserProvider, UserList, RoleList, btnSave.Text); } catch (Exception ex) { message = ex.Message; } if (msg) { MessageHelper.ShowAlertMessage("Data saved successfully"); } else { MessageHelper.ShowAlertMessage(MessageConstants.SavedWarning); } }
private GroupUserProvider GenerateGroupUserProvider() { GroupUserProvider gUPObj = new GroupUserProvider(); if (hfUserCode.Value.IsNotNullOrEmpty()) { gUPObj.GroupCode = hfUserCode.Value; } gUPObj.GroupName = txtGroupName.Text; gUPObj.Description = txtDescription.Text; return(gUPObj); }
private List <GroupUserProvider> GenerateUserList() { List <GroupUserProvider> userList = new List <GroupUserProvider>(); foreach (GridViewRow row in gvUser.Rows) { CheckBox chkSelected = (CheckBox)row.FindControl("ChkUser"); if (chkSelected.Checked) { GroupUserProvider user = new GroupUserProvider(); Label userID = (Label)row.FindControl("lblUserID"); user.UserID = userID.Text; userList.Add(user); } } return(userList); }
private List <GroupUserProvider> GenerateRoleList() { List <GroupUserProvider> RoleList = new List <GroupUserProvider>(); foreach (GridViewRow row in gvRole.Rows) { CheckBox chkSelected = (CheckBox)row.FindControl("ChkRole"); if (chkSelected.Checked) { GroupUserProvider role = new GroupUserProvider(); Label roleCode = (Label)row.FindControl("lblRoleCode"); role.SecurityRuleCode = roleCode.Text; RoleList.Add(role); } } return(RoleList); }
public bool Save(GroupUserProvider GroupUser, List <GroupUserProvider> userList, List <GroupUserProvider> RoleList, string mode) { bool IsSave = false; String GroupCode = string.Empty; try { SqlCommand command = new SqlCommand(); ConnectionOpen(); command.Connection = Connection; this.BeginTransaction(true); command.Transaction = this.Transaction; command.CommandType = CommandType.StoredProcedure; command.CommandText = StoredProcedureNames.GroupSet; if (mode == "Save") { SqlParameter t = new SqlParameter("@GroupCode", SqlDbType.VarChar); t.Direction = ParameterDirection.Output; t.Size = 16; command.Parameters.Add(t); command.Parameters.Add("@Option", SqlDbType.Int).Value = DBConstants.DataModificationOption.Insert; } else { command.Parameters.Add("@GroupCode", SqlDbType.VarChar, 100).Value = GroupUser.GroupCode; command.Parameters.Add("@Option", SqlDbType.Int).Value = DBConstants.DataModificationOption.Update; } command.Parameters.Add("@GroupName", SqlDbType.VarChar, 100).Value = GroupUser.GroupName; command.Parameters.Add("@Description", SqlDbType.VarChar, 200).Value = GroupUser.Description; command.ExecuteNonQuery(); if (mode == "Save") { GroupCode = (string)command.Parameters["@GroupCode"].Value; } else { GroupCode = GroupUser.GroupCode; } //-------------------------------------Group User-------------------------------------- int update = 1; foreach (GroupUserProvider groupUser in userList) { command = new SqlCommand(); command.Connection = Connection; command.Transaction = this.Transaction; command.CommandType = CommandType.StoredProcedure; command.CommandText = StoredProcedureNames.GroupUserSet; command.Parameters.Add("@UserID", SqlDbType.VarChar).Value = groupUser.UserID; command.Parameters.Add("@GroupCode", SqlDbType.VarChar).Value = GroupCode; command.Parameters.Add("@Option", SqlDbType.Int).Value = DBConstants.DataModificationOption.Insert; command.Parameters.Add("@Update", SqlDbType.Int).Value = update; command.ExecuteNonQuery(); update++; } update = 1; foreach (GroupUserProvider groupRole in RoleList) { command = new SqlCommand(); command.Connection = Connection; command.Transaction = this.Transaction; command.CommandType = CommandType.StoredProcedure; command.CommandText = StoredProcedureNames.GroupRoleSet; command.Parameters.Add("@RoleCode", SqlDbType.VarChar).Value = groupRole.SecurityRuleCode; command.Parameters.Add("@GroupCode", SqlDbType.VarChar).Value = GroupCode; command.Parameters.Add("@Option", SqlDbType.Int).Value = DBConstants.DataModificationOption.Insert; command.Parameters.Add("@Update", SqlDbType.Int).Value = update; command.ExecuteNonQuery(); update++; } this.CommitTransaction(); this.ConnectionClosed(); IsSave = true; } catch (Exception exp) { this.RollbackTransaction(); throw new Exception(exp.Message); } finally { this.ConnectionClosed(); } return(IsSave); }