예제 #1
0
        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");
            }
        }
예제 #2
0
        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");
        }