예제 #1
0
        private void BuildUserGroups(int?userId)
        {
            GroupsList.Items.Clear();

            if (userId.HasValue)
            {
                GroupDa  da         = new GroupDa();
                DataView groupsList = da.GetGroupsByUser(userId.Value).DefaultView;
                groupsList.Sort = BOL.Group.GroupName + " ASC";

                // build list of avialble groups
                // groupsList.RowFilter = BOL.UserGroup.UserGroupId + " IS NULL";
                GroupsList.DataSource = groupsList;
                GroupsList.DataBind();
                SetGroupCheckBox(GroupsList, groupsList.Table);

                // build list of current groups
                groupsList.RowFilter             = BOL.UserGroup.UserGroupId + " IS NOT NULL";
                UserGroupsPanel.Visible          = true;
                CurrentUserGroupsRptr.DataSource = groupsList;
                CurrentUserGroupsRptr.DataBind();

                BuildUserAttributes(userId.Value);

                AddUserGroupText.Visible = true;
            }
            else
            {
                DataView groupsList = BOL.BusinessObject.GetAllAsDataView <BOL.Group>();
                groupsList.Sort = BOL.Group.GroupName + " ASC";

                // build list of avialble groups
                GroupsList.DataSource = groupsList;
                GroupsList.DataBind();

                // build list of current groups (empty)
                UserGroupsPanel.Visible          = false;
                CurrentUserGroupsRptr.DataSource = null;
                CurrentUserGroupsRptr.DataBind();

                AddUserGroupText.Visible = false;
            }
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Global.CurrentPerson == null || string.IsNullOrEmpty(Request.QueryString["Series"]))
                {
                    Response.Redirect("Index.aspx");
                }

                SeriesId            = long.Parse(Request.QueryString["Series"]);
                SeriesIdField.Value = SeriesId.ToString();

                DataTable                  eventTable    = new DataTable();
                List <Models.Event>        eventModel    = new List <Models.Event>();
                DataTable                  requestsTable = new DataTable();
                List <Models.GroupRequest> requestsModel = new List <Models.GroupRequest>();

                using (OracleConnection objConn = new OracleConnection(Global.ConnectionString))
                {
                    // Set up the getEvent command
                    var eventCommand = new OracleCommand("TICKETS_QUERIES.getEvent", objConn)
                    {
                        BindByName = true, CommandType = CommandType.StoredProcedure
                    };
                    eventCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue);
                    eventCommand.Parameters.Add("p_SeriesId", OracleDbType.Int64, SeriesId, ParameterDirection.Input);

                    // Set up the getGroupRequestsForEvent command
                    var requestsCommand = new OracleCommand("TICKETS_QUERIES.getGroupRequestsForEvent", objConn)
                    {
                        BindByName = true, CommandType = CommandType.StoredProcedure
                    };
                    requestsCommand.Parameters.Add("p_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue);
                    requestsCommand.Parameters.Add("p_SeriesId", OracleDbType.Int64, SeriesId, ParameterDirection.Input);
                    requestsCommand.Parameters.Add("p_PersonId", OracleDbType.Int64, Global.CurrentPerson.person_id, ParameterDirection.Input);

                    try
                    {
                        // Execute the queries and auto map the results to models
                        objConn.Open();
                        var eventAdapter = new OracleDataAdapter(eventCommand);
                        eventAdapter.Fill(eventTable);
                        eventModel = Mapper.DynamicMap <IDataReader, List <Models.Event> >(eventTable.CreateDataReader());

                        var requestsAdapter = new OracleDataAdapter(requestsCommand);
                        requestsAdapter.Fill(requestsTable);
                        requestsModel = Mapper.DynamicMap <IDataReader, List <Models.GroupRequest> >(requestsTable.CreateDataReader());
                    }
                    catch (Exception)
                    {
                        Response.Redirect("EventSignup.aspx?Series=" + SeriesId);
                    }

                    objConn.Close();
                }

                if (eventModel.Any())
                {
                    var currentEvent = eventModel.FirstOrDefault();
                    EventName.InnerHtml   = currentEvent.name;
                    EventDescription.Text = currentEvent.description;
                    EventLocation.Text    = currentEvent.building;

                    EventDateList.DataSource = eventModel;
                    EventDateList.DataBind();
                }

                if (requestsModel.Any())
                {
                    if (requestsModel.Any(r => r.requested_id == Global.CurrentPerson.person_id && r.has_accepted == 1))
                    {
                        Response.Redirect("AcceptedGroup.aspx?Series=" + SeriesId);
                    }

                    List <Group> groups = requestsModel.GroupBy(distinctGroup => distinctGroup.group_id).Select(group => new Group
                    {
                        group_id = group.First().group_id,
                        group_leader_firstname = group.First().group_leader_firstname,
                        group_leader_lastname  = group.First().group_leader_lastname,
                        group_requests         = requestsModel.Where(r => r.group_id == group.First().group_id).ToList(),
                        guests = group.First().guest_tickets
                    }).ToList();

                    GroupsList.DataSource = groups;
                    GroupsList.DataBind();
                }
                else
                {
                    Response.Redirect("EventSignup.aspx?Series=" + SeriesId);
                }
            }
        }