예제 #1
0
    protected void lnkDel_Click(object sender, EventArgs e)
    {
        DulyDBDataContext dc = new DulyDBDataContext();

        var query = (from u in dc.Users
                     where u.userId == int.Parse(Session["dulyNoted"].ToString())
                     select u).First();

        //get all the note
        var note = from n in dc.Notes
                   where n.userId == query.userId
                   select n;

        var comment = from c in dc.Comments
                      where c.userId == query.userId
                      select c;

        //delete note
        dc.Notes.DeleteAllOnSubmit(note);
        dc.Comments.DeleteAllOnSubmit(comment);

        //delete account
        dc.Users.DeleteOnSubmit(query);
        dc.SubmitChanges();

        //abandon session
        Session.Abandon();
        Response.Redirect("~/LogoutConfirm.aspx");
    }
예제 #2
0
    protected void course_select(object sender, EventArgs e)
    {
        //get the course id from the dropdown list
        int cId = int.Parse(ddlCourseNumber.SelectedValue);


        var dc    = new DulyDBDataContext();
        var query = from c in dc.Sections
                    where c.courseId == cId
                    select new { sID = c.sId, sNumber = c.sectionNumber };

        if (query.Count() > 0)
        {
            lblError.Text = "";

            //enable the section number
            ddlSection.Enabled = true;

            ddlSection.DataSource     = query;
            ddlSection.DataTextField  = "sNumber";
            ddlSection.DataValueField = "sId";
            ddlSection.DataBind();

            //insert top line default value
            ddlSection.Items.Insert(0, new ListItem("Please Select...", "-1"));
        }
        else
        {
            lblError.Text = "no Section for the selected Course Number";
        }
    }
예제 #3
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        DulyDBDataContext dc = new DulyDBDataContext();

        //check if user leave blank fields
        if (txtAdminId.Text.Trim() != "" && txtPassword.Text.Trim() != "")
        {
            //check if correct email and pass
            var query = from u in dc.Admins
                        where u.adminId == txtAdminId.Text && u.password == txtPassword.Text
                        select u;
            if (query.Count() > 0)
            {
                //get the user record (row) from Users table
                var admin = query.First();

                //using session for secured page
                Session["Admin"] = admin.adminId;

                //redirect to admin page
                Response.Redirect("~/AdminPage.aspx");
            }
            else
            {
                lblError.Text = "Please check your Id / password";
            }
        }
    }
예제 #4
0
    //comment part
    protected void PostCommentButton_Click(object sender, EventArgs e)
    {
        if (Session["dulyNoted"] != null)
        {
            // no blank comments
            if (txtCommentTextBox.Text.Trim() != "")
            {
                DulyDBDataContext dc = new DulyDBDataContext();
                int uId = int.Parse(Session["dulyNoted"].ToString());
                int nId = int.Parse(Request.QueryString["Note"]);

                //create new comment
                var newComment = new Comment
                {
                    userId        = uId,
                    noteId        = nId,
                    comment1      = txtCommentTextBox.Text,
                    commentedTime = DateTime.Now
                };

                dc.Comments.InsertOnSubmit(newComment);
                dc.SubmitChanges();
                showComments();

                //reset the text box
                txtCommentTextBox.Text = "";
            }
        }
        else
        {
            doLogin();
        }
    }
    protected void OnSelectedIndexChanged(object sender, EventArgs e)
    {
        string title = GridView1.SelectedRow.Cells[0].Text;

        var dc    = new DulyDBDataContext();
        var qNote = from n in dc.Notes
                    where n.title == title
                    select n;

        foreach (var noteTitle in qNote)
        {
            dc.Notes.DeleteOnSubmit(noteTitle);
        }

        dc.SubmitChanges();

        int sId = getSid();

        if (sId != -1)
        {
            BindData(sId);
        }
        else
        {
            Response.Redirect("~/AdminPage.aspx");
        }
    }
