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 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());
        }
    }
    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);
        }
    }
예제 #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");
    }
    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());
        }
    }
예제 #6
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 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);
        }
    }
    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);
        }
    }
예제 #9
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);
    }
예제 #10
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);
    }
    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());
        }
    }