Example #1
0
        private string CheckDiscount()
        {
            string discount = string.Empty;
            Regex  regex    = new Regex(@"^\+38 \(\d{3}\) \d{3}-\d{2}\d{2}$");

            if (regex.IsMatch(txbPhone.Text))
            {
                using (DB_A2CE2A_OrdersEntities context = new DB_A2CE2A_OrdersEntities())
                {
                    var query = from users in context.Orders
                                where users.Phone == txbPhone.Text
                                select users.Name;
                    discount = query.SingleOrDefault();
                }
            }
            if (string.IsNullOrEmpty(discount))
            {
                return("0");
            }
            else if (Numdays.SelectedIndex < 5)
            {
                return("1");
            }
            else if (Numdays.SelectedIndex < 21)
            {
                return("2");
            }
            else
            {
                return("3");
            }
        }
Example #2
0
        protected async void PlaceOrder(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                DB_A2CE2A_OrdersEntities context = new DB_A2CE2A_OrdersEntities();
                Order newOrder = new Order()
                {
                    Name     = txbName.Text,
                    Phone    = txbPhone.Text,
                    Address_ = txbAdr.Text,
                    BoxType  = (short)BoxListOrders.SelectedIndex,
                    Comment  = txbComment.Text,
                    Email    = txbEmail.Text,
                    NumDays  = Convert.ToInt32(Numdays.SelectedValue),
                    Sex      = Convert.ToBoolean(rblSex.SelectedIndex),
                    Date     = DateTime.Now
                };
                context.Orders.Add(newOrder);
                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                    {
                        Response.Write("Object: " + validationError.Entry.Entity.ToString());
                        Response.Write(" ");
                        foreach (DbValidationError err in validationError.ValidationErrors)
                        {
                            Response.Write(err.ErrorMessage + " ");
                        }
                    }
                }

                Response.Write("<script>alert('Спасибо за заказ');</script>");


                await new NotifySender(newOrder).SendEmail();
            }
        }