예제 #1
0
        public async Task <IActionResult> Register(RegisterViewModel registerVm)
        {
            HttpContext.Session.SetString("user_name", "");
            HttpContext.Session.SetString("id", "");
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Error", "Complet all fields.");
                return(View(registerVm));
            }
            var exist = await _context.Persons
                        .SingleOrDefaultAsync(m => m.EmailAddress == registerVm.Email);

            if (exist != null)
            {
                ModelState.AddModelError("Error", "Email address is used.");
                return(View(registerVm));
            }
            exist = await _context.Persons
                    .SingleOrDefaultAsync(m => m.Username == registerVm.UserName);

            if (exist != null)
            {
                ModelState.AddModelError("Error", "Username is used.");
                return(View(registerVm));
            }
            exist = await _context.Persons
                    .SingleOrDefaultAsync(m => m.Cnp == registerVm.Cnp);

            if (exist != null)
            {
                ModelState.AddModelError("Error", "Cnp is used.");
                return(View(registerVm));
            }
            var user = new Person
            {
                Id           = new Guid(),
                Cnp          = registerVm.Cnp,
                FirstName    = registerVm.FirstName,
                LastName     = registerVm.LastName,
                Username     = registerVm.UserName,
                EmailAddress = registerVm.Email,
                Password     = CryptingUtils.Encode(registerVm.Password),
                Gender       = registerVm.Gender,
                Birthday     = registerVm.Birthday,
                Role         = "Patient"
            };

            _context.Add(user);
            await _context.SaveChangesAsync();

            MailUtils email;

            email = new MailUtils(user.EmailAddress, "Account Confirmation.",
                                  "Your account has been successfully created. You can login.\nA beautiful day!\nMedicore team.");

            email.Send();
            return(RedirectToAction("Login", "Persons"));
        }
예제 #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            String email        = txtEmail.Value;
            string smtpUserName = "******";
            string smtpPassword = "******";
            string smtpHost     = "smtp.gmail.com";
            int    smtpPort     = 25;

            string emailTo = email;
            string subject = "Vương quốc son môi";
            string body    = string.Format("Chúng tôi sẽ sớm liên lạc với bạn! Cảm ơn bạn đã ghé thăm shop!");

            MailUtils service = new MailUtils();
            bool      kq      = service.Send(smtpUserName, smtpPassword, smtpHost, smtpPort, emailTo, subject, body);
        }
예제 #3
0
        public async Task <IActionResult> SendEmail(EmailSenderViewModel emailSenderVm)
        {
            if (!ModelState.IsValid)
            {
                return(View(emailSenderVm));
            }
            var isOk = await _context.Persons
                       .SingleOrDefaultAsync(m => m.Username == emailSenderVm.ToUsername);

            if (isOk == null)
            {
                return(View(emailSenderVm));
            }
            MailUtils email;

            email = new MailUtils(isOk.EmailAddress, emailSenderVm.Subject,
                                  emailSenderVm.Body);

            email.Send();
            return(RedirectToAction("Index", "Persons"));
        }
