Пример #1
0
        public ActionResult Edit([Bind(Include = "ID,Name,Email,Password,City,Country,Image")] MemberVM member)
        {
            if (Session["UserID"] == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            Member requester = db.Members.Find(Convert.ToInt32(Session["UserID"].ToString()));

            if (requester.ID != member.ID && requester.Role != Coursework.Models.Role.Admin)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            if (ModelState.IsValid)
            {
                Member currentMember = db.Members.Find(member.ID);
                currentMember.Name    = member.Name;
                Session["UserName"]   = member.Name.ToString();
                currentMember.Email   = member.Email;
                currentMember.City    = member.City;
                currentMember.Country = member.Country;

                if (member.Password != null)
                {
                    currentMember.Password = Crypto.HashPassword(member.Password);
                }

                // if an image was attached, do upload to S3
                if (member.Image != null && member.Image.ContentLength > 0)
                {
                    // Image upload courtesy of Stack Overflow, Stephen Muecke, 10/03/2016, https://stackoverflow.com/questions/35904830/asp-net-mvc-upload-image
                    Stream         st         = member.Image.InputStream;
                    string         extension  = Path.GetExtension(member.Image.FileName).ToLower();
                    string         fileName   = string.Format("{0}{1}", Guid.NewGuid(), extension);
                    string         bucketName = "multitude";
                    string         s3dir      = "UserImages";
                    AmazonUploader uploader   = new AmazonUploader();
                    bool           a          = uploader.sendMyFileToS3(st, bucketName, s3dir, fileName);

                    if (a != true)
                    {
                        ModelState.AddModelError("Image", "Image upload to S3 failed.");
                        return(View(member));
                    }

                    currentMember.ImagePath = "https://s3-eu-west-1.amazonaws.com/multitude/UserImages/" + fileName;
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(member));
        }
Пример #2
0
        public ActionResult Edit([Bind(Include = "ID,Title,Description,Pledge,Target,Image")] CauseVM cause)
        {
            Cause currentCause = db.Causes.Find(cause.ID);

            if (Session["UserID"] == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            Member requester = db.Members.Find(Convert.ToInt32(Session["UserID"].ToString()));

            if (requester.ID != currentCause.Member.ID && requester.Role != Coursework.Models.Role.Admin)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            if (ModelState.IsValid)
            {
                currentCause.Title       = cause.Title;
                currentCause.Description = cause.Description;
                currentCause.Pledge      = cause.Pledge;
                currentCause.Target      = cause.Target;

                // if an image was attached, do upload to S3
                if (cause.Image != null && cause.Image.ContentLength > 0)
                {
                    // Save file to S3 and add path to model
                    Stream         st         = cause.Image.InputStream;
                    string         extension  = Path.GetExtension(cause.Image.FileName).ToLower();
                    string         fileName   = string.Format("{0}{1}", Guid.NewGuid(), extension);
                    string         bucketName = "multitude";
                    string         s3dir      = "UserImages";
                    AmazonUploader uploader   = new AmazonUploader();
                    bool           a          = uploader.sendMyFileToS3(st, bucketName, s3dir, fileName);

                    if (a != true)
                    {
                        ModelState.AddModelError("Image", "Image upload to S3 failed.");
                        return(View(cause));
                    }

                    currentCause.ImageURL = "https://s3-eu-west-1.amazonaws.com/multitude/UserImages/" + fileName;
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(cause));
        }
    protected void FileUpload1_Click(object sender, EventArgs e)
    {
        if (FileUploadControl.HasFile)
        {
            Random         rnd             = new Random();
            int            imageUniqueID   = rnd.Next(1, 10000);
            Stream         st              = FileUploadControl.PostedFile.InputStream;
            string         name            = Path.GetFileName(FileUploadControl.FileName);
            string         myBucketName    = "elasticbeanstalk-us-east-1-606091308774"; //your s3 bucket name goes here
            string         s3DirectoryName = "PropertyImages";
            string         s3FileName      = imageUniqueID.ToString() + @name;
            bool           a;
            AmazonUploader myUploader = new AmazonUploader();
            a = myUploader.sendMyFileToS3(st, myBucketName, s3DirectoryName, s3FileName);
            //Insert image to property
            System.Data.SqlClient.SqlConnection sc = new System.Data.SqlClient.SqlConnection();
            sc.ConnectionString = "server=aawnyfad9tm1sf.cqpnea2xsqc1.us-east-1.rds.amazonaws.com; database =roommagnetdb;uid=admin;password=Skylinejmu2019;";
            System.Data.SqlClient.SqlCommand insert = new System.Data.SqlClient.SqlCommand();
            insert.Connection = sc;
            sc.Open();

            insert.Parameters.Add(new System.Data.SqlClient.SqlParameter("@imagefilename", s3FileName));
            insert.CommandText = "INSERT INTO PropertyImages VALUES(NULL, @imagefilename)";

            string check = insert.CommandText;
            Console.Write(check);
            insert.ExecuteNonQuery();

            sc.Close();

            string selectQ = "SELECT MAX(ImagesID) from PropertyImages";
            System.Data.SqlClient.SqlCommand select = new System.Data.SqlClient.SqlCommand(selectQ, sc);
            sc.Open();
            int test = (int)select.ExecuteScalar();

            PropertyRoomImages.propertyRoomImagesArray.Add(test);

            StatusLabel.Text = "Imaged Saved!";
        }
        else
        {
            StatusLabel.Text = "";
        }
    }
Пример #4
0
        public ActionResult Create([Bind(Include = "Title,Description,Pledge,Target,Image")] CauseVM cause)
        {
            if (Session["UserID"] == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            cause.CreatedAt = DateTime.Now;
            int    memberID = Convert.ToInt32(Session["UserID"].ToString());
            Member member   = db.Members.Find(memberID);

            cause.Member = member;
            cause.Signers.Add(member);
            if (cause.Image == null || cause.Image.ContentLength <= 0)
            {
                ModelState.AddModelError("Image", "Image is required.");
            }
            if (ModelState.IsValid)
            {
                // Save file to S3 and add path to model
                Stream         st         = cause.Image.InputStream;
                string         extension  = Path.GetExtension(cause.Image.FileName).ToLower();
                string         fileName   = string.Format("{0}{1}", Guid.NewGuid(), extension);
                string         bucketName = "multitude";
                string         s3dir      = "UserImages";
                AmazonUploader uploader   = new AmazonUploader();
                bool           a          = uploader.sendMyFileToS3(st, bucketName, s3dir, fileName);

                if (a != true)
                {
                    ModelState.AddModelError("Image", "Image upload to S3 failed.");
                    return(View(cause));
                }

                cause.ImageURL = "https://s3-eu-west-1.amazonaws.com/multitude/UserImages/" + fileName;

                db.Causes.Add(new Cause(cause));
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cause));
        }
Пример #5
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        Stream st           = FileUpload1.PostedFile.InputStream;
        string name         = Path.GetFileName(FileUpload1.FileName);
        string myBucketName = "YOURBUCKETNAME";   //your	s3	bucket	name	goe here

        string         s3DirectoryName = "MyFolder2";
        string         s3FileName      = @name;
        bool           a;
        AmazonUploader myUploader = new AmazonUploader();

        a = myUploader.sendMyFileToS3(st, myBucketName, s3DirectoryName, s3FileName);
        if (a == true)
        {
            Response.Write("successfully	uploaded");
        }
        else
        {
            Response.Write("Error");
        }
    }
    protected void HostImageUpdate()
    {
        if (HostImageUpload.HasFile)
        {
            // Upload image to S3
            Random         rnd             = new Random();
            int            imageUniqueID   = rnd.Next(1, 10000);
            Stream         st              = HostImageUpload.PostedFile.InputStream;
            string         name            = Path.GetFileName(HostImageUpload.FileName);
            string         myBucketName    = "elasticbeanstalk-us-east-1-606091308774"; //your s3 bucket name goes here
            string         s3DirectoryName = "UserImages";
            string         s3FileName      = imageUniqueID.ToString() + @name;
            bool           a;
            AmazonUploader myUploader = new AmazonUploader();
            a = myUploader.sendMyFileToS3(st, myBucketName, s3DirectoryName, s3FileName);

            // Grab AccountID to update correct account
            System.Data.SqlClient.SqlConnection sc = new System.Data.SqlClient.SqlConnection();
            sc.ConnectionString = "server=aawnyfad9tm1sf.cqpnea2xsqc1.us-east-1.rds.amazonaws.com; database =roommagnetdb;uid=admin;password=Skylinejmu2019;";
            System.Data.SqlClient.SqlCommand update = new System.Data.SqlClient.SqlCommand();
            update.Connection = sc;
            sc.Open();

            update.Parameters.Add(new System.Data.SqlClient.SqlParameter("@HostID", Session["AccountID"]));
            update.Parameters.Add(new System.Data.SqlClient.SqlParameter("@imagefilename", s3FileName));
            update.CommandText = "UPDATE Account SET AccountImage = @imagefilename WHERE AccountID = @HostID";

            string check = update.CommandText;
            Console.Write(check);
            update.ExecuteNonQuery();

            sc.Close();

            StatusLabel.Text = "Looking good! Profile image updated.";
        }
        else
        {
            StatusLabel.Text = "";
        }
    }