Beispiel #1
0
        protected void gvSearchResults_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                /* Check if the first row is a header*/
                if (e.Row.RowType == DataControlRowType.Header)
                {
                    //e.Row.Cells[0].Text = "Name";
                    //e.Row.Cells[1].Text = "Rating";
                }
                /* Check if it is a Data row, then add the name and rating*/
                else if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    SessionsListView searchResult = e.Row.DataItem as SessionsListView;
                    if (searchResult.RegisteredStudents <= 0)
                    {
                        LinkButton lbStudentsList = e.Row.FindControl("lbStudentsList") as LinkButton;
                        lbStudentsList.Visible = false;
                    }

                    if (!searchResult.Status.Equals(SessionStatus.Active.ToString()))
                    {
                        LinkButton lbStudentsList = e.Row.FindControl("lbCancel") as LinkButton;
                        lbStudentsList.Visible = false;

                        LinkButton lbUpdateSession = e.Row.FindControl("lbUpdateSession") as LinkButton;
                        lbUpdateSession.Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        public static Result <object> CanEnrolInSession(SessionsListView ses, OlescUser student)
        {
            Result <object> result = new Result <object>();

            /* If this user has student role */
            if (AccessManagementValidator.UserHasRole(student, Constants.Roles.Student))
            {
                if (ses.TutorID == student.ID)
                {
                    result.isSuccess = false;
                    result.message   = "Student is the same as the Tutor";
                }
                else if (ses.Status.Equals("Active"))
                {
                    if (ses.RemainingSeats > 0)
                    {
                        result.isSuccess = true;
                        result.message   = "Can Enrol in Session there are " + ses.RemainingSeats + " remaining seats";
                    }
                    else
                    {
                        result.isSuccess = false;
                        result.message   = "Session has no empty seats";
                    }
                }
                else
                {
                    result.isSuccess = false;
                    result.message   = "Session is Not Active";
                }
            }
            else
            {
                result.isSuccess = false;
                result.message   = "Provided user is not a student";
            }

            return(result);
        }
        /* Data taken from DataSource, triggered by DataBind
         * What I want to do with it now is in this method*/
        protected void gvSearchResults_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                /* Check if the first row is a header*/
                if (e.Row.RowType == DataControlRowType.Header)
                {
                    //e.Row.Cells[0].Text = "Name";
                    //e.Row.Cells[1].Text = "Rating";
                }
                /* Check if it is a Data row, then add the name and rating*/
                else if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    SessionsListView searchResult = e.Row.DataItem as SessionsListView;

                    /*This has been moved to the screen using Eval() method in grid view*/
                    //Rating rating = (Rating)e.Row.Cells[0].FindControl("rateTutor");
                    //if (rating != null)
                    //{
                    //    if (searchResult.TutorRating == null)
                    //    {
                    //        rating.Visible = false;
                    //    }

                    //    else
                    //    {
                    //        rating.CurrentRating = (int)searchResult.TutorRating;
                    //    }
                    //}

                    //HiddenField hf = (HiddenField)e.Row.FindControl("hdnSessionID");
                    //if (hf != null)
                    //{
                    //    hf.Value = searchResult.SessionID.ToString();
                    //}


                    //Studnet is enrolled and Session is active
                    if (searchResult.Status.Equals(SessionStatus.Active.ToString()))
                    {
                        if (CurrentUser.SessionStudents.Where(s => s.SessionID == searchResult.SessionID).Count() > 0)
                        {
                            (e.Row.FindControl("lbEnrol") as LinkButton).Visible          = false;
                            (e.Row.FindControl("lbDisEnrol") as LinkButton).Visible       = true;
                            (e.Row.FindControl("lbRequestSession") as LinkButton).Visible = false;
                        }
                        else

                        {
                            HiddenField hfRemainingSeats = e.Row.FindControl("hfRemainingSeats") as HiddenField;

                            if (hfRemainingSeats != null && int.Parse(hfRemainingSeats.Value) <= 0)
                            {
                                (e.Row.FindControl("lbRequestSession") as LinkButton).Visible = true;
                            }
                            else
                            {
                                (e.Row.FindControl("lbRequestSession") as LinkButton).Visible = false;
                            }

                            /* session is active and user is not enrolled
                             * when the tutor of the session is the same person searching for sessions, then hide the enroll button for them*/
                            if (searchResult.TutorID == CurrentUser.ID)
                            {
                                (e.Row.FindControl("lbEnrol") as LinkButton).Visible    = false;
                                (e.Row.FindControl("lbDisEnrol") as LinkButton).Visible = false;
                            }
                            else
                            {
                                (e.Row.FindControl("lbEnrol") as LinkButton).Visible    = true;
                                (e.Row.FindControl("lbDisEnrol") as LinkButton).Visible = false;
                            }
                        }
                    }
                    else
                    {
                        (e.Row.FindControl("lbEnrol") as LinkButton).Visible          = false;
                        (e.Row.FindControl("lbDisEnrol") as LinkButton).Visible       = false;
                        (e.Row.FindControl("lbRequestSession") as LinkButton).Visible = false;
                    }
                }
            }
            catch (Exception)
            {
                // Not nessesary
            }
        }