public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates) { using (var db = new Team2_BookDBEntities()) { try { int CartItemCount = CartItemUpdates.Count(); List <shoppingCart> myCart = CartItems(); foreach (var shoppingCart in myCart) { // Iterate through all rows within shopping cart list for (int i = 0; i < CartItemCount; i++) { if (shoppingCart.product.productID == CartItemUpdates[i].ProductId) { if (CartItemUpdates[i].PurchaseQuantity < 1 || CartItemUpdates[i].RemoveItem == true) { RemoveItem(cartId, shoppingCart.productID); } else { UpdateItem(cartId, shoppingCart.productID, CartItemUpdates[i].PurchaseQuantity); } } } } } catch (Exception exp) { throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp); } } }
private ArrayList createOrderDetailRecord(int orderId) { ordersDetail odl = new ordersDetail(); using (WebDL.Team2_BookDBEntities bke = new Team2_BookDBEntities()) { WebDL.shoppingCart sc = new shoppingCart(); var data = from car in bke.shoppingCarts where car.userID == userId select car; List <WebDL.shoppingCart> scl = data.ToList(); for (int i = 0; i < scl.Count; i++) { odl.ordersID = orderId; odl.productID = scl[i].productID; odl.quantity = scl[i].quantity; odl.ordersDetailDescription = ""; bke.ordersDetails.Add(odl); bke.SaveChanges(); // var odId = (from r in bke.ordersDetails select r).Last(); //int lastID = bke.ordersDetails.AsEnumerable().Last().ordersDetailID; //odIDList[i] = odl.ordersDetailID; odIDList.Add(odl.ordersDetailID); } } return(odIDList); }
protected void btnCreate_Click(object sender, EventArgs e) { using (Team2_BookDBEntities cntx = new Team2_BookDBEntities()) { var createProduct = new product(); createProduct.categoryID = Convert.ToInt32(dropListCategoryType.SelectedValue); createProduct.productName = txtBookName.Text; createProduct.productCode = txtCodeNo.Text; createProduct.productQty = Convert.ToInt32(txtQty.Text); createProduct.productPrice = Convert.ToDouble(txtPrice.Text); createProduct.productDiscount = Convert.ToDouble(txtDiscount.Text); createProduct.productDiscountedPrice = Convert.ToDouble(txtDisPrice.Text); createProduct.productDescription = txtDesc.Text; //createProduct.productID = 5; if (fileUImage.HasFile) { string filename = Path.GetFileName(fileUImage.PostedFile.FileName); fileUImage.SaveAs(Server.MapPath("~/Images") + filename); createProduct.productImage = filename; } lblSuccessful.Text = "Success"; cntx.products.Add(createProduct); cntx.SaveChanges(); } }
public void Dispose() { if (DB != null) { DB.Dispose(); DB = null; } }
private void loadUserId() { userName = Session["userName"].ToString(); using (WebDL.Team2_BookDBEntities bke = new Team2_BookDBEntities()) { WebDL.user user = new user(); var data = from u in bke.users where u.userName == userName select u; userId = data.FirstOrDefault().userID; } }
private void loadCogiggnee() { using (WebDL.Team2_BookDBEntities bke = new Team2_BookDBEntities()) { //int id =bke.users.Find(Session.["userId"]); var data = from ur in bke.users where ur.userID == userId select ur; WebDL.user user = data.First(); lbCustomerName.Text = user.userName; lbDeliveryAddress.Text = user.userAddress; lbContactNumber.Text = user.userPhone.ToString(); } }
private void removeShoppingCart() { using (WebDL.Team2_BookDBEntities bke = new Team2_BookDBEntities()) { var sc = from f in bke.shoppingCarts where f.userID == userId select f; if (sc != null) { bke.shoppingCarts.RemoveRange(sc); bke.SaveChanges(); } } }
private int createOrderRecord() { order order = new order(); using (WebDL.Team2_BookDBEntities bke = new Team2_BookDBEntities()) { order.userID = userId; order.ordersDate = DateTime.Now.Date; order.ordersDescription = ""; bke.orders.Add(order); bke.SaveChanges(); } orderID = order.ordersID; return(orderID); }
private void createDeliveryRecord() { using (WebDL.Team2_BookDBEntities bke = new Team2_BookDBEntities()) { delivery deli = new delivery(); deli.userID = userId; deli.ordersID = orderID; deli.deliveryDate = Convert.ToDateTime(txtDeliveryDate.Text); deli.deliveryStatus = "pending"; deli.deliveryAddress = lbDeliveryAddress.Text; deli.deliveryDescription = txtDeliveryDescrip.Text; bke.deliveries.Add(deli); bke.SaveChanges(); } }
protected void Page_Load(object sender, EventArgs e) { using (Team2_BookDBEntities db = new Team2_BookDBEntities()) { var results = (from p in db.products join c in db.categories on p.categoryID equals c.categoryID select new { productName = p.productName, productCode = p.productCode, productPrice = p.productPrice, productImage = p.productImage, }).ToList(); DataList1.DataSource = results; DataList1.DataBind(); } }
protected void OnRowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = GridView1.Rows[e.RowIndex]; int deliveryId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]); string status = (row.FindControl("txtDeliveryStatus") as TextBox).Text; using (Team2_BookDBEntities entities = new Team2_BookDBEntities()) { delivery delivery = (from d in entities.deliveries where d.deliveryID == deliveryId select d).FirstOrDefault(); delivery.deliveryStatus = status; entities.SaveChanges(); } GridView1.EditIndex = -1; this.BindGrid(); }
protected void Page_Load(object sender, EventArgs e) { using (Team2_BookDBEntities cntx = new Team2_BookDBEntities()) { string loginUserName = Session["userName"].ToString(); var editUser = cntx.users.Where(a => a.userName.Equals(loginUserName)).FirstOrDefault(); if (editUser != null) { txtUserName.Text = editUser.userName; editUser.roleID = 1; txtPassword.Text = editUser.userPassword; txtEmail.Text = editUser.userEmail; txtPhoneNo.Text = Convert.ToString(editUser.userPhone); txtAddress.Text = editUser.userAddress; txtDesc.Text = editUser.userDescription; } } }
public void UpdateItem(string updateCartID, int updateProductID, int quantity) { using (var db = new Team2_BookDBEntities()) { try { var myItem = (from c in db.shoppingCarts where c.user.userName == updateCartID && c.product.productID == updateProductID select c).FirstOrDefault(); if (myItem != null) { myItem.quantity = quantity; db.SaveChanges(); } } catch (Exception exp) { throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp); } } }
private void BindGrid() { Team2_BookDBEntities entities = new Team2_BookDBEntities(); var c = (from d in entities.deliveries join u in entities.users on d.userID equals u.userID select new DeliveryList { deliveryId = d.deliveryID, orderId = d.ordersID, userId = u.userID, userName = u.userName, deliveryAddress = d.deliveryAddress, deliveryDate = d.deliveryDate, deliveryStatus = d.deliveryStatus }).ToList <DeliveryList>(); GridView1.DataSource = c; GridView1.DataBind(); }
public void AddToCart(string name) { ShoppingCartActions Action = new ShoppingCartActions(); Team2_BookDBEntities DB = new Team2_BookDBEntities(); // Retrieve the product from the database. string ShoppingCartId = Action.GetCatrId(); var user = from u in DB.users where u.userName == ShoppingCartId select u; WebDL.user userdata = user.FirstOrDefault(); var book = from b in DB.products where b.productName == name select b; WebDL.product bookdata = book.FirstOrDefault(); var cartItem = DB.shoppingCarts.FirstOrDefault( c => c.user.userName == ShoppingCartId && c.product.productName == name); var product = DB.products.FirstOrDefault(p => p.productName == name); if (cartItem == null) { // Create a new cart item if no cart item exists. cartItem = new shoppingCart { productID = bookdata.productID, quantity = Convert.ToInt32(tbQuantity.Text), userID = userdata.userID, shoppingCartExpiredDate = DateTime.Now.AddDays(7), user = DB.users.SingleOrDefault(u => u.userID == userdata.userID), product = DB.products.SingleOrDefault(p => p.productName == name) }; DB.shoppingCarts.Add(cartItem); } else { // If the item does exist in the cart, // then add one to the quantity. cartItem.quantity += Convert.ToInt32(tbQuantity.Text); } product.productQty -= Convert.ToInt32(tbQuantity.Text); DB.SaveChanges(); }
protected void btnFind(object sender, EventArgs e) { using (Team2_BookDBEntities cntx = new Team2_BookDBEntities()) { var findproduct = cntx.products.FirstOrDefault(m => m.productCode == txtBookCode.Text); if (findproduct != null) { txtBookCode.Text = findproduct.productCode; txtBookName.Text = findproduct.productName; //dropListCategoryType.SelectedValue = findproduct.categoryID.ToString(); txtCategory.Text = findproduct.categoryID.ToString(); txtDescription.Text = findproduct.productDescription; txtQuantity.Text = findproduct.productQty.ToString(); txtPrice.Text = findproduct.productPrice.ToString(); txtDiscount.Text = findproduct.productDiscount.ToString(); txtDiscountedPrice.Text = findproduct.productDiscountedPrice.ToString(); } } }
public void RemoveItem(string removeCartID, int removeProductID) { using (var db = new Team2_BookDBEntities()) { try { var myItem = (from c in db.shoppingCarts where c.user.userName == removeCartID && c.product.productID == removeProductID select c).FirstOrDefault(); if (myItem != null) { // Remove Item. db.shoppingCarts.Remove(myItem); db.SaveChanges(); } } catch (Exception exp) { throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp); } } }
protected void btnUpdate_Click(object sender, EventArgs e) { using (Team2_BookDBEntities cntx = new Team2_BookDBEntities()) { string productcode = txtBookCode.Text; var data = from f in cntx.products where f.productCode == productcode select f; product p = data.First(); p.productName = txtBookName.Text; p.productCode = txtBookCode.Text; //dropListCategoryType.SelectedValue = p.categoryID.ToString(); p.categoryID = Convert.ToInt32(txtCategory.Text); p.productDescription = txtDescription.Text; p.productQty = Convert.ToInt32(txtQuantity.Text); p.productPrice = Convert.ToInt32(txtPrice.Text); p.productDiscount = Convert.ToInt32(txtDiscount.Text); p.productDiscountedPrice = Convert.ToInt32(txtDiscountedPrice.Text); cntx.SaveChanges(); lblSuccess.Text = "Update successfully."; ClearFields(); } }
protected void btnEdit_Click(object sender, EventArgs e) { using (Team2_BookDBEntities cntx = new Team2_BookDBEntities()) { string loginUserName = Session["userName"].ToString(); var editUser = cntx.users.Where(a => a.userName.Equals(loginUserName)).FirstOrDefault(); //var editUser = new user(); if (editUser != null) { editUser.userName = txtUserName.Text; editUser.roleID = 1; editUser.userPassword = txtPassword.Text; editUser.userEmail = txtEmail.Text; editUser.userPhone = Convert.ToInt32(txtPhoneNo.Text); editUser.userAddress = txtAddress.Text; editUser.userDescription = txtDesc.Text; cntx.SaveChanges(); Response.Redirect("/AdminHome.aspx"); } Response.Redirect("/AdminHome.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { //Session["userID"] = "Preethi"; //Session["productName"] = "How to Deal with Anger"; Team2_BookDBEntities DB = new Team2_BookDBEntities(); ShoppingCartActions Action = new ShoppingCartActions(); string pName = Action.getProductName(); var data1 = from b in DB.products where b.productName == pName select b; WebDL.product book = data1.FirstOrDefault(); var data2 = from c in DB.categories where c.categoryID == book.categoryID select c; WebDL.category cat = data2.First(); imgCover.ImageUrl = book.productImage; lbBooktitle.Text = book.productName; tbDescription.Text = book.productDescription; lbCategory1.Text = cat.categoryName.ToString(); lbPrice1.Text = book.productPrice.ToString(); lbbookDiscount.Text = book.productDiscount.ToString(); lbBookqty.Text = book.productQty.ToString(); lbDiscountedPrice1.Text = book.productDiscountedPrice.ToString(); }
protected void btnLogIn_Click(object sender, EventArgs e) { using (Team2_BookDBEntities bookEnt = new Team2_BookDBEntities()) { var userLogIn = bookEnt.users.FirstOrDefault(m => m.userEmail == txtEmail.Text && m.userPassword == txtPassword.Text); if (userLogIn != null) { if (userLogIn.roleID == 1) { Session["userName"] = userLogIn.userName; Response.Redirect("/View_Admin/ViewAllBooks.aspx"); } else { Session["userName"] = userLogIn.userName; Response.Redirect("/Home.aspx"); } } else { lblError.Text = "User Name or Password is incorrect."; } } }