예제 #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Header.DataBind();
        if (Session["dulyNoted"] == null)
        {
            div1.Visible         = false;
            div_Notlogin.Visible = true;
            //modify this to the current page name
            var returnUrl = "Member.aspx";

            //let the login page know which page to return
            string LoginPageUrl = "Login.aspx?ReturnURL=" + returnUrl;
            Page.Header.Controls.Add(new LiteralControl(string.Format("<META http-equiv=\"REFRESH\" content=\"3;url={0}\" > ", LoginPageUrl)));
        }
        else      //logged in
        {
            if (!IsPostBack)
            {
                div1.Visible         = true;
                div_Notlogin.Visible = false;
                divProfile.Visible   = true;
                divNotes.Visible     = false;
                btnProfile.Enabled   = false;

                //get the information
                DulyDBDataContext dc = new DulyDBDataContext();
                var query            = (from u in dc.Users
                                        where u.userId == int.Parse(Session["dulyNoted"].ToString())
                                        select u).First();

                // display info for fun -- replace by actual features later
                lblDisplayname.Text = query.displayName + " last login: " + query.lastLoginDate.Value.ToShortDateString();
            }
        }
    }
예제 #7
0
    protected void btnCheckSubject_Click(object sender, EventArgs e)
    {
        var dc    = new DulyDBDataContext();
        var query = from s in dc.Courses
                    where s.subject == txtSubject.Text
                    select new { cID = s.courseId, cNumber = s.courseNumber };

        if (query.Count() > 0)
        {
            lblError.Text = "";

            //enable the Course Number
            ddlCourseNumber.Enabled = true;

            //populate data to the course List
            ddlCourseNumber.DataSource     = query;
            ddlCourseNumber.DataTextField  = "cNumber";
            ddlCourseNumber.DataValueField = "cID";
            ddlCourseNumber.DataBind();

            //insert the top line default value
            ddlCourseNumber.Items.Insert(0, new ListItem("Please Select...", "-1"));
        }
        else
        {
            lblError.Text = "The Subject you entered does not exist.";
        }
    }
예제 #8
0
    protected void btnUserSearch_Click(object sender, EventArgs e)
    {
        var dc    = new DulyDBDataContext();
        var qUser = (from u in dc.Users
                     where u.displayName == txtUsername.Text
                     select u).First();

        divUser.Visible  = true;
        lblUserName.Text = qUser.firstName;

        banStatus(qUser.email);

        /*
         * var banStatus = from n in dc.BannedEmails
         *               where n.email == qUser.email
         *               select n;
         *
         * if (banStatus.Count() > 0)
         * {
         *  banBtn.Visible = false;
         *  unbanBtn.Visible = true;
         * }
         * else
         * {
         *  banBtn.Visible = true;
         *  unbanBtn.Visible = false;
         * }
         */

        binddata(qUser.userId);
    }
예제 #9
0
    //delete note
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //get note Id
        int nId = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());

        var dc = new DulyDBDataContext();

        //get all comments
        var comment = from c in dc.Comments
                      where c.noteId == nId
                      select c;

        //delete the comments
        dc.Comments.DeleteAllOnSubmit(comment);


/*      This is one way to get the note to delete
 *      var note = (from n in dc.Notes
 *                  where n.noteId == nId
 *                  select n).Single();
 *
 *      dc.Notes.DeleteOnSubmit(note);
 */

        //same as above but using LAMBDA
        dc.Notes.DeleteOnSubmit(dc.Notes.Single(n => n.noteId == nId));
        dc.SubmitChanges();
        BindData();
    }
예제 #10
0
    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
        var dc    = new DulyDBDataContext();
        var qUser = (from u in dc.Users
                     where u.displayName == txtUsername.Text
                     select u).First();

        binddata(qUser.userId);
    }
    //bind data to the gridview
    protected void BindData(int sId)
    {
        var dc = new DulyDBDataContext();

        //join 2 tables: Notes and Users
        var query = from n in dc.Notes
                    where n.sId == sId
                    join u in dc.Users on n.userId equals u.userId
                    select new
        {
            nId      = n.noteId,
            Title    = n.title,
            Uploader = u.displayName,
            UpVote   = n.upVoteCounter,
            DownVote = n.downVoteCounter,
            Flag     = n.numberTimesFlagged
        };

        lblResult.Text = string.Format("{0} notes match your search criteria.", query.Count());

        //sorting handler
        bool sortAsc = this.SortDirection == SortDirection.Ascending ? true : false;

        switch (SortExpression)
        {
        case "Title":
            query = sortAsc ? query.OrderBy(q => q.Title) : query.OrderByDescending(q => q.Title);
            break;

        case "Uploader":
            query = sortAsc ? query.OrderBy(q => q.Uploader) : query.OrderByDescending(q => q.Uploader);
            break;

        case "UpVote":
            query = sortAsc ? query.OrderBy(q => q.UpVote) : query.OrderByDescending(q => q.UpVote);
            break;

        case "DownVote":
            query = sortAsc ? query.OrderBy(q => q.DownVote) : query.OrderByDescending(q => q.DownVote);
            break;

        case "Flag":
            query = sortAsc ? query.OrderBy(q => q.Flag) : query.OrderByDescending(q => q.Flag);
            break;

        default:
            query = sortAsc ? query.OrderBy(q => q.Title) : query.OrderByDescending(q => q.Title);
            break;
        }

        //bind.
        GridView1.DataSource = query.ToList();
        GridView1.DataBind();
    }
