public Product ProductListView_GetData([RouteData] int ProductID) { try { Service service = new Service(); return service.GetProductByID(ProductID); } catch (Exception) { ModelState.AddModelError(String.Empty, "Fel inträffade då produkten hämtades."); return null; } }
public Order OrderFormView_GetData([RouteData] int OrderID) { try { Service service = new Service(); return service.GetOrderByID(OrderID); } catch (Exception) { ModelState.AddModelError(String.Empty, "Fel inträffade då beställning hämtades."); return null; } }
public void ProductFormView_InsertItem(Product product) { if (ModelState.IsValid) { try { Service service = new Service(); service.UpdateProduct(product); //Session["Success"] = true; Response.RedirectToRoute("AProducts"); } catch (Exception) { ModelState.AddModelError(String.Empty, "Fel inträffade då linje skulle läggas till."); } } }
public void OrderFormView_InsertItem(WebshopClick.Model.BLL.Order order) { if (ModelState.IsValid) { try { Service service = new Service(); Orderrow orderrow = new Orderrow(); List<Item> cart = (List<Item>)Session["cart"]; if (cart.Count > 0) { service.UpdateOrder(order); foreach (Item item in cart) { orderrow.OrderID = order.OrderID; orderrow.ProductID = item.Product.ProductID; orderrow.TaxID = 1; orderrow.Quantity = item.Quantity; orderrow.Price = item.Product.Price; orderrow.Discount = Convert.ToDecimal(0); service.UpdateOrderrow(orderrow); orderrow.RowID = 0; } cart.Clear(); FlashPlaceHolder.Visible = true; } } catch (Exception) { ModelState.AddModelError(String.Empty, "Fel inträffade då beställning skulle genomföras."); } } }
protected void BuyButton_OnClick(object sender, EventArgs e) { Button myButton = (Button)sender; Service service = new Service(); int productID = Convert.ToInt32(RouteData.Values["ProductID"]); if (Session["Cart"] == null) { List<Item> cart = new List<Item>(); cart.Add(new Item(this.Service.GetProductByID(productID), 1)); Session["Cart"] = cart; } else { List<Item> cart = (List<Item>)Session["cart"]; int index = isExisting(productID); if (index == -1) { cart.Add(new Item(this.Service.GetProductByID(productID), 1)); } else { cart[index].Quantity++; } Session["Cart"] = cart; } Response.RedirectToRoute("ViewCart"); }
public void UserFormView_InsertItem(WebshopClick.Model.BLL.User user) { //Checks if username already exists in the database TextBox userName = (TextBox)UserFormView.FindControl("Login"); Service service = new Service(); User checkUser = service.GetUserByLoginID(userName.Text); if (checkUser != null) { Session["Reg"] = true; PlaceHolderCheckFail.Visible = true; return; } //Salting password before hashing TextBox pswOriginal = (TextBox)UserFormView.FindControl("Password"); pswOriginal.Text = pswOriginal.Text + userName.Text; TextBox pswConfirm = (TextBox)UserFormView.FindControl("ConfirmPassword"); pswConfirm.Text = pswConfirm.Text + userName.Text; //Hashing of password string hash1 = PasswordHasher.Hash(pswOriginal.Text); string hash2 = PasswordHasher.Hash(pswConfirm.Text); if (ModelState.IsValid) { try { user.Password = hash1; service.UpdateUser(user); FlashPlaceHolder.Visible = true; isLoged(); } catch (Exception) { ModelState.AddModelError(String.Empty, "Fel inträffade då användare skulle läggas till."); } } }
protected void ButtonCheck_Click(object sender, EventArgs e) { TextBox userName = (TextBox)UserFormView.FindControl("Login"); Service service = new Service(); User user = service.GetUserByLoginID(userName.Text); if (ModelState.IsValid) { try { Session["Reg"] = true; if (user == null || user.LoginID == "") { PlaceHolderCheckOK.Visible = true; } else { PlaceHolderCheckFail.Visible = true; } } catch (Exception) { ModelState.AddModelError(String.Empty, "Fel inträffade."); } } }
protected void LoginButton_Click(object sender, EventArgs e) { Service service = new Service(); string pass = PasswordLogin.Text; string userName = UsernameLogin.Text; string password = PasswordLogin.Text + UsernameLogin.Text; string psw = PasswordHasher.Hash(password); User user = service.GetUserByLoginID(userName); if (user != null) { if (user.Password == psw) { Session["User"] = user; isLoged(); return; } } PlaceHolder1.Visible = true; }