Ejemplo n.º 1
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            string name = AName.Text;
            string desc = ADesc.Text;
            string loca = ALocation.Text;
            int    cat  = int.Parse(category.SelectedItem.Value);

            var    folder   = Server.MapPath("~/uploads");
            string fileName = Path.GetFileName(FileUpload.PostedFile.FileName);
            string filePath = "~/uploads/" + fileName;

            string cost      = APrice.Text;
            string pvditem   = AProvided.Text;
            string bringitem = ABring.Text;


            imgName.Text = fileName.ToString();

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            FileUpload.PostedFile.SaveAs(Server.MapPath(filePath));

            Activity ac = new Activity(name, desc, loca, cat, filePath, cost, pvditem, bringitem);

            int result = ac.AddActivity();

            if (result == 1)
            {
                LblMsg.Text = "Activity successfully added!";

                LblMsg.ForeColor = System.Drawing.Color.Green;
                AName.Text       = "";
                ADesc.Text       = "";
                ALocation.Text   = "";
                category.ClearSelection();
                imgName.Text   = "";
                APrice.Text    = "";
                AProvided.Text = "";
                ABring.Text    = "";

                Response.Redirect("HostView.aspx");
            }
            else
            {
                LblMsg.Text      = "An error occured while adding, try again.";
                LblMsg.ForeColor = System.Drawing.Color.Red;
            }
        }