예제 #12
0
    protected void rating(string action)
    {
        //check for logged in
        if (Session["dulyNoted"] == null)
        {
            doLogin();
        }
        else
        {
            int nId   = int.Parse(Request.QueryString["Note"]);
            var dc    = new DulyDBDataContext();
            var query = (from n in dc.Notes
                         where n.noteId == nId
                         select n).First();

            //get user Id
            int userId = int.Parse(Session["dulyNoted"].ToString());

            //call the votingRecord
            voteRecord(userId, nId);

            //then just update the voting
            var qvote = (from v in dc.VotingChecks
                         where v.userId == userId && v.noteId == nId
                         select v).First();

            switch (action)
            {
            case "Up":
                query.upVoteCounter += 1;
                qvote.voted          = true;
                disableVoting();
                break;

            case "Down":
                query.downVoteCounter += 1;
                qvote.voted            = true;
                disableVoting();
                break;

            case "Flag":
                query.numberTimesFlagged += 1;
                qvote.flagged             = true;
                btnFlag.Enabled           = false;
                break;
            }

            dc.SubmitChanges();
        }
    }
예제 #13
0
    protected void btnChangePass_Click(object sender, EventArgs e)
    {
        DulyDBDataContext dc = new DulyDBDataContext();

        int userId = int.Parse(Session["dulyNoted"].ToString());

        // retrieve the salt for the given username
        //query the user table
        var saltQuery = from u in dc.Users
                        where u.userId == userId
                        select u.salt;

        string userSalt = saltQuery.First();



        var query = from r in dc.PasswordRecoveries
                    where r.userId == userId && r.validCode == hashPassword(txtTempPass.Text.Trim(), userSalt)
                    select r;

        if (query.Count() > 0)
        {
            var user = (from u in dc.Users
                        where u.userId == userId
                        select u).First();

            // create a new salt for the new password
            string newSalt = createSalt(24);

            // update password and salt in database
            user.password = hashPassword(txtNewPass.Text.Trim(), newSalt);
            user.salt     = newSalt;

            //delete the temp pass
            dc.PasswordRecoveries.DeleteOnSubmit(query.First());

            dc.SubmitChanges();
            lblError.Text = "Successfully changed Password. You will be redirected to member page shortly";

            //redirect to member
            string PageUrl = "Member.aspx";
            Page.Header.Controls.Add(new LiteralControl(string.Format("<META http-equiv=\"REFRESH\" content=\"3;url={0}\" > ", PageUrl)));
        }
        else //no match
        {
            lblError.Text = "Please Check your Temporary password again!";
        }
    }
예제 #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // check to see if the user is logged in.
        if (Session["dulyNoted"] != null)
        {
            //get the logged in user's information information
            DulyDBDataContext dc = new DulyDBDataContext();
            var query            = (from u in dc.Users
                                    where u.userId == int.Parse(Session["dulyNoted"].ToString())
                                    select u).First();


            txtName.Text  = query.firstName.Trim() + " " + query.lastName.Trim();
            txtEmail.Text = query.email.Trim();
        }
    }