예제 #4
0
 private void SendMail(List <string> files)
 {
     try
     {
         MailUtils.Send("Inserimente Note Geisp.",
                        "Inserimente Note Geisp.",
                        files,
                        ConfigUtils.GetCaricoAddress(), ConfigUtils.GetPostAddress());
     }
     catch
     {
         try
         {
             MailUtils.Send("IImpossibile inviare la posta. È possibile trovare il file excel all'indirizzo: " + files.FirstOrDefault(),
                            "PRESTITEMPO ESITI: errori nell’inserimento degli esiti su sito committente",
                            new List <string>(),
                            ConfigUtils.GetCaricoAddress(), ConfigUtils.GetPostAddress());
         }
         catch { }
         Logger.Log("Impossibile inviare la posta. È possibile che le credenziali di posta non sono buone. È possibile trovare il file excel all'indirizzo: " + files.FirstOrDefault(), LogType.Error);
     }
 }
        public override async Task <IActionResult> Result()
        {
            var currentStep = Storage.GetCurrentStep(MsgId);

            //Switch to next step = currentStep + 1
            switch (currentStep + 1)
            {
                #region step 1
            case 1:
            {
                Storage.AddOrUpdateToStorage(MsgId, 1, null);
                using (var petTypeDAO = new PetTypeDAO())
                {
                    return(Receiver.Json(new
                        {
                            speech = "",
                            messages = new[]
                            {
                                new
                                {
                                    type = 2,
                                    platform = "facebook",
                                    title = "Bạn muốn sản phẩm cho thú cưng nào ạ?",
                                    replies = (await petTypeDAO.ReadAll(false))
                                              .Select(x => x.Name)
                                              .ToArray()
                                }
                            }
                        }));
                }
            }

                #endregion
                #region Step 2
            case 2:
            {
                //Check if answer is valid
                if (!_isSkipValidation)
                {
                    using (var petTypeDAO = new PetTypeDAO())
                    {
                        if (await(await petTypeDAO.ReadAll(false))
                            .Select(x => x.Name)
                            .AllAsync(x => x != MsgReply))
                        {
                            _isSkipValidation = true;
                            goto case 1;
                        }
                    }
                }

                Storage.AddOrUpdateToStorage(MsgId, 2, null);
                Storage.AddOrUpdateToStorage(MsgId, 1, MsgReply);
                return(Receiver.Json(new
                    {
                        speech = "",
                        messages = new[]
                        {
                            new
                            {
                                type = 2,
                                platform = "facebook",
                                title = "Bạn muốn mua gì cho bé ạ?",
                                replies = new[] { "Đồ chơi", "Thức ăn", "Lồng", "phụ kiện" }
                            }
                        }
                    }));
            }

                #endregion
                #region Step 3
            case 3:
            {
                //Check if answer is valid
                if (!_isSkipValidation)
                {
                    if (new[] { "Đồ chơi", "Thức ăn", "Lồng", "phụ kiện" }.All(x => x != MsgReply))
                    {
                        _isSkipValidation = true;
                        goto case 2;
                    }
                }

                Storage.AddOrUpdateToStorage(MsgId, 3, null);
                Storage.AddOrUpdateToStorage(MsgId, 2, MsgReply);
                return(Receiver.Json(new
                    {
                        speech = "",
                        messages = new[]
                        {
                            new
                            {
                                type = 2,
                                platform = "facebook",
                                title = "Bạn có thể cho mình biết mức giá bạn muốn tìm kiếm?",
                                replies = new[] { "<100000", "100000 - 300000", ">300000 - 500000", ">500000" }
                            }
                        }
                    }));
            }
                #endregion
                #region Step 4

            case 4:
            {
                //Check if answer is valid
                if (!_isSkipValidation)
                {
                    if (new[] { "<100000", "100000 - 300000", ">300000 - 500000", ">500000" }.All(x =>
                                                                                                  x != MsgReply))
                    {
                        _isSkipValidation = true;
                        goto case 3;
                    }
                }

                Storage.AddOrUpdateToStorage(MsgId, 4, null);
                Storage.AddOrUpdateToStorage(MsgId, 3, MsgReply);

                //Find minimum and maximum price from step 3
                int minimumPrice, maximumPrice;

                switch (Storage[MsgId, 3])
                {
                case "<100000":
                    minimumPrice = 0;
                    maximumPrice = 99999;
                    break;

                case "100000 - 300000":
                    minimumPrice = 100000;
                    maximumPrice = 300000;
                    break;

                case ">300000 - 500000":
                    minimumPrice = 300001;
                    maximumPrice = 500000;
                    break;

                default:
                    minimumPrice = 500001;
                    maximumPrice = int.MaxValue;
                    break;
                }

                //Find product in step 2, for pet in step 1
                return(await MessengerProductListResult(GetProductType(), minimumPrice, maximumPrice));
            }

                #endregion
                #region Step 5
            case 5:
            {
                //Check if answer is valid
                if (!_isSkipValidation)
                {
                    using (var productDAO = new ProductDAO())
                    {
                        if (await productDAO.Read(MsgQuery, false) == null)
                        {
                            _isSkipValidation = true;
                            goto case 4;
                        }
                    }
                }

                Storage.AddOrUpdateToStorage(MsgId, 5, null);
                Storage.AddOrUpdateToStorage(MsgId, 4, MsgQuery);
                return(Receiver.Json(new
                    {
                        speech = "Bạn có thể cho mình biết tên đăng nhập trên hệ thống Cutieshop được không ạ?\nNếu chưa có, bạn có thể gõ tên đăng nhập mới để chúng mình tạo tài khoản cho bạn"
                    }));
            }
                #endregion
                #region Step 6

            case 6:
            {
                //This step receive username first, then the email and address. So we need to keep the username to the storage for further uses, email will be used once in this step and can be queried by DAO easily in the future.
                //Checking null will prevent email from being overwritten to username in Storage
                if (Storage[MsgId, 5] == null)
                {
                    Storage.AddOrUpdateToStorage(MsgId, 5, MsgReply);
                }

                using (var userDAO = new UserDAO())
                {
                    var user = await userDAO.ReadChild(Storage[MsgId, 5], true);

                    //If user is null, create a user, then ask customer their email
                    if (user == null)
                    {
                        Storage.AddOrUpdateToStorage(MsgId, 6, "userPassword", new GuidHelper().CreateGuid());
                        await userDAO.Create(new Auth
                            {
                                Username = Storage[MsgId, 5],
                                Password = Storage[MsgId, 6, "userPassword"]
                            });

                        await userDAO.CreateChild(new User
                            {
                                Username = Storage[MsgId, 5],
                                Email    = string.Empty,
                                Address  = string.Empty
                            });

                        await userDAO.Context.SaveChangesAsync();
                    }

                    user = await userDAO.ReadChild(Storage[MsgId, 5], true);

                    //If email is empty, as for email
                    if (user.Email == string.Empty)
                    {
                        if (Storage[MsgId, 6, "isAskForEmail"] == null)
                        {
                            Storage.AddOrUpdateToStorage(MsgId, 6, "isAskForEmail", "1");
                            return(Receiver.Json(new
                                {
                                    speech = "Bạn hãy cho mình biết email nhé"
                                }));
                        }

                        //Validate email
                        var atInd = MsgReply.IndexOf("@", StringComparison.OrdinalIgnoreCase);
                        if (atInd < 1 || atInd == MsgReply.Length - 1)
                        {
                            return(Receiver.Json(new
                                {
                                    speech = "Email không hợp lệ\nVui lòng nhập lại email"
                                }));
                        }

                        user.Email = MsgReply;
                        await userDAO.Context.SaveChangesAsync();
                    }

                    //If address is empty but email is not, MsgReply must be address
                    if (user.Address == string.Empty)
                    {
                        if (Storage[MsgId, 6, "isAskForAddress"] == null)
                        {
                            Storage.AddOrUpdateToStorage(MsgId, 6, "isAskForAddress", "1");
                            return(Receiver.Json(new
                                {
                                    speech = "Bạn cho mình xin địa chỉ"
                                }));
                        }

                        user.Address = MsgReply;
                        await userDAO.Context.SaveChangesAsync();
                    }

                    //Ready to jump into step 7 after this
                    Storage.AddOrUpdateToStorage(MsgId, 6, null);

                    using (var onlineOrderProductDAO = new OnlineOrderProductDAO(userDAO.Context))
                    {
                        var orderId = new GuidHelper().CreateGuid();
                        await onlineOrderProductDAO.Create(new OnlineOrder
                            {
                                OnlineOrderId = orderId,
                                FirstName     = user.FirstName,
                                LastName      = user.LastName,
                                Address       = user.Address,
                                PostCode      = "10000",
                                City          = user.City,
                                PhoneNo       = "12345678",
                                Email         = user.Email,
                                Date          = DateTime.Now,
                                Username      = user.Username,
                                StatusId      = 0
                            });

                        await onlineOrderProductDAO.CreateChild(new OnlineOrderProduct
                            {
                                ProductId     = Storage[MsgId, 4],
                                OnlineOrderId = orderId,
                                Quantity      = 1
                            });

                        Product buyProduct;
                        using (var productDAO = new ProductDAO())
                        {
                            buyProduct = await productDAO.Read(Storage[MsgId, 4], false);
                        }
                        var mailProductTable = _mailContent.BuyReq.TableRow.
                                               Replace("{0}", buyProduct.Name)
                                               .Replace("{1}", buyProduct.Description)
                                               .Replace("{2}", "1");

                        var mailBody = _mailContent.BuyReq.Body
                                       .Replace("{0}", user.Username)
                                       .Replace("{1}", mailProductTable)
                                       .Replace("{2}", "http://cutieshopapi.azurewebsites.net/verify?id=" + orderId);

                        MailUtils.Send(user.Email, _mailContent.BuyReq.Subject, mailBody);

                        var reply =
                            $"Mail xác nhận đã được gửi đến {user.Email}. Hãy xác nhận qua mail để hoàn tất đặt hàng nhé!";

                        //Send temporary password if customer create new account
                        if (Storage[MsgId, 6, "userPassword"] != null)
                        {
                            reply = $"Password tạm thời của bạn là {Storage[MsgId, 6, "userPassword"]}. Bạn nên vào trang chủ để thay đổi mật khẩu mặc định\n" + reply;
                        }

                        //Remove data in storage
                        Storage.RemoveId(MsgId);

                        return(Receiver.Json(new
                            {
                                speech = reply
                            }));
                    }
                }
            }

                #endregion
            }

            Storage.RemoveId(MsgId);
            throw new UnhandledChatException();
        }
