protected void btnPost_Click(object sender, EventArgs e) { using (eCommerceDBEntities context = new eCommerceDBEntities()) { if (Session["CustomerID"] != null) { int CustID = Convert.ToInt16(Session["CustomerID"].ToString()); int ProdID = Convert.ToInt16(Request.QueryString["ProductID"]); Review rv = new Review() { ReviewTitle = txtReviewTitle.Text, ReviewDescription = txtReviewDetail.Text, CustomerID = CustID, ProductID = ProdID, Rating = Convert.ToInt16(ddlRatings.SelectedValue), ReviewDate = DateTime.Now }; context.Reviews.AddObject(rv); context.SaveChanges(); string notifyTitle = "Review added"; string message = "Your review has been posted on the product page. Thanks for helping others."; string notification = string.Format("?notifyTitle={0}¬ificationDescription={1}", notifyTitle, message); Response.Redirect("~/product.aspx?ProductID=" + ViewState["prodid"].ToString() + "&" + notification); } } }
protected void btnAdd_Click(object sender, EventArgs e) { try { //Save the file on server's folder kepping the original filename flImageUpload.SaveAs(Server.MapPath(@"~\Site_data\product_images\" + flImageUpload.FileName)); Product pr = new Product { ProductName = txtName.Text, ProductDescription = txtDescription.Text, ProductPrice = Convert.ToDecimal(txtPrice.Text), ProductImageURL = @"~\Site_data\product_images\" + flImageUpload.FileName, Discount = Convert.ToInt16(string.IsNullOrEmpty(txtDiscount.Text) ? "0" : txtDiscount.Text), CategoryID = Convert.ToInt16(ddlCategory.SelectedValue) }; using(eCommerceDBEntities context = new eCommerceDBEntities()) { context.Products.AddObject(pr); context.SaveChanges(); } lblStatus.Text = "Product successfully uploaded."; lblStatus.ForeColor = System.Drawing.Color.Green; hlAddFeature.NavigateUrl = "~/Admin/addFeatures.aspx?ProductID=" + pr.ProductID; } catch (System.IO.DirectoryNotFoundException ex) { lblStatus.ForeColor= System.Drawing.Color.Red; lblStatus.Text = "Select an image first"; } }
protected void btnChange_Click(object sender, EventArgs e) { using (eCommerceDBEntities context = new eCommerceDBEntities()) { //Getting user info based on session variable int id = (int)Session["CustomerID"]; Customer cust = context.Customers.Where(i => i.CustomerID == id).FirstOrDefault(); cust.Password = txtPassword.Text; context.SaveChanges(); } lblError.Visible = true; lblError.Text = "Password successfully updated"; }
protected void btnSave_Click(object sender, EventArgs e) { using (eCommerceDBEntities context = new eCommerceDBEntities()) { Customer cust = context.Customers.Where(i => i.UserName==txtUserName.Text).FirstOrDefault(); cust.CustomerName = txtName.Text; cust.email = txtEmail.Text; cust.ContactNumber = txtContact.Text; cust.Address = txtAddress.Text; cust.Password = txtPassword.Text; cust.sex = ddlGender.SelectedValue; cust.UserType = ddlUserType.SelectedValue; context.SaveChanges(); } }
protected void btnSave_Click(object sender, EventArgs e) { using (eCommerceDBEntities context = new eCommerceDBEntities()) { //Getting user info based on session variable int id = (int)Session["CustomerID"]; Customer cust = context.Customers.Where(i => i.CustomerID == id).FirstOrDefault(); cust.CustomerName = txtName.Text; cust.sex = ddlGender.SelectedValue; cust.UserName = txtUserName.Text; cust.Address = txtAddress.Text; cust.email = txtEmail.Text; cust.ContactNumber = txtContact.Text; context.SaveChanges(); } lblError.Visible = true; lblError.Text = "Details successfully updated"; }
protected void btnSignup_Click(object sender, EventArgs e) { using (eCommerceDBEntities context = new eCommerceDBEntities()) { //New user object created from the information in the webform. Customer newUser = new Customer() { CustomerName = txtName.Text, sex = ddlGender.SelectedValue, UserName = txtUserName.Text, Password = txtPassword.Text, Address = txtAddress.Text, email = txtEmail.Text, ContactNumber = txtContact.Text, UserType = "customer" }; //Lookup if a user with the given username or email already exists in DB. Customer cust = context.Customers.Where(i => i.UserName == newUser.UserName || i.email == newUser.email).FirstOrDefault(); //If user is found, show error, else add new user. if (cust != null) { lblError.Text = "A user with that Email ID or UserName already exists."; lblError.Visible = true; } else { //Add new user to the customers' context context.Customers.AddObject(newUser); //Save new user in the database. context.SaveChanges(); //Send user to loginpage Response.Redirect("login.aspx"); } } }
protected void btnPay_Click(object sender, EventArgs e) { using (eCommerceDBEntities context = new eCommerceDBEntities()) { int custID = Convert.ToInt16(Session["CustomerID"]); if (string.IsNullOrEmpty(txtAmount.Text)) { lblStatus.Text = "Please select mode of payment Debit/Credit card"; lblStatus.ForeColor = System.Drawing.Color.Red; } else { List<Cart> cart = context.Carts.Where(i => i.CustomerID == custID).ToList(); foreach (var i in cart) { //Fill order table context.Orders.AddObject(new Order { CustomerID = custID, ProductID = i.ProductID, DateOrdered = DateTime.Now }); //Product is bought so, empty the cart. context.Carts.DeleteObject(i); } context.SaveChanges(); lblStatus.Text = "Your order has been placed. Happy shopping!"; lblStatus.ForeColor = System.Drawing.Color.Green; string notifyTitle = "Payment Successful!"; string message = "The order has been placed. You will receive your shipment sonn."; string notification = string.Format("?notifyTitle={0}¬ificationDescription={1}", notifyTitle, message); Response.Redirect("~/order.aspx" + notification); } } }
protected void lnkRemoveItem_Click(object sender, EventArgs e) { using (eCommerceDBEntities context = new eCommerceDBEntities()) { //Get the reference of the clicked button. LinkButton button = (sender as LinkButton); //Get the Repeater Item reference RepeaterItem item = button.NamingContainer as RepeaterItem; //Get the repeater item index int index = item.ItemIndex; string id = ((Label)(Repeater1.Items[index].FindControl("lblHiddenCartID"))).Text; int cartid = Convert.ToInt16(id); Cart cr = context.Carts.Where(i => i.CartID == cartid).FirstOrDefault(); context.Carts.DeleteObject(cr); context.SaveChanges(); string notifyTitle = "One item removed"; string message = "One item was removed from your cart!"; string notification = string.Format("?notifyTitle={0}¬ificationDescription={1}", notifyTitle, message); Response.Redirect("~/order.aspx" + notification); } }
protected void btnAdd_Click(object sender, EventArgs e) { using (eCommerceDBEntities context = new eCommerceDBEntities()) { if (rdoChooseFeature.SelectedValue == "1") { Feature fr = new Feature() { MetaFeatureID = Convert.ToInt16(ddlFeatureName.SelectedValue), ProductID = Convert.ToInt16(txtProductID.Text), FeatureDescription = txtBoxFeatureValue.Text }; context.Features.AddObject(fr); } else if (rdoChooseFeature.SelectedValue == "2") { //Show error on empty textbox if (string.IsNullOrEmpty(txtFeatureName.Text)) { lblStatus.ForeColor = System.Drawing.Color.Red; lblStatus.Text = "Please add a feature name."; } else { //Check if the feature already exists MetaFeature mr = context.MetaFeatures.Where(i => i.FeatureName == txtFeatureName.Text).FirstOrDefault(); int id; //If not found, create new row if (mr == null) { MetaFeature mfr = new MetaFeature() { FeatureName = txtFeatureName.Text }; context.MetaFeatures.AddObject(mfr); context.SaveChanges(); //get the ID which is just created id = mfr.MetaFeatureID; Feature fr = new Feature() { MetaFeatureID = id, ProductID = Convert.ToInt16(txtProductID.Text), FeatureDescription = txtBoxFeatureValue.Text }; context.Features.AddObject(fr); } //if found, update row. else { id = mr.MetaFeatureID; Feature fUpdate = context.Features.Where(i => i.MetaFeatureID == id).FirstOrDefault(); fUpdate.FeatureDescription = txtBoxFeatureValue.Text; } } } context.SaveChanges(); lblStatus.ForeColor = System.Drawing.Color.Green; lblStatus.Text = "Feature added successfully. You can add more!"; } }
protected void Page_Load(object sender, EventArgs e) { if (Session["CustomerID"] == null) { string redirectToURL = "~/order.aspx"; Response.Redirect("~/login.aspx?redirect=" + redirectToURL); } if (!IsPostBack) { //Get logged in id int CustID = Convert.ToInt16(Session["CustomerID"]); using (eCommerceDBEntities context = new eCommerceDBEntities()) { if (Request.QueryString["addToCart"] != null) { int ProdID = Convert.ToInt16(Request.QueryString["addToCart"]); //Check if product is already in cart Cart cr = context.Carts.Where(i => i.ProductID == ProdID).FirstOrDefault(); //If not in the DB add it. if (cr == null) { context.Carts.AddObject(new Cart { CustomerID = CustID, ProductID = ProdID, Quantity = 1 }); context.SaveChanges(); } } var cart = (from c in context.Carts join p in context.Products on c.ProductID equals p.ProductID where c.CustomerID == CustID select new { p.ProductName, p.ProductPrice, p.ProductImageURL, c.CartID }); Repeater1.DataSource = cart; Repeater1.DataBind(); Boolean isCartEmpty = context.Carts.Where(i=>i.CustomerID == CustID).FirstOrDefault() == null; //If cart is empty. No ID label means, no cart item if (isCartEmpty) { Wizard1.Visible = false; lblMessage.Visible = true; } } } }