예제 #15
0
    //--------------------change pass part --------------------------------------------
    protected void btnChangePass_Click(object sender, EventArgs e)
    {
        DulyDBDataContext dc = new DulyDBDataContext();

        // query db using the userID for the password salt
        var saltQuery = from u in dc.Users
                        where u.userId == int.Parse(Session["dulyNoted"].ToString())
                        select u.salt;

        string userSalt = saltQuery.First();

        string hashedPassword = "******";

        // make sure the user was found
        if (saltQuery.Count() > 0)
        {
            // makes sure there was a valid salt
            if (userSalt != null)
            {
                hashedPassword = hashPassword(txtCurrentPass.Text, userSalt);
            }
        }


        var query = from u in dc.Users
                    where u.userId == int.Parse(Session["dulyNoted"].ToString()) && u.password == hashedPassword
                    select u;

        if (query.Count() > 0)
        {
            var user = query.First();

            userSalt       = createSalt(24);
            hashedPassword = hashPassword(txtNewPass.Text, userSalt);
            user.password  = hashedPassword;
            user.salt      = userSalt;
            dc.SubmitChanges();
            lblError.Text      = "Password successfully changed";
            lblError.ForeColor = System.Drawing.Color.Blue;
        }
        else //no match
        {
            lblError.ForeColor = System.Drawing.Color.Red;
            lblError.Text      = "Please Check your current password again!";
        }
    }
예제 #16
0
    protected Note getNote()
    {
        int nId = (string.IsNullOrEmpty(Request.QueryString["Note"])) ? (int)-1 : int.Parse(Request.QueryString["Note"]);

        if (nId != -1)
        {
            var dc = new DulyDBDataContext();
            return((from n in dc.Notes
                    where n.noteId == nId
                    select n).First());
        }
        else
        {
            Response.Redirect("~/Search.aspx");
            return(null);
        }
    }
예제 #17
0
    protected void btnCheckUsername_Click(object sender, EventArgs e)
    {
        var dc    = new DulyDBDataContext();
        var query = from u in dc.Users
                    where u.displayName == txtUsername.Text
                    select u;

        if (query.Count() > 0)
        {
            lblUserError.Text     = "";
            btnSearchUser.Enabled = true;
        }
        else
        {
            lblUserError.Text = "the User you entered does not exist";
        }
    }
예제 #18
0
    protected void banUser(object sender, EventArgs e)
    {
        var dc    = new DulyDBDataContext();
        var qUser = (from u in dc.Users
                     where u.displayName == txtUsername.Text
                     select u).First();

        var banUser = new BannedEmail
        {
            email = qUser.email
        };

        dc.BannedEmails.InsertOnSubmit(banUser);
        dc.SubmitChanges();
        banStatus(qUser.email);
        binddata(qUser.userId);
    }
예제 #19
0
    protected void showComments()
    {
        //just reset everything
        lblComment.Text = "";

        //original code
        var dc    = new DulyDBDataContext();
        int nId   = int.Parse(Request.QueryString["Note"]);
        var query = from c in dc.Comments
                    where c.noteId == nId
                    join u in dc.Users on c.userId equals u.userId
                    orderby c.commentedTime ascending
                    select new
        {
            cTime  = c.commentedTime,
            cMsg   = c.comment1,
            uName  = u.displayName,
            userId = c.userId
        };

        foreach (var c in query)
        {
            //for fun
            //you will see your own messages on the right side
            if (Session["dulyNoted"] != null && (c.userId == int.Parse(Session["dulyNoted"].ToString())))
            {
                lblComment.Text += "<br /><br /><font size=-2>";
                lblComment.Text += "<span style='float:right'>commented by " + "<font color='red'>You</font>";
                lblComment.Text += " | " + c.cTime.ToShortDateString();
                lblComment.Text += " @ " + c.cTime.ToShortTimeString();
                lblComment.Text += "</span></font><br /><br />";
                lblComment.Text += "<span style='float:right'><p class='triangle-right right'>" + c.cMsg + " </p></span> <br /><br /><br /><br />";
            }

            else
            {
                lblComment.Text += "<br /><br /><font size=-2>";
                lblComment.Text += "<span style='float:left'>commented by " + "<font color='red'>" + c.uName + "</font>";
                lblComment.Text += " | " + c.cTime.ToShortDateString();
                lblComment.Text += " @ " + c.cTime.ToShortTimeString();
                lblComment.Text += "</span></font><br /><br />";
                lblComment.Text += "<span style='float:left'><p class='triangle-right left'>" + c.cMsg + "</p></span> <br /><br /><br /><br /><br />";
            }
        }
    }
