protected void approveButton_Click(object sender, EventArgs e)
    {
        //Database
        CuriousCamEntities db = new CuriousCamEntities();

        //Table
        Users c = (from x in db.Users
                   where x.UserID == userID
                   select x).SingleOrDefault();

        //New values

        if (c != null)
        {
            c.IsApproved = true;

            try
            {
                db.SaveChanges();

                showMessage("User has been approved succesfully...");

                approveButton.Enabled = false;
            }
            catch (Exception ex)
            {
                showMessage("An error occured:" + ex.ToString());
            }
        }
        else
        {
            showMessage("There is a problem with User ID:" + userID);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int videoID = Convert.ToInt32(Request.QueryString["no"]);

            CuriousCamEntities db = new CuriousCamEntities();

            Videos v = (from x in db.Videos
                        where x.VideoID == videoID
                        select x).SingleOrDefault();
            if (v != null)
            {
                string Path = "videos/" + v.Path;

                videoTitle.InnerHtml = v.Title;

                videoSrc1.Attributes["src"] = Path;
                videoSrc2.Attributes["src"] = Path;
                videoSrc3.Attributes["src"] = Path;
                videoSrc4.Attributes["src"] = Path;

                ownerLabel.Text       = func.getUserName(v.UserID);
                ownerLink.NavigateUrl = "VideoOwner.aspx?no=" + v.UserID.ToString();
                topicLabel.Text       = func.getTopicName(v.TopicID);
                subTopicLabel.Text    = func.getSubTopicName(v.SubTopicID);
                dateLabel.Text        = v.UploadDate.ToShortDateString();
            }
            else
            {
                videoTitle.InnerHtml = "Wrong or no video number ...";
            }
        }
    }
    protected void deleteButton_Click(object sender, EventArgs e)
    {
        //Database
        CuriousCamEntities db = new CuriousCamEntities();

        //Table
        Videos c = (from x in db.Videos
                    where x.VideoID == videoID
                    select x).SingleOrDefault();

        if (c != null)
        {
            db.Videos.Remove(c);
            db.SaveChanges();

            string fileFullPath = Server.MapPath("/videos/") + c.Path;

            if (File.Exists(fileFullPath))
            {
                File.Delete(fileFullPath);
            }
        }
        else
        {
            showMessage("Video Delete: Wrong Video ID:" + videoID.ToString());
        }
    }
Example #4
0
    public string setUserPhoto(string email, string fileName)
    {
        if (fileName == null)
        {
            return("person.jpg");
        }

        CuriousCamEntities db = new CuriousCamEntities();

        Users u = (from x in db.Users
                   where x.Email == email
                   select x).SingleOrDefault();

        if (u != null)
        {
            String path        = Server.MapPath("/Photos/");
            string newFileName = "user" + u.UserID + Path.GetExtension(fileName);

            u.Photo = newFileName;
            db.SaveChanges();

            return(newFileName);
        }
        else
        {
            errorMessage = "Wrong user email:" + email;
        }

        return("person.jpg");
    }