예제 #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string SECURE_SECRET      = OnepayCode.SECURE_SECRET;//Hòa: cần thay bằng mã thật từ app_code
            string hashvalidateResult = "";
            // Khoi tao lop thu vien
            VPCRequest conn = new VPCRequest("http://onepay.vn");

            conn.SetSecureSecret(SECURE_SECRET);
            // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa
            hashvalidateResult = conn.Process3PartyResponse(Request.QueryString);

            // Lay gia tri tham so tra ve tu cong thanh toan
            String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown");
            string amount          = conn.GetResultField("vpc_Amount", "Unknown");
            string localed         = conn.GetResultField("vpc_Locale", "Unknown");
            string command         = conn.GetResultField("vpc_Command", "Unknown");
            string version         = conn.GetResultField("vpc_Version", "Unknown");
            string cardBin         = conn.GetResultField("vpc_Card", "Unknown");
            string orderInfo       = conn.GetResultField("vpc_OrderInfo", "Unknown");
            string merchantID      = conn.GetResultField("vpc_Merchant", "Unknown");
            string authorizeID     = conn.GetResultField("vpc_AuthorizeId", "Unknown");
            string merchTxnRef     = conn.GetResultField("vpc_MerchTxnRef", "Unknown");
            string transactionNo   = conn.GetResultField("vpc_TransactionNo", "Unknown");
            string txnResponseCode = vpc_TxnResponseCode;
            string message         = conn.GetResultField("vpc_Message", "Unknown");

            System.Decimal TongThanhTien = 0;
            String         hoten, sdt, diachi, tinh, quan, maDH, datetime, email;

            DataTable dt = new DataTable();
            DataTable info = new DataTable();

            // Sua lai ham check chuoi ma hoa du lieu
            if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0")
            {
                //vpc_Result.Text = "Transaction was paid successful";
                dt            = (DataTable)Session["GioHang"];
                info          = (DataTable)Session["info"];
                hoten         = info.Rows[0]["hoten"].ToString();
                sdt           = info.Rows[0]["sdt"].ToString();
                maDH          = info.Rows[0]["maDH"].ToString();
                TongThanhTien = int.Parse(info.Rows[0]["TongThanhTien"].ToString());
                datetime      = info.Rows[0]["datetime"].ToString();
                email         = info.Rows[0]["email"].ToString();
                diachi        = info.Rows[0]["diachi"].ToString();

                XuLyDonHang.getDonDatHang(2, sdt, hoten, maDH, TongThanhTien, datetime, dt, email, diachi, 0);

                #region xử lý mail

                string smtpUserName = "******";
                string smtpPassword = "******";
                string smtpHost     = "smtp.gmail.com";
                int    smtpPort     = 25;

                string emailTo = email;
                string subject = "Vương quốc son môi - thanh toán quốc tế";
                string body    = string.Format("Xin chào, " + email + Environment.NewLine +
                                               "\n Số tiền bạn đã thanh toán: " + String.Format("{0:0,00}₫", TongThanhTien) + ":" + Environment.NewLine +
                                               "\n Bạn đã thanh toán đơn hàng bằng hình thức thanh toán quốc tế thành công! Đơn hàng đang chờ được duyệt" + Environment.NewLine +
                                               "\n Cảm ơn bạn đã sử dụng dịch vụ của Vương quốc son môi!" + Environment.NewLine +
                                               "\n Chúc bạn có thêm nhiều niềm vui với bưu phẩm của mình <3");

                MailUtils service = new MailUtils();
                bool      kq      = service.Send(smtpUserName, smtpPassword, smtpHost, smtpPort, emailTo, subject, body);
                #endregion

                Session["Giohang"] = null;
                Session["info"]    = null;
                Response.Write("<div class='result'>Đã thanh toán thành công</div>");
            }
            else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0")
            {
                //vpc_Result.Text = "Transaction is pending";
                //Response.Write("Error description : " + message + "<br/>");
                Response.Write("<div class='result'>Thanh toán đang chờ</div>");
            }
            else
            {
                //vpc_Result.Text = "Transaction was not paid successful";
                //Response.Write("Error description : " + message + "<br/>");
                Response.Write("<div class='result'>Thanh toán không thành công</div>");
            }
        }