예제 #20
0
    //this function return the voting record
    protected VotingCheck doVotingCheck(int userId)
    {
        int nId = int.Parse(Request.QueryString["Note"]);
        var dc  = new DulyDBDataContext();
        //pull the user voting check
        var qvote = from v in dc.VotingChecks
                    where v.userId == userId && v.noteId == nId
                    select v;

        if (qvote.Count() > 0)
        {
            return(qvote.First());
        }
        else
        {
            return(null);
        }
    }
예제 #21
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!this.IsPostBack)
     {
         string            nActivationCode = !string.IsNullOrEmpty(Request.QueryString["activationCode"]) ? Request.QueryString["activationCode"] : Guid.Empty.ToString();
         DulyDBDataContext dc = new DulyDBDataContext();
         if (dc.UserActivations.Any(a => a.activationCode == nActivationCode))
         {
             dc.UserActivations.DeleteOnSubmit(dc.UserActivations.Single(d => d.activationCode == nActivationCode));
             dc.SubmitChanges();
             ltMessage.Text = "Activation successful. Welcome to DulyNoted";
         }
         else
         {
             ltMessage.Text = "Invalid Activation code.";
         }
     }
 }
예제 #22
0
    protected void binddata(int userId)
    {
        var dc    = new DulyDBDataContext();
        var qNote = from n in dc.Notes
                    where n.userId == userId
                    select new
        {
            nId   = n.noteId,
            Title = n.title,
            Flag  = n.numberTimesFlagged
        };


        if (qNote.Count() > 0)
        {
            bool sortAsc = this.SortDirection == SortDirection.Ascending ? true : false;
            switch (SortExpression)
            {
            case "Title":
                qNote = sortAsc ? qNote.OrderBy(q => q.Title) : qNote.OrderByDescending(q => q.Title);
                break;

            case "nID":
                qNote = sortAsc ? qNote.OrderBy(q => q.nId) : qNote.OrderByDescending(q => q.Title);
                break;

            case "Flag":
                qNote = sortAsc ? qNote.OrderBy(q => q.Flag) : qNote.OrderByDescending(q => q.Flag);
                break;

            default:
                qNote = sortAsc ? qNote.OrderBy(q => q.Title) : qNote.OrderByDescending(q => q.Title);
                break;
            }
        }
        if (qNote.Count() < 0)
        {
            NoNotesError.Text = "No notes found.";
        }

        //bind.
        GridView1.DataSource = qNote.ToList();
        GridView1.DataBind();
    }
예제 #23
0
    //register button
    protected void RegisterUser(object sender, EventArgs e)
    {
        DulyDBDataContext dc = new DulyDBDataContext();
        bool nameCheck       = dc.Users.Any(u => u.displayName == txtDisplayName.Text.Trim());
        bool emailCheck      = dc.Users.Any(u => u.email == txtEmail.Text.Trim());

        string message = string.Empty;

        //check for exist user
        if (nameCheck)
        {
            message = "Display name already exists.\\nPlease choose a different Display name.";
        }
        else if (emailCheck)
        {
            message = "This email address has already been used.";
        }
        else
        {
            string salt = createSalt(24);

            var newUser = new User
            {
                email       = txtEmail.Text.Trim(),
                password    = hashPassword(txtPassword.Text.Trim(), salt),
                displayName = txtDisplayName.Text.Trim(),
                firstName   = txtFirstName.Text.Trim(),
                lastName    = txtLastName.Text.Trim(),
                createdDate = DateTime.Now,
                salt        = salt,
            };
            dc.Users.InsertOnSubmit(newUser);
            dc.SubmitChanges();

            //send activation email
            SendActivationEmail(newUser.userId);

            //redirect to confirm page
            string url = "~/Registration_Success.aspx?Email=" + txtEmail.Text.Trim();
            Response.Redirect(url);
        }
        ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
    }