Example #5
0
    void LoadData(int userID)
    {
        CuriousCamEntities db = new CuriousCamEntities();;

        //Query
        Users c = (from x in db.Users
                   where x.UserID == userID
                   select x).SingleOrDefault();

        //If a matching record has been found
        if (c != null)
        {
            //New record
            nameText.Text    = c.Name;
            surnameText.Text = c.Surname;

            emailText.Text = c.Email;

            phoneText.Text = c.Phone;

            userTypeDDList.SelectedValue = c.UserType.ToString();
            facultyDDList.SelectedValue  = c.FacultyID.ToString();

            loadDepartments(c.FacultyID);

            departmentDDList.SelectedValue = c.DepartmentID.ToString();

            if (c.Photo != "")
            {
                userImage.ImageUrl = "photos/" + c.Photo;
            }
        }
    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        //Database
        CuriousCamEntities db = new CuriousCamEntities();

        //Table
        Users newRec = new Users();

        //New record
        newRec.Name    = nameText.Text;
        newRec.Surname = surnameText.Text;

        newRec.Email    = emailText.Text;
        newRec.Password = password1Text.Text;

        newRec.Phone = phoneText.Text;

        newRec.UserType     = Convert.ToInt32(userTypeDDList.SelectedValue);
        newRec.FacultyID    = Convert.ToInt32(facultyDDList.SelectedValue);
        newRec.DepartmentID = Convert.ToInt32(departmentDDList.SelectedValue);

        //Active but not approved
        newRec.IsActive = true;

        if (FileUpload.FileName != "")
        {
            if (func.isImage(FileUpload.FileName) == false)
            {
                showMessage("The file you selected must be one these picture formats: gif, jpg or png");
                return;
            }

            newRec.Photo = FileUpload.FileName;
        }
        else
        {
            showMessage("Please select a picture of yours.");
        }
        try
        {
            db.Users.Add(newRec);
            db.SaveChanges();


            string newFileName = func.setUserPhoto(emailText.Text, FileUpload.FileName);

            FileUpload.SaveAs(Server.MapPath("/photos/") + newFileName);
            Image.ImageUrl = "photos/" + newFileName;


            submitButton.Enabled = false;

            showMessage("Your information has been successfully saved. You can log-in after you are approved.");
        }
        catch (Exception ex)
        {
            showMessage("Please try a different username." + ex.ToString());
        }
    }