예제 #7
0
        public override async Task <IActionResult> Result()
        {
            var currentStep = Storage.GetCurrentStep(MsgId);

            //Switch to next step = currentStep + 1
            switch (currentStep + 1)
            {
                #region step 1
            case 1:
                Storage.AddOrUpdate(MsgId, 1, null);
                using (var petTypeDAO = new PetTypeDAO())
                {
                    var allPetTypes = (await petTypeDAO
                                       .ReadAll(false))
                                      .Select(x => x.Name)
                                      .ToArray();

                    return(Recv.Json(RespObj(RespType.QuickReplies,
                                             "Bạn muốn sản phẩm cho thú cưng nào ạ?", allPetTypes)));
                }

                #endregion
                #region Step 2
            case 2:
                //Check if answer is valid
                if (!_isSkipValidation)
                {
                    using (var petTypeDAO = new PetTypeDAO())
                    {
                        if (await(await petTypeDAO.ReadAll(false))
                            .Select(x => x.Name)
                            .AllAsync(x => x != MsgReply))
                        {
                            _isSkipValidation = true;
                            goto case 1;
                        }
                    }
                }

                Storage.AddOrUpdate(MsgId, 2, null);
                Storage.AddOrUpdate(MsgId, 1, MsgReply);
                return(Recv.Json(RespObj(RespType.QuickReplies, "Bạn muốn mua gì cho bé ạ?",
                                         new[] { "Đồ chơi", "Thức ăn", "Lồng", "phụ kiện" })));

                #endregion
                #region Step 3
            case 3:
                //Check if answer is valid
                // ReSharper disable once InvertIf
                if (!_isSkipValidation)
                {
                    if (new[] { "Đồ chơi", "Thức ăn", "Lồng", "phụ kiện" }.All(x => x != MsgReply))
                    {
                        _isSkipValidation = true;
                        goto case 2;
                    }

                    Storage.AddOrUpdateAndMoveNext(MsgId, MsgReply);
                }

                return(Recv.Json(RespObj(RespType.QuickReplies,
                                         "Bạn có thể cho mình biết mức giá bạn muốn tìm kiếm?",
                                         new[] { "<100000", "100000 - 300000", ">300000 - 500000", ">500000" })));

                #endregion
                #region Step 4
            case 4:
                //Check if answer is valid
                if (!_isSkipValidation)
                {
                    if (new[] { "<100000", "100000 - 300000", ">300000 - 500000", ">500000" }.All(x => x != MsgReply))
                    {
                        _isSkipValidation = true;
                        goto case 3;
                    }

                    Storage.AddOrUpdateAndMoveNext(MsgId, MsgReply);
                }

                //Find minimum and maximum price from step 3
                int minimumPrice, maximumPrice;

                switch (Storage[MsgId, 3])
                {
                case "<100000":
                    minimumPrice = 0;
                    maximumPrice = 99999;
                    break;

                case "100000 - 300000":
                    minimumPrice = 100000;
                    maximumPrice = 300000;
                    break;

                case ">300000 - 500000":
                    minimumPrice = 300001;
                    maximumPrice = 500000;
                    break;

                default:
                    minimumPrice = 500001;
                    maximumPrice = int.MaxValue;
                    break;
                }

                //Find product in step 2, for pet in step 1
                return(await MessengerProductListResult(GetProductType(), minimumPrice, maximumPrice));

                #endregion
                #region Step 5
            case 5:
                //Check if answer is valid
                if (!_isSkipValidation)
                {
                    using (var productDAO = new ProductDAO())
                        if (await productDAO.Read(MsgQuery, false) == null)
                        {
                            _isSkipValidation = true;
                            goto case 4;
                        }
                }

                Storage.AddOrUpdateAndMoveNext(MsgId, MsgQuery);

                return(Recv.Json(RespObj(RespType.Text, "Vui lòng nhập số lượng sản phẩm bạn muốn mua")));

                #endregion
                #region Step 6
            case 6:
                if (!int.TryParse(MsgReply, out var res) || res < 1)
                {
                    return(Recv.Json(RespObj(RespType.Text,
                                             "Số lượng nhập vào không hợp lệ. Vui lòng nhập lại")));
                }

                Storage.AddOrUpdateAndMoveNext(MsgId, MsgQuery);

                return(Recv.Json(MultiResp(RespObj(RespType.Text,
                                                   "Bạn có thể cho mình biết tên đăng nhập trên hệ thống Cutieshop được không ạ?\nNếu chưa có, bạn có thể gõ tên đăng nhập mới để chúng mình tạo tài khoản cho bạn"),
                                           RespUndo())));

                #endregion
                #region Step 7
            case 7:
                if (_isUndoRequested && Storage[MsgId, 6] == null)
                {
                    Storage.StepBack(MsgId);
                    return(Recv.Json(RespObj(RespType.Text, "Vui lòng nhập số lượng sản phẩm bạn muốn mua")));
                }

                //This step receive username first, then the email and address. So we need to keep the username to the storage for further uses, email will be used once in this step and can be queried by DAO easily in the future.
                //Checking null will prevent email from being overwritten to username in Storage

                if (Storage[MsgId, 6] == null)
                {
                    if (!MsgReply.IsPureAscii() || MsgReply.Contains(' '))
                    {
                        return(Recv.Json(RespObj(RespType.Text, "Vui lòng nhập tên đăng nhập hợp lệ (không dấu, khoảng cách)")));
                    }
                    Storage.AddOrUpdate(MsgId, 6, MsgReply);
                }

                using (var userDAO = new UserDAO())
                {
                    var user = await userDAO.ReadChild(Storage[MsgId, 6], true);

                    //If user is null, create a user, then ask customer their email
                    if (user == null)
                    {
                        Storage.AddOrUpdate(MsgId, 7, "userPassword", NewGuid().ToString().Substring(0, 6));
                        await userDAO.Create(new Auth
                        {
                            Username = Storage[MsgId, 6],
                            Password = Storage[MsgId, 7, "userPassword"]
                        });

                        await userDAO.CreateChild(new User
                        {
                            Username = Storage[MsgId, 6],
                            Email    = string.Empty,
                            Address  = string.Empty
                        });

                        await userDAO.Context.SaveChangesAsync();
                    }

                    user = await userDAO.ReadChild(Storage[MsgId, 6], true);

                    if (Storage[MsgId, 7, "fullName"] == null)
                    {
                        if (Storage[MsgId, 7, "isAskFullName"] == null)
                        {
                            Storage.AddOrUpdate(MsgId, 7, "isAskFullName", "1");
                            return(Recv.Json(RespObj(RespType.Text, "Cho mình xin họ tên người nhận hàng?")));
                        }

                        if (MsgReply.Trim().Count(x => x == ' ') == 0)
                        {
                            return(Recv.Json(RespObj(RespType.Text, "Vui lòng nhập đầy đủ họ tên")));
                        }

                        Storage.AddOrUpdate(MsgId, 7, "fullName", MsgReply);
                    }

                    //If email is empty, ask for email
                    if (user.Email == string.Empty)
                    {
                        if (Storage[MsgId, 7, "isAskForEmail"] == null)
                        {
                            Storage.AddOrUpdate(MsgId, 7, "isAskForEmail", "1");
                            return(Recv.Json(MultiResp(
                                                 RespObj(RespType.Text, "Bạn hãy cho mình biết email nhé"), RespUndo())));
                        }

                        //Undo handling
                        if (_isUndoRequested)
                        {
                            Storage.AddOrUpdate(MsgId, 7, "fullName", null);
                            Storage.AddOrUpdate(MsgId, 7, "isAskForEmail", null);
                            return(Recv.Json(RespObj(RespType.Text, "Cho mình xin họ tên người nhận hàng?")));
                        }

                        //Validate email
                        if (!MsgReply.IsEmail())
                        {
                            return(Recv.Json(MultiResp(RespObj(RespType.Text, "Email không hợp lệ\nVui lòng nhập lại email"), RespUndo())));
                        }

                        user.Email = MsgReply;
                        await userDAO.Context.SaveChangesAsync();
                    }

                    if (Storage[MsgId, 7, "phoneNo"] == null)
                    {
                        if (Storage[MsgId, 7, "isAskForPhoneNo"] == null)
                        {
                            Storage.AddOrUpdate(MsgId, 7, "isAskForPhoneNo", "1");
                            return(Recv.Json(MultiResp(
                                                 RespObj(RespType.Text, "Bạn cho mình xin số điện thoại ạ"), RespUndo())));
                        }

                        if (_isUndoRequested)
                        {
                            Storage.AddOrUpdate(MsgId, 7, "isAskForPhoneNo", null);

                            if (Storage[MsgId, 7, "isAskForEmail"] != null)
                            {
                                user.Email = "";
                                await userDAO.Context.SaveChangesAsync();

                                return(Recv.Json(MultiResp(RespObj(RespType.Text, "Bạn hãy cho mình biết email nhé"), RespUndo())));
                            }

                            Storage.AddOrUpdate(MsgId, 7, "fullName", null);
                            return(Recv.Json(RespObj(RespType.Text, "Cho mình xin họ tên người nhận hàng?")));
                        }

                        if (Storage[MsgId, 7, "isAskForPhoneNo"] == "1")
                        {
                            Storage.AddOrUpdate(MsgId, 7, "phoneNo", MsgReply);
                        }
                    }

                    if (_isUndoRequested)
                    {
                        user.Address = "";
                        await userDAO.Context.SaveChangesAsync();

                        Storage.AddOrUpdate(MsgId, 7, "phoneNo", null);
                        Storage.AddOrUpdate(MsgId, 7, "isAskForAddress", null);
                        return(Recv.Json(MultiResp(RespObj(RespType.Text, "Bạn cho mình xin số điện thoại ạ"), RespUndo())));
                    }

                    if (user.Address == string.Empty)
                    {
                        if (Storage[MsgId, 7, "isAskForAddress"] == null)
                        {
                            Storage.AddOrUpdate(MsgId, 7, "isAskForAddress", "1");
                            return(Recv.Json(MultiResp(RespObj(RespType.Text, "Bạn cho mình xin địa chỉ"), RespUndo())));
                        }

                        user.Address = MsgReply;
                        await userDAO.Context.SaveChangesAsync();
                    }

                    //Ready to jump into step 8 (if exists) after this
                    Storage.AddOrUpdate(MsgId, 7, null);

                    using (var orderDAO = new OnlineOrderProductDAO(userDAO.Context))
                    {
                        var orderId = NewGuid().ToString();
                        await orderDAO.Create(orderId, Storage[MsgId, 7, "fullName"], user.Address, "10000", user.City, Storage[MsgId, 7, "phoneNo"], user.Email, user.Username, 0);

                        await orderDAO.CreateChild(Storage[MsgId, 4], orderId, int.Parse(Storage[MsgId, 5]));

                        Product buyProd;
                        using (var prdctDAO = new ProductDAO())
                            buyProd = await prdctDAO.Read(Storage[MsgId, 4], false);

                        var mailPrdctTbl = _mailContent.BuyReq.TableRow
                                           .MultiReplace(("{0}", buyProd.Name), ("{1}", buyProd.Description), ("{2}", Storage[MsgId, 5]));

                        var mailBody = _mailContent.BuyReq.Body
                                       .MultiReplace(
                            ("{0}", user.Username),
                            ("{1}", mailPrdctTbl),
                            ("{2}", orderId),
                            ("{3}", (buyProd.Price * int.Parse(Storage[MsgId, 5])).ToString()));

                        MailUtils.Send(user.Email, _mailContent.BuyReq.Subject, mailBody);

                        var reply = $"Mail xác nhận đã được gửi đến {user.Email}. Hãy xác nhận qua mail để hoàn tất đặt hàng nhé!";

                        //Send temporary password if customer create new account
                        if (Storage[MsgId, 7, "userPassword"] != null)
                        {
                            reply = $"Password tạm thời của bạn là {Storage[MsgId, 7, "userPassword"]}. Bạn nên vào trang chủ để thay đổi mật khẩu mặc định\n" + reply;
                        }

                        //Remove data in storage
                        Storage.RemoveId(MsgId);
                        return(Recv.Json(RespObj(RespType.Text, reply)));
                    }
                }
                #endregion
            }

            Storage.RemoveId(MsgId);
            throw new UnhandledChatException();
        }