예제 #24
0
    protected void banStatus(string email)
    {
        var dc = new DulyDBDataContext();

        var banStatus = from n in dc.BannedEmails
                        where n.email == email
                        select n;

        if (banStatus.Count() > 0)
        {
            banBtn.Visible   = false;
            unbanBtn.Visible = true;
        }
        else
        {
            banBtn.Visible   = true;
            unbanBtn.Visible = false;
        }
    }
예제 #25
0
    protected void DeleteNote()
    {
        int nId = int.Parse(Request.QueryString["Note"]);
        var dc  = new DulyDBDataContext();

        var comment = from c in dc.Comments
                      where c.noteId == nId
                      select c;

        //delete the comments
        dc.Comments.DeleteAllOnSubmit(comment);

        //delete the note from the database
        dc.Notes.DeleteOnSubmit(dc.Notes.Single(n => n.noteId == nId));
        dc.SubmitChanges();

        //return to member page
        Response.Redirect("~/Member.aspx");
    }
예제 #26
0
    //activation
    private void SendActivationEmail(int Id)
    {
        DulyDBDataContext dc = new DulyDBDataContext();
        string            nActivationCode = Guid.NewGuid().ToString();//generate the code using Guid
        var activation = new UserActivation
        {
            userId         = Id,
            activationCode = nActivationCode
        };

        dc.UserActivations.InsertOnSubmit(activation);
        dc.SubmitChanges();

        //sending email
        using (MailMessage mm = new MailMessage("*****@*****.**", txtEmail.Text))
        {
            mm.Subject = "DulyNoted Account Activation";
            string body = "Hi " + txtDisplayName.Text.Trim() + ",";
            body         += "<br /><br />You're one step away from becoming a DulyNoted member.";
            body         += "<br/> <br/> Below is your account login information:";
            body         += "<br/> email: " + txtEmail.Text.Trim();
            body         += "<br/> First Name: " + txtFirstName.Text.Trim();
            body         += "<br/> Last Name: " + txtLastName.Text.Trim();
            body         += "<br /><br />Please click the following link to activate your account";
            body         += "<br /><a href = '" + Request.Url.AbsoluteUri.Replace("Register.aspx", "Activation_Page.aspx?activationCode=" + nActivationCode + "'>Click here to activate</a>");
            body         += "<br /><br />If you have any problems verifying your account please reply to this email";
            body         += "<br /><br />Welcome to DulyNoted";
            body         += "<br /> DulyNoted Development Team";
            mm.Body       = body;
            mm.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            //SMTP , using gmail... will switch to our own if if we have time to create our SMTP host.
            smtp.Host      = "smtp.gmail.com";
            smtp.EnableSsl = true;
            //lol it the username and password (I know it's not encrypted) for gmail account.
            NetworkCredential NetworkCred = new NetworkCredential("*****@*****.**", "DulyPassword");
            smtp.UseDefaultCredentials = true;
            smtp.Credentials           = NetworkCred;
            smtp.Port = 587;
            smtp.Send(mm);
        }
    }
예제 #27
0
    protected void voteRecord(int userId, int nId)
    {
        var         dc         = new DulyDBDataContext();
        VotingCheck votestatus = doVotingCheck(userId);

        //if there is no record, create new one
        if (votestatus == null)
        {
            var newVotingRec = new VotingCheck
            {
                userId  = userId,
                noteId  = nId,
                flagged = false,
                voted   = false
            };

            dc.VotingChecks.InsertOnSubmit(newVotingRec);
            dc.SubmitChanges();
        }
    }
예제 #28
0
    ////////END OF COPY FROM SEARCH

    protected void OnSelectedIndexChanged(object sender, EventArgs e)
    {
        int NoteID = int.Parse(GridView1.SelectedRow.Cells[1].Text);

        var dc    = new DulyDBDataContext();
        var qNote = from n in dc.Notes
                    where n.noteId == NoteID
                    select n;

        foreach (var nId in qNote)
        {
            dc.Notes.DeleteOnSubmit(nId);
        }

        dc.SubmitChanges();

        var qUser = (from u in dc.Users
                     where u.displayName == txtUsername.Text
                     select u).First();

        binddata(qUser.userId);
    }