Example #7
0
    protected void updateButton_Click(object sender, EventArgs e)
    {
        //Database
        CuriousCamEntities db = new CuriousCamEntities();

        //Table
        Users c = (from x in db.Users
                   where x.UserID == userID
                   select x).SingleOrDefault();

        if (c != null)
        {
            //New record
            c.Name    = nameText.Text;
            c.Surname = surnameText.Text;

            c.Email = emailText.Text;
            c.Phone = phoneText.Text;

            c.UserType     = Convert.ToInt32(userTypeDDList.SelectedValue);
            c.FacultyID    = Convert.ToInt32(facultyDDList.SelectedValue);
            c.DepartmentID = Convert.ToInt32(departmentDDList.SelectedValue);

            try{
                if (FileUpload.FileName != "")
                {
                    if (func.isImage(FileUpload.FileName) == false)
                    {
                        showMessage("The file you selected must be one these picture formats: gif, jpg or png");
                        return;
                    }

                    string newFileName = func.setUserPhoto(emailText.Text, FileUpload.FileName);

                    FileUpload.SaveAs(Server.MapPath("/photos/") + newFileName);
                    userImage.ImageUrl = "photos/" + newFileName + "?time=" + DateTime.Now;

                    c.Photo = newFileName;
                }

                db.SaveChanges();

                showMessage("Your information has been successfully updated.");

                Session["name"]    = c.Name;
                Session["surname"] = c.Surname;
                Session["photo"]   = c.Photo;
            }
            catch (Exception ex)
            {
                showMessage("An error occured during update. If you try to change your email. Please try another email.");
            }
        }
        else
        {
            showMessage("User cannot be found in th database:" + userID);
        }
    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        //Database
        CuriousCamEntities db = new CuriousCamEntities();

        //Table
        Videos newRec = new Videos();

        //New record
        newRec.Title  = titleText.Text;
        newRec.UserID = userID;

        newRec.TopicID    = Convert.ToInt32(topicDDList.SelectedValue);
        newRec.SubTopicID = Convert.ToInt32(subTopicDDList.SelectedValue);
        newRec.UploadDate = DateTime.Now.Date;

        if (FileUpload.FileName != "")
        {
            if (func.isVideo(FileUpload.FileName) == false)
            {
                showMessage("The file you selected must be either of these video formats: mp4, webm or ogv.");
                return;
            }

            newRec.Path = FileUpload.FileName;
        }
        else
        {
            showMessage("You should select a video file...");
            return;
        }

        try
        {
            db.Videos.Add(newRec);
            db.SaveChanges();

            string newFileName = func.getUserVideoFileName(userID, newRec.VideoID, FileUpload.FileName);
            FileUpload.SaveAs(Server.MapPath("/videos/") + newFileName);
            newRec.Path = newFileName;


            db.SaveChanges();

            Response.Redirect("VideoUpdate.aspx?no=" + newRec.VideoID);

            submitButton.Enabled = false;

            showMessage("Your video has been successfully saved...");
        }
        catch (Exception ex)
        {
            showMessage("Error:" + ex.ToString());
        }
    }
    protected void updateButton_Click(object sender, EventArgs e)
    {
        //Database
        CuriousCamEntities db = new CuriousCamEntities();

        //Table
        Users c = (from x in db.Users
                   where x.UserID == userID
                   select x).SingleOrDefault();

        if (c != null)
        {
            //New record
            c.Name    = nameText.Text;
            c.Surname = surnameText.Text;

            c.Email = emailText.Text;
            c.Phone = phoneText.Text;

            c.UserType     = Convert.ToInt32(userTypeDDList.SelectedValue);
            c.FacultyID    = Convert.ToInt32(facultyDDList.SelectedValue);
            c.DepartmentID = Convert.ToInt32(departmentDDList.SelectedValue);

            try{
                if (FileUpload.FileName != "")
                {
                    string newFileName = func.setUserPhoto(emailText.Text, FileUpload.FileName);

                    FileUpload.SaveAs(Server.MapPath("/photos/") + newFileName);
                    userImage.ImageUrl = "photos/" + newFileName;

                    c.Photo = newFileName;
                }

                db.SaveChanges();

                showMessage("User information has been successfully updated.");

                if (userID == func.getUserId())
                {
                    Session["name"]    = c.Name;
                    Session["surname"] = c.Surname;
                    Session["photo"]   = FileUpload.FileName;
                }
            }
            catch (Exception ex)
            {
                showMessage("An error occured:" + ex.ToString());
            }
        }
        else
        {
            showMessage("User cannot be found in th database:" + userID);
        }
    }
    void login(string email, string password)
    {
        func.setSessionVar(-1, false, "", "", "", -1, "", false);

        CuriousCamEntities db = new CuriousCamEntities();

        Users p = (from x in db.Users
                   where x.Email == email &&
                   x.Password == password
                   select x).SingleOrDefault();

        if (p == null)
        {
            showMessage("Please check your user name and password!");
        }
        else
        {
            Boolean state = p.IsActive && p.IsApproved;
            func.setSessionVar(p.UserType, p.IsAdmin, p.Email, p.Name, p.Surname, p.UserID, p.Photo, state);


            if (rememberCheckBox.Checked)
            {
                Response.Cookies["email"].Value   = p.Email;
                Response.Cookies["email"].Expires = DateTime.Now.AddDays(7);

                Response.Cookies["password"].Value   = p.Password;
                Response.Cookies["password"].Expires = DateTime.Now.AddDays(7);
            }
            else
            {
                Response.Cookies["email"].Expires    = DateTime.Now.AddDays(-1);
                Response.Cookies["password"].Expires = DateTime.Now.AddDays(-1);
            }

            if (state)
            {
                showMessage("Welcome " + p.Name + " " + p.Surname);
                Response.Redirect("/");
            }
            else
            {
                if (!p.IsActive)
                {
                    showMessage(" Dear " + p.Name + " " + p.Surname + " your account is disabled. Please contact your administrator.");
                }
                else
                {
                    showMessage(" Dear " + p.Name + " " + p.Surname + " your membership is still in the approval process.");
                }
            }
        }
    }
Example #11
0
    public string getSubTopicName(int subTopicID)
    {
        CuriousCamEntities db = new CuriousCamEntities();

        String name = (from x in db.SubTopics
                       where x.SubTopicID == subTopicID
                       select x.SubTopic).SingleOrDefault();

        if (name != null)
        {
            return(name);
        }
        else
        {
            return("Wrong Sub Topic ID");
        }
    }
Example #12
0
    public string getUserName(int userID)
    {
        CuriousCamEntities db = new CuriousCamEntities();

        String name = (from x in db.Users
                       where x.UserID == userID
                       select x.Name + " " + x.Surname).SingleOrDefault();

        if (name != null)
        {
            return(name);
        }
        else
        {
            return("Wrong User ID");
        }
    }
