Exemple #1
0
        protected void btnCreateVenture_Click(object sender, EventArgs e)
        {
            lblEmailsMust.Visible   = false;
            lblRequired.Visible     = false;
            lblPicCheckSize.Visible = false;
            lblPicCheckType.Visible = false;
            string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName); //uploaded file extension
            int    iFileSize     = FileUpload1.PostedFile.ContentLength;               //uploaded file size
            int    count         = Convert.ToInt32(db.CheckIfVentureNameExists(txtVentureName.Text));

            if (valid.IsBlank(txtVentureName.Text) || valid.IsBlank(txtPrimaryContactEmail.Text) || valid.IsBlank(txtEmail.Text) || valid.IsBlank(txtDescription.Text))
            {
                lblRequired.Visible = true;
            }
            else if (count >= 1)
            {
                lblVentureNameCheck.Visible = true;
            }
            else if (FileUpload1.FileContent == null && FileUpload1.HasFile == false)
            {//no pic detected in control
            }
            else if (valid.TestForLegalImageTypes(fileExtension) == false)
            {//fail
                lblPicCheckType.Visible = true;
                lblPicCheckType.Text    = fileExtension + " file extension is not allowed. Please use .png, .gif, .jpg, .jpeg, .pdf, .pcd, .fpx, .tif instead";
            }
            else if (iFileSize >= 90000)
            {//fail
                lblPicCheckSize.Visible = true;
                lblPicCheckSize.Text    = "Your file size is " + iFileSize + " bytes. Please reduce the size to less than 90 KB (9000 bytes).";
            }
            else
            {
                MemoryStream ms  = new MemoryStream();
                var          img = System.Drawing.Image.FromStream(FileUpload1.FileContent);
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                byte[] imageBytes = ms.ToArray();
                Session["venture-pic-upload"] = imageBytes;

                Venture venture = new Venture
                {
                    name                = txtVentureName.Text,
                    description         = txtDescription.Text,
                    aboutUs             = aboutUs.Text,
                    contactEmail        = txtEmail.Text,
                    contactPhoneNumber  = txtPhoneNumber.Text,
                    contactLinkedIn     = txtLinkedIn.Text,
                    Picture             = (byte[])Session["venture-pic-upload"],
                    primaryContactEmail = txtPrimaryContactEmail.Text,
                    isActive            = true,
                    lastUpdateDate      = DateTime.Now,
                    lastUpdateUser      = txtVentureName.Text
                };
                //create new venture

                int result = db.CreateVenture(venture);

                //add venture info to session
                int ventureID = Convert.ToInt32(db.GetVentureID(venture.name));
                sessionObj.storeVentureDataInSession(ventureID);

                //add current user as a venture member
                string   role             = "Founder";
                Expert   expertProfileObj = (CapstoneBlackstone.Expert)Session["expertProfileObj"];
                string   lastUpdateUser   = expertProfileObj.lastName + ", " + expertProfileObj.firstName;
                DateTime lastUpdateDate   = DateTime.Now;
                string   TUID             = expertProfileObj.tuID;
                db.CreateVentureMember(TUID, ventureID, role, lastUpdateDate, lastUpdateUser);

                //redirect to venture page
                Response.Redirect("VenturePage.aspx?name=" + venture.name);
            }
        }