예제 #29
0
    protected void check_Subject(object sender, EventArgs e)
    {
        var dc    = new DulyDBDataContext();
        var query = from s in dc.Courses
                    where s.subject == txtSubject.Text
                    select new { cID = s.courseId, cNumber = s.courseNumber };

        if (query.Count() > 0)
        {
            lblError.Text = "";

            //enable the Course Number
            ddlCourseNumber.Enabled = true;

            //populate data to the course List
            ddlCourseNumber.DataSource     = query;
            ddlCourseNumber.DataTextField  = "cNumber";
            ddlCourseNumber.DataValueField = "cID";
            ddlCourseNumber.DataBind();

            //insert the top line default value
            ddlCourseNumber.Items.Insert(0, new ListItem("Please Select...", "-1"));
        }
        else
        {
            lblError.Text = "the Subject you entered does not exist";

            // Clear the drop down lists, and set it to disabled.
            ddlCourseNumber.Items.Clear();
            ddlCourseNumber.Items.Insert(0, new ListItem("Please Select...", "-1"));
            ddlCourseNumber.Enabled = false;

            //Clear section number drop down list, just in case
            ddlSection.Items.Clear();
            ddlSection.Items.Insert(0, new ListItem("Please Select...", "-1"));
            ddlSection.Enabled = false;
        }
    }
예제 #30
0
    //bind data to the gridview
    protected void BindData(int sId)
    {
        var dc = new DulyDBDataContext();

        //join 2 tables: Notes and Users
        var query = from n in dc.Notes
                    where n.sId == sId
                    join u in dc.Users on n.userId equals u.userId
                    select new
        {
            nId              = n.noteId,
            Title            = n.title,
            Uploader         = u.displayName,
            UpVote           = n.upVoteCounter,
            DownVote         = n.downVoteCounter,
            Flag             = n.numberTimesFlagged,
            noteDate         = n.noteDate,
            UploadDate       = n.uploadDate,
            prettyNoteDate   = n.noteDate.Value.ToShortDateString(),
            prettyUploadDate = n.uploadDate.Value.ToShortDateString()
        };

        //get the course and section description
        var qcourse = from s in dc.Sections
                      where s.sId == sId
                      join c in dc.Courses on s.courseId equals c.courseId
                      join p in dc.Professors on s.professorEmail equals p.email
                      select new
        {
            cName    = c.coursename,
            cNumber  = c.courseNumber,
            sNumber  = s.sectionNumber,
            cSubject = c.subject,
            pEmail   = p.email,
            pFirst   = p.firstName,
            pLast    = p.lastName
        };
        var    course     = qcourse.ToList().First();
        string resultText = course.cSubject + " " + course.cNumber + "- " + course.sNumber +
                            "<br/> Description: " + course.cName + "<br/> Professor Name: " + course.pFirst + " " + course.pLast +
                            "<br/> Professor Email: " + course.pEmail + "<br/><br/>There are: " + query.Count() + " notes that match your search criteria.<br/>";

        lblResult.Text = resultText;

        //sorting handler
        bool sortAsc = this.SortDirection == SortDirection.Ascending ? true : false;

        switch (SortExpression)
        {
        case "Title":
            query = sortAsc ? query.OrderBy(q => q.Title) : query.OrderByDescending(q => q.Title);
            break;

        case "Uploader":
            query = sortAsc ? query.OrderBy(q => q.Uploader) : query.OrderByDescending(q => q.Uploader);
            break;

        case "UpVote":
            query = sortAsc ? query.OrderBy(q => q.UpVote) : query.OrderByDescending(q => q.UpVote);
            break;

        case "DownVote":
            query = sortAsc ? query.OrderBy(q => q.DownVote) : query.OrderByDescending(q => q.DownVote);
            break;

        case "Flag":
            query = sortAsc ? query.OrderBy(q => q.Flag) : query.OrderByDescending(q => q.Flag);
            break;

        case "NoteDate":
            query = sortAsc ? query.OrderBy(q => q.noteDate) : query.OrderByDescending(q => q.noteDate);
            break;

        case "UploadDate":
            query = sortAsc ? query.OrderBy(q => q.UploadDate) : query.OrderByDescending(q => q.UploadDate);
            break;

        default:
            query = sortAsc ? query.OrderBy(q => q.Title) : query.OrderByDescending(q => q.Title);
            break;
        }

        //bind.
        GridView1.DataSource = query.ToList();
        GridView1.DataBind();
    }