Example #13
0
    public int getUserId(string email)
    {
        CuriousCamEntities db = new CuriousCamEntities();

        int id = (from x in db.Users
                  where x.Email == email
                  select x.UserID).SingleOrDefault();

        if (id != null)
        {
            return(id);
        }
        else
        {
            return(-1);
        }
    }
Example #14
0
    public string getFacultyName(int facultyID)
    {
        CuriousCamEntities db = new CuriousCamEntities();

        String name = (from x in db.Faculties
                       where x.FacultyID == facultyID
                       select x.Name).SingleOrDefault();

        if (name != null)
        {
            return(name);
        }
        else
        {
            return("Wrong Faculty ID");
        }
    }
Example #15
0
    public string getDepartmentName(int departmanID)
    {
        CuriousCamEntities db = new CuriousCamEntities();

        String name = (from x in db.Departments
                       where x.DepartmentID == departmanID
                       select x.Name).SingleOrDefault();

        if (name != null)
        {
            return(name);
        }
        else
        {
            return("Wrong Department ID");
        }
    }
Example #16
0
    void LoadData(int userID)
    {
        CuriousCamEntities db = new CuriousCamEntities();;

        //Query
        Users c = (from x in db.Users
                   where x.UserID == userID
                   select x).SingleOrDefault();

        //If a matching record has been found
        if (c != null)
        {
            //New record
            ownerName.InnerHtml  = c.Name + " " + c.Surname;
            emailLabel.Text      = c.Email;
            facultyLabel.Text    = func.getFacultyName(c.FacultyID);
            departmentLabel.Text = func.getDepartmentName(c.DepartmentID);

            if (c.Photo != "")
            {
                userImage.ImageUrl = "photos/" + c.Photo;
            }

            //Query
            Videos[] v = (from y in db.Videos
                          where y.UserID == userID
                          select y).ToArray();

            string html = "<ul class='list-group'>";

            for (int i = 0; i < v.Length; i++)
            {
                html += "<li class='list-group-item'>";
                html += "<h5><a href='VideoShow.aspx?no=" + v[i].VideoID.ToString() + "'>" +
                        "<b>" + v[i].Title + "</b></a> <small><i>(" + v[i].UploadDate.ToShortDateString() + ")</i></small></h5>";
                html += "</li>";
            }

            html += "</ul>";

            videoList.InnerHtml = html;
        }
    }
    protected void loadDepartments(int facultyID)
    {
        departmentDDList.Items.Clear();

        CuriousCamEntities db = new CuriousCamEntities();

        Departments[] dp = (from x in db.Departments
                            where x.FacultyID == facultyID
                            select x).ToArray();
        if (dp != null)
        {
            for (int i = 0; i < dp.Length; i++)
            {
                ListItem l = new ListItem(dp[i].Name, Convert.ToString(dp[i].DepartmentID));

                departmentDDList.Items.Add(l);
            }
        }
    }
    protected void loadSubTopics(int topicID)
    {
        subTopicDDList.Items.Clear();

        CuriousCamEntities db = new CuriousCamEntities();

        SubTopics [] st = (from x in db.SubTopics
                           where x.MainTopicID == topicID
                           select x).ToArray();

        if (st != null)
        {
            for (int i = 0; i < st.Length; i++)
            {
                ListItem l = new ListItem(st[i].SubTopic, Convert.ToString(st[i].SubTopicID));

                subTopicDDList.Items.Add(l);
            }
        }
    }
    protected void adminButton_Click(object sender, EventArgs e)
    {
        //Database
        CuriousCamEntities db = new CuriousCamEntities();

        //Table
        Users c = (from x in db.Users
                   where x.UserID == userID
                   select x).SingleOrDefault();

        //New values

        if (c != null)
        {
            c.IsAdmin = !c.IsAdmin;

            try
            {
                db.SaveChanges();

                if (c.IsAdmin)
                {
                    adminButton.Text = "Cancel Admin";
                }
                else
                {
                    adminButton.Text = "Make Admin";
                }

                showMessage("User has been " + adminButton.Text + "ed succesfully...");
            }
            catch (Exception ex)
            {
                showMessage("An error occured:" + ex.ToString());
            }
        }
        else
        {
            showMessage("There is a problem with User ID:" + userID);
        }
    }
