コード例 #1
0
        public ActionResult Registor()
        {
            var Thangs = new SelectList(
                new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Tháng một", Value = "1"
                },
                new SelectListItem {
                    Text = "Tháng hai", Value = "2"
                },
                new SelectListItem {
                    Text = "Tháng ba", Value = "3"
                },
                new SelectListItem {
                    Text = "Tháng bốn", Value = "4"
                },
                new SelectListItem {
                    Text = "Tháng năm", Value = "5"
                },
                new SelectListItem {
                    Text = "Tháng sáu", Value = "6"
                },
                new SelectListItem {
                    Text = "Tháng bảy", Value = "7"
                },
                new SelectListItem {
                    Text = "Tháng tám", Value = "8"
                },
                new SelectListItem {
                    Text = "Tháng chín", Value = "9"
                },
                new SelectListItem {
                    Text = "Tháng mười", Value = "10"
                },
                new SelectListItem {
                    Text = "Tháng mười một", Value = "11"
                },
                new SelectListItem {
                    Text = "Tháng mười hai", Value = "12"
                }
            }, "Value", "Text");

            ViewBag.Ngay  = DayMonthYear.GetNgays();
            ViewBag.Thang = Thangs;
            ViewBag.Nam   = DayMonthYear.GetNams();

            var Customer = new Customer();

            return(View(Customer));
        }
コード例 #2
0
        public ActionResult Registor(Customer customer)
        {
            KHACHHANG KhachHang  = new KHACHHANG();
            var       CheckEmail = db.KHACHHANGs.Where(x => x.Email == customer.Email).ToList();
            var       CheckPhone = db.KHACHHANGs.Where(x => x.SoDienThoai == customer.SoDienThoai).ToList();

            if (ModelState.IsValid)
            {
                if (CheckEmail.Count > 0)
                {
                    ModelState.AddModelError("Email", "Email của bạn đã tồn tại");
                }

                if (CheckPhone.Count > 0)
                {
                    ModelState.AddModelError("SoDienThoai", "Số điện thoại  của bạn tồn tại");
                }

                if (CheckEmail.Count == 0 && CheckPhone.Count == 0)
                {
                    var ngay  = customer.Ngay.ToString();
                    var thang = customer.Thang.ToString();
                    if (customer.Ngay < 10)
                    {
                        ngay = '0' + customer.Ngay.ToString();
                    }
                    if (customer.Thang < 10)
                    {
                        thang = '0' + customer.Thang.ToString();
                    }

                    var thoigian = ngay + "/" + thang + "/" + customer.Nam;
                    KhachHang = new KHACHHANG
                    {
                        TenKhachHang     = customer.TenKhachHang,
                        DiaChi           = customer.DiaChi,
                        SoDienThoai      = customer.SoDienThoai,
                        Email            = customer.Email,
                        PassWord         = Helper.GenHash.GenSHA1(customer.PassWord),
                        Id_LoaiKhachHang = 2
                    };

                    if (thoigian != " ")
                    {
                        KhachHang.NgaySinh = DateTime.ParseExact(thoigian, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                    }
                    // tổng chi +1,
                    // dfsdfsd

                    var aNewKhachHang = db.KHACHHANGs.Add(KhachHang);
                    KhachHang.Id_KhachHang = aNewKhachHang.Id_KhachHang;

                    DIACHI DiaChi = new DIACHI()
                    {
                        Id_KhachHang = aNewKhachHang.Id_KhachHang,
                        SoDienThoai  = aNewKhachHang.SoDienThoai,
                        TenKhachHang = aNewKhachHang.TenKhachHang,
                        DiaChi       = aNewKhachHang.DiaChi,
                        TrangThai    = true
                    };

                    db.DIACHIs.Add(DiaChi);
                    db.SaveChanges();


                    return(RedirectToAction("Index", "Homepage"));
                }
            }

            var Thangs = new SelectList(
                new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Tháng một", Value = "1"
                },
                new SelectListItem {
                    Text = "Tháng hai", Value = "2"
                },
                new SelectListItem {
                    Text = "Tháng ba", Value = "3"
                },
                new SelectListItem {
                    Text = "Tháng bốn", Value = "4"
                },
                new SelectListItem {
                    Text = "Tháng năm", Value = "5"
                },
                new SelectListItem {
                    Text = "Tháng sáu", Value = "6"
                },
                new SelectListItem {
                    Text = "Tháng bảy", Value = "7"
                },
                new SelectListItem {
                    Text = "Tháng tám", Value = "8"
                },
                new SelectListItem {
                    Text = "Tháng chín", Value = "9"
                },
                new SelectListItem {
                    Text = "Tháng mười", Value = "10"
                },
                new SelectListItem {
                    Text = "Tháng một", Value = "11"
                },
                new SelectListItem {
                    Text = "Tháng hai", Value = "12"
                }
            }, "Value", "Text");

            ViewBag.Ngay  = DayMonthYear.GetNgays();
            ViewBag.Thang = Thangs;
            ViewBag.Nam   = DayMonthYear.GetNams();

            return(View(customer));
        }