private void FillActiveUserData(Customer customer) { txtFNamn.Text = customer.FirstName; txtENamn.Text = customer.LastName; txtEPost.Text = customer.EmailAddress; txtFNamn.Enabled = false; txtENamn.Enabled = false; txtEPost.Enabled = false; }
private bool GetActiveUser(out Customer customer) { var activeUserID = Session[WebShopController.SessionKeyActiveUserID]; customer = null; if (activeUserID != null) { using (var db = new AvensiaWebshopEntities()) { customer = db.Customer.FirstOrDefault(c => c.CustomerID == (int)activeUserID); return customer != null; } } return false; }
private void SendComfirmationMail(SalesOrderHeader salesOrderHeader, Customer customer) { try { var subject = "Thank you for ordering form FlyCycles"; var body = $"We have recived your order with the order ID {salesOrderHeader.SalesOrderNumber}.\r\n" + $"Best regards\r\n" + $"FlyCycles"; WebShopController.SendMail(WebShopController.SuportMail, new MailAddress(customer.EmailAddress, $"{customer.FirstName} {customer.LastName}"), subject, body); } catch (Exception ex) { // TODO: Logg order confirm mail error. panelMail.Visible = false; panelMailError.Visible = true; } }
protected void btnRegister_Click(object sender, EventArgs e) { using (var db = new AvensiaWebshopEntities()) { var customerExistQuery = db.Customer.FirstOrDefault(c => c.EmailAddress == txtUserName.Text); if (customerExistQuery != null) { lblStatus.Text = "E-postadressen finns redan"; return; } else if (txtPassword.Text != txtConfirmPassword.Text) { lblStatus.Text = "Password must match"; return; } var customer = new Customer() { NameStyle = false, FirstName = txtFirstName.Text.Trim(), LastName = txtLastName.Text.Trim(), EmailAddress = txtUserName.Text, PasswordHash = txtPassword.Text, PasswordSalt = "", rowguid = Guid.NewGuid(), ModifiedDate = DateTime.Now }; db.Customer.Add(customer); db.SaveChanges(); Session[WebShopController.SessionKeyActiveUserID] = customer.CustomerID; Response.Redirect("/Hem.aspx"); } }
protected void btnConfirmOrder_Click(object sender, EventArgs e) { try { var shopingCart = (ShopingCart)Session[WebShopController.SessionKeyShopingCart]; using (var db = new AvensiaWebshopEntities()) { var customer = new Customer() { NameStyle = false, FirstName = txtFNamn.Text.Trim(), LastName = txtENamn.Text.Trim(), EmailAddress = txtEPost.Text.Trim(), PasswordHash = "", PasswordSalt = "", rowguid = Guid.NewGuid(), ModifiedDate = DateTime.Now }; db.Customer.Add(customer); var address = new Address() { AddressLine1 = txtAdress.Text.Trim(), AddressLine2 = txtCoAdress.Text.Trim(), City = txtOrt.Text.Trim(), StateProvince = "", CountryRegion = "", PostalCode = txtPostNr.Text.Trim(), rowguid = Guid.NewGuid(), ModifiedDate = DateTime.Now }; db.Address.Add(address); db.SaveChanges(); var salesOrderHeader = new SalesOrderHeader() { OrderDate = DateTime.Today, DueDate = DateTime.Today.AddDays(14), SalesOrderNumber = "Number", CustomerID = customer.CustomerID, ShipToAddressID = address.AddressID, ShipMethod = rblDeliveryOptions.SelectedItem.Text, TaxAmt = shopingCart.SumTotal * (decimal)0.2, ModifiedDate = DateTime.Now, rowguid = Guid.NewGuid(), Freight = GetFreightPrice() }; db.SalesOrderHeader.Add(salesOrderHeader); db.SaveChanges(); foreach (var cartItem in shopingCart.CartItems) { db.SalesOrderDetail.Add(new SalesOrderDetail() { SalesOrderID = salesOrderHeader.SalesOrderID, OrderQty = cartItem.Quantity, ProductID = cartItem.ProductID, UnitPrice = cartItem.Price * (decimal)0.8, UnitPriceDiscount = (decimal)0, rowguid = Guid.NewGuid(), ModifiedDate = DateTime.Now }); db.SaveChanges(); } Session["LastOrderID"] = salesOrderHeader.SalesOrderID; } } catch (Exception ex) { Session["LastOrderID"] = null; throw; } Session[WebShopController.SessionKeyShopingCart] = new ShopingCart(); Response.Redirect("/Bekraftelse.aspx"); }