Example #20
0
    public bool deleteUserVideos(int userID)
    {
        CuriousCamEntities db = new CuriousCamEntities();

        // Delete the rest
        //Table
        Videos[] p = (from x in db.Videos
                      where x.UserID == userID
                      select x).ToArray();
        //New values
        if (p != null)
        {
            if (p.Length > 0)
            {
                for (int i = 0; i < p.Length; i++)
                {
                    string fileFullPath = Server.MapPath("/videos/") + p[i].Path;
                    try
                    {
                        db.Videos.Remove(p[i]);

                        if (File.Exists(fileFullPath))
                        {
                            File.Delete(fileFullPath);
                        }
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.ToString();
                        return(false);
                    }
                }

                db.SaveChanges();

                return(true);
            }
        }

        return(false);
    }
Example #21
0
    public bool removeUser(int userID)
    {
        //Database
        CuriousCamEntities db = new CuriousCamEntities();

        //Table
        Users c = (from x in db.Users
                   where x.UserID == userID
                   select x).SingleOrDefault();

        if (c != null)
        {
            string fileFullPath = Server.MapPath("/images/") + c.Photo;

            if (c.UserType == 1 && !deleteUserVideos(userID))
            {
                errorMessage = "The user could no be deleted. Because his or her vides cannot be deleted: Details:" + errorMessage;
                return(false);
            }


            db.Users.Remove(c);
            db.SaveChanges();

            if (File.Exists(fileFullPath))
            {
                File.Delete(fileFullPath);
            }

            stateMessage = "User has been deleted successfully";

            return(true);
        }
        else
        {
            errorMessage = "Wrong Video ID:" + userID.ToString();
        }

        return(false);
    }
    void loadData(int videoID)
    {
        CuriousCamEntities db = new CuriousCamEntities();;

        //Query
        Videos c = (from x in db.Videos
                    where x.VideoID == videoID
                    select x).SingleOrDefault();

        //If a matching record has been found
        if (c != null)
        {
            if (c.UserID != userID && !func.isAdmin())
            {
                Response.Redirect("/");
            }

            titleText.Text = c.Title;

            videoSrc1.Attributes["src"] = "videos/" + c.Path;
            videoSrc2.Attributes["src"] = "videos/" + c.Path;
            videoSrc3.Attributes["src"] = "videos/" + c.Path;


            topicDDList.SelectedValue = c.TopicID.ToString();
            loadSubTopics(c.TopicID);

            uploadDateLabel.Text = c.UploadDate.ToShortDateString();

            subTopicDDList.SelectedValue = c.SubTopicID.ToString();
        }
        else
        {
            showMessage("Video Update: Wrong Video ID:" + videoID.ToString());
        }
    }
    protected void updateButton_Click(object sender, EventArgs e)
    {
        //Database
        CuriousCamEntities db = new CuriousCamEntities();

        //Table
        Videos c = (from x in db.Videos
                    where x.VideoID == videoID
                    select x).SingleOrDefault();

        if (c != null)
        {
            c.Title      = titleText.Text;
            c.TopicID    = Convert.ToInt32(topicDDList.SelectedValue);
            c.SubTopicID = Convert.ToInt32(subTopicDDList.SelectedValue);

            try
            {
                if (FileUpload.FileName != "")
                {
                    if (func.isVideo(FileUpload.FileName) == false)
                    {
                        showMessage("The file you selected must be either of these video formats: mp4, webm, ogv or flv");
                        return;
                    }


                    if (File.Exists(Server.MapPath("videos/") + c.Path))
                    {
                        File.Delete(Server.MapPath("videos/") + c.Path);
                    }

                    string newFileName = func.getUserVideoFileName(c.UserID, c.VideoID, FileUpload.FileName);
                    FileUpload.SaveAs(Server.MapPath("/videos/") + newFileName);

                    c.Path = newFileName;

                    string vs = "videos/" + c.Path + "?time=" + DateTime.Now;

                    videoSrc1.Attributes["src"] = vs;
                    videoSrc2.Attributes["src"] = vs;
                    videoSrc3.Attributes["src"] = vs;


                    c.UploadDate = DateTime.Now;
                }

                db.SaveChanges();

                showMessage("Your video has been successfully apdated...");
            }
            catch (Exception ex)
            {
                showMessage("Error:" + ex.ToString());
            }
        }
        else
        {
            showMessage("Video Update: Wrong Video ID:" + videoID.ToString());
        }
    }
    public void listUsers(string cat)
    {
        CuriousCamEntities db = new CuriousCamEntities();

        Users[] b;

        if (cat == "apr")
        {
            b = (from x in db.Users where x.IsApproved == false orderby x.IsActive descending select x).ToArray();
            pageTitle.Text = "Users Waiting for Approvement";
        }
        else if (cat == "ins")
        {
            b = (from x in db.Users where x.UserType == 1 orderby x.IsActive descending select x).ToArray();
            pageTitle.Text = "Instructors";
        }
        else if (cat == "std")
        {
            b = (from x in db.Users where x.UserType == 2 orderby x.IsActive descending select x).ToArray();
            pageTitle.Text = "Students";
        }
        else if (cat == "oth")
        {
            b = (from x in db.Users where x.UserType == 0 orderby x.IsActive descending select x).ToArray();
            pageTitle.Text = "Other University Staff";
        }
        else
        {
            b = (from x in db.Users orderby x.IsActive descending select x).ToArray();
            pageTitle.Text = "All Users";
        }



        string html    = "No user to list.";
        bool   putLine = true;

        if (b != null)
        {
            if (b.Length > 0)
            {
                html = "<ul class='list-group'>";

                for (int i = 0; i < b.Length; i++)
                {
                    if (b[i].IsActive == false && putLine)
                    {
                        html   += "<br/><h5 class='text-danger'>Deactivated Users:</h5>";
                        putLine = false;
                    }

                    html += "<li class='list-group-item'>";
                    html += "<a href='AdminUserManage.aspx?no=" + b[i].UserID + "'>";
                    html += b[i].Name + " " + b[i].Surname + "</a> - <small>" + func.getUserTypeName(b[i].UserType) + "</small>";
                    html += "</li>";
                }

                if (putLine)
                {
                    html += "<br/><h5 class='text-danger'>Deactivated Users:</h5><li class='list-group-item'>No inactive user.</li>";
                }

                html += "</ul>";
            }
        }

        userList.InnerHtml = html;
    }
    void LoadData(int userID)
    {
        CuriousCamEntities db = new CuriousCamEntities();;

        //Query
        Users c = (from x in db.Users
                   where x.UserID == userID
                   select x).SingleOrDefault();


        if (c != null)
        {
            //New record
            nameText.Text    = c.Name;
            surnameText.Text = c.Surname;

            emailText.Text = c.Email;

            phoneText.Text = c.Phone;

            userTypeDDList.SelectedValue = c.UserType.ToString();
            facultyDDList.SelectedValue  = c.FacultyID.ToString();

            loadDepartments(c.FacultyID);

            departmentDDList.SelectedValue = c.DepartmentID.ToString();

            if (c.Photo != "")
            {
                userImage.ImageUrl = "photos/" + c.Photo;
            }

            approveButton.Enabled = !c.IsApproved;
            if (c.IsActive)
            {
                deactivateButton.Text = "Deactivate";
            }
            else
            {
                deactivateButton.Text = "Activate";
            }

            if (c.IsAdmin)
            {
                adminButton.Text = "Cancel Admin";
            }
            else
            {
                adminButton.Text = "Make Admin";
            }

            if (c.UserType == 1)
            {
                userHomeLink1.NavigateUrl = "VideoOwner.aspx?no=" + c.UserID.ToString();
                userHomeLink2.NavigateUrl = "VideoOwner.aspx?no=" + c.UserID.ToString();
            }
            else
            {
                userHomeLink2.Visible = false;
            }
        }
    }