Exemple #1
0
        public PartialViewResult EditSize(string SizeGuid, string SectionGuid, string ProductGuid)
        {
            shSizeService _size = new shSizeService();
            shSetSize     size  = _size.FindByKey(SizeGuid);

            if (size == null)
            {
                size = new shSetSize();
            }

            shSectionService           _section  = new shSectionService();
            IEnumerable <shProductSet> dsSection = _section.DanhSachSection_TheoProductGuid(ProductGuid);

            ViewBag.SectionGuid = new SelectList(dsSection, "SectionGuid", "SectionName", SectionGuid);

            IEnumerable <shSetSize> dsSize = _size.DanhSachSize_BySectionGuid(null, ProductGuid, null)
                                             .Where(x => string.IsNullOrWhiteSpace(x.ParentId) ||
                                                    string.IsNullOrEmpty(x.ParentId));

            foreach (var item in dsSize)
            {
                item.SizeName = _section.SectionName(item.SectionGuid) + " - " + item.SizeName;
            }
            ViewBag.Parent = new SelectList(dsSize, "SizeGuid", "SizeName", size.ParentId);
            //size.PriceCurrent = Format.SubStringDotInDecimal(size.PriceCurrent.Value);

            return(PartialView("EditSize", size));
        }
Exemple #2
0
        public static decimal ListProductPrice_Quantity(List <CartItem> ds, decimal MatHangGiamGia, decimal DiemThuong, decimal PhiGiaoHang)
        {
            shSizeService _size = new shSizeService();
            decimal       price = _size.ListProductPrice_Quantity(ds, MatHangGiamGia, DiemThuong, PhiGiaoHang);

            return(price);
        }
Exemple #3
0
        public static MvcHtmlString ChatLieu_KichThuoc(this HtmlHelper helper, string SizeGuid, string SizeName, string Stuff, string ParentId, string SectionGuid)
        {
            string html = string.Empty;

            if (!string.IsNullOrWhiteSpace(SizeName))
            {
                html += SizeName;
            }

            if (!string.IsNullOrWhiteSpace(Stuff))
            {
                html += " - " + Stuff;
            }
            string title = string.Empty;
            string style = string.Empty;

            if (!string.IsNullOrWhiteSpace(ParentId))
            {
                shSectionService _section = new shSectionService();
                shSizeService    _size    = new shSizeService();
                shSetSize        size     = _size.FindByKey(ParentId);
                if (size != null)
                {
                    title = "Thuộc bộ sản phẩm: " + _section.SectionName(SectionGuid) + " [" + size.SizeName + "]";
                }
            }
            else
            {
                style = "font-weight:bold; cursor: pointer";
            }
            string span = "<span title='" + title + "' style='" + style + "' class='parent-size'>" + html + "</span>";

            return(new MvcHtmlString(span));
        }
        public ActionResult SizeGuid(string ProductGuid, string SectionGuid, string SizeGuid)
        {
            if (string.IsNullOrWhiteSpace(SectionGuid) || string.IsNullOrEmpty(SectionGuid))
            {
                shSectionService _section = new shSectionService();

                IEnumerable <shProductSet> ds = _section.DanhSachSection_TheoProductGuid_ParentNull(ProductGuid);

                if (ds != null && ds.Count() > 0)
                {
                    SectionGuid = ds.FirstOrDefault().SectionGuid;
                }
            }

            shSizeService           _size  = new shSizeService();
            IEnumerable <shSetSize> dsSize = _size.DanhSachSize_BySectionGuid(SectionGuid, ProductGuid, null);

            foreach (var size in dsSize)
            {
                size.SizeName += " - " + Format.FormatDecimalToString(size.PriceCurrent.GetValueOrDefault(0)).Replace(',', '.');
            }
            SelectList select = new SelectList(dsSize, "SizeGuid", "SizeName", SizeGuid);

            return(PartialView("SizeGuid", select));
        }
Exemple #5
0
        public static MvcHtmlString ProductPrice_Quantity(this HtmlHelper helper, string SizeGuid, int Quantity)
        {
            shSizeService _size = new shSizeService();

            decimal price = _size.ProductSize_Quantity(SizeGuid, Quantity);

            return(new MvcHtmlString(Format.FormatDecimalToString(price)));
        }
        public PartialViewResult dsSize(string ProductGuid)
        {
            shSizeService _size = new shSizeService();

            IEnumerable <shSetSize> dsSize = _size.DanhSachSection_Size(ProductGuid);

            return(PartialView("dsSize", dsSize));
        }
        public ActionResult dsNhap2(string ReceiptIsuueGuid, string SizeGuid, int?Number, string SizeAdd)
        {
            shGoodReceiptIsuueDetailService _goodDetail = new shGoodReceiptIsuueDetailService();
            List <shGoodReceiptIsuueDetail> dsNhap      = new List <shGoodReceiptIsuueDetail>();

            shSizeService _size = new shSizeService();
            shSetSize     size  = new shSetSize();

            if (!string.IsNullOrEmpty(SizeAdd) || !string.IsNullOrWhiteSpace(SizeAdd))
            {
                string[] dsSizeAdd = SizeAdd.Split(';');

                foreach (var childSize in dsSizeAdd)
                {
                    string[] obj = childSize.Split('$');

                    if (obj != null)
                    {
                        size = _size.FindByKey(obj[0]);
                        if (size != null)
                        {
                            dsNhap.Add(new shGoodReceiptIsuueDetail
                            {
                                ReceiptIsuueDetailGuid = obj[2],
                                ReceiptIsuueGuid       = ReceiptIsuueGuid,
                                ProductGuid            = size.ProductGuid,
                                SectionGuid            = size.SectionGuid,
                                SizeGuid = size.SizeGuid,
                                Number   = TypeHelper.ToInt32(obj[1]),
                            });
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(SizeGuid) || !string.IsNullOrWhiteSpace(SizeGuid))
            {
                size = _size.FindByKey(SizeGuid);
                dsNhap.Add(new shGoodReceiptIsuueDetail
                {
                    // ReceiptIsuueDetailGuid = GuidUnique.getInstance().GenerateUnique(),
                    ReceiptIsuueGuid = ReceiptIsuueGuid,
                    ProductGuid      = size.ProductGuid,
                    SectionGuid      = size.SectionGuid,
                    SizeGuid         = size.SizeGuid,
                    Number           = Number,
                });

                SizeAdd += SizeGuid + "$" + Number + "$" + "" + ";";
            }

            ViewBag.ReceiptIsuueGuid = ReceiptIsuueGuid;
            ViewBag.dsNhap           = dsNhap;

            ViewBag.SizeAdd = SizeAdd;

            return(PartialView("dsNhap", dsNhap));
        }
Exemple #8
0
        public PartialViewResult DsChildSize(string SizeGuid)
        {
            shSizeService    _size    = new shSizeService();
            shSectionService _section = new shSectionService();

            IEnumerable <shSetSize> ListSize = _size.DanhSachSize_ByParent(SizeGuid);

            return(PartialView("DsChildSize", ListSize));
        }
        public ActionResult SizeGuid(string ProductGuid)
        {
            shSizeService _size = new shSizeService();

            IEnumerable <shSetSize> dsSize = _size.DanhSachSection_Size(ProductGuid);

            ViewBag.SizeGuid = new SelectList(dsSize, "SizeGuid", "SizeName", null);

            return(PartialView("SizeGuid", ViewBag.SizeGuid));
        }
Exemple #10
0
        public static MvcHtmlString SoLuongSanPham(this HtmlHelper helper, string ProductGuid)
        {
            shSizeService           _size  = new shSizeService();
            IEnumerable <shSetSize> dsSize = _size.DanhSachSize_BySectionGuid_ParentNull(null, ProductGuid, null);
            int SoLuong = 0;

            foreach (var size in dsSize)
            {
                SoLuong += size.Number.GetValueOrDefault(0);
            }
            return(new MvcHtmlString(SoLuong.ToString()));
        }
Exemple #11
0
        public static MvcHtmlString SizeName(this HtmlHelper helper, string SizeGuid)
        {
            shSizeService _size = new shSizeService();

            shSetSize size = _size.FindByKey(SizeGuid);

            if (size == null)
            {
                size = new shSetSize();
            }
            return(new MvcHtmlString(size.SizeName));
        }
Exemple #12
0
        public ActionResult EditSize(string SizeGuid, string ProductGuid, string SectionGuid, string SizeName, decimal?PriceCurrent, string Stuff, string Parent)
        {
            shSizeService _size = new shSizeService();
            shSetSize     size  = new shSetSize();

            using (var context = new ShopOnlineDb())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        size = _size.InsertUpdateSize(
                            SizeGuid,
                            null,
                            ProductGuid,
                            SectionGuid,
                            SizeName,
                            null,
                            PriceCurrent,
                            null,
                            null,
                            null,
                            null,
                            null,
                            true,
                            DateTime.Now,
                            Stuff,
                            Parent);

                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }


            if (Request.IsAjaxRequest())
            {
                string data = "fail";
                if (size.SizeId > 0)
                {
                    data = "ok";
                }

                return(Json(data, JsonRequestBehavior.AllowGet));
            }

            return(RedirectToAction("Index"));
        }
Exemple #13
0
        public ActionResult DeleteSize(string SizeGuid, string SectionGuid, string ProductGuid)
        {
            shSizeService _size = new shSizeService();

            _size.Delete(SizeGuid);

            if (Request.IsAjaxRequest())
            {
                return(Json("OK", JsonRequestBehavior.AllowGet));
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult dsNhap(string ReceiptIsuueGuid)
        {
            shGoodReceiptIsuueDetailService _goodDetail = new shGoodReceiptIsuueDetailService();
            List <shGoodReceiptIsuueDetail> dsNhap      = _goodDetail.DanhSachPhieuXuatNhap_ByParent(ReceiptIsuueGuid).ToList();

            if (dsNhap == null)
            {
                dsNhap = new List <shGoodReceiptIsuueDetail>();
            }
            shSizeService _size = new shSizeService();

            ViewBag.ReceiptIsuueGuid = ReceiptIsuueGuid;
            ViewBag.dsNhap           = dsNhap;

            return(PartialView("dsNhap", dsNhap));
        }
        public void LoadDuLieu()
        {
            shOrderService _order = new shOrderService();

            @ViewBag.DonHang          = _order.SoDonHangTrongNgay(DateTime.Now);
            @ViewBag.DoanhThuTheoNgay = Format.FormatDecimalToString(_order.DoanhThuTheoNgay(DateTime.Now));

            shMemberService _member = new shMemberService();

            @ViewBag.NewMember = _member.DanhSachMemberDangKyMoi();

            shProductService _product = new shProductService();
            shSectionService _section = new shSectionService();
            shSizeService    _size    = new shSizeService();

            @ViewBag.SoLuongTon = _size.SoLuongTonSetSize();
        }
Exemple #16
0
        public static MvcHtmlString SizeNameByParentId_SectionGuid(this HtmlHelper helper, string ParentId, string SectionGuid)
        {
            shSizeService _size = new shSizeService();
            shSetSize     size  = _size.DanhSachSize()
                                  .Where(x => x.ParentId == ParentId &&
                                         x.SectionGuid == SectionGuid)
                                  .FirstOrDefault();

            string html = string.Empty;

            if (size != null && !string.IsNullOrEmpty(size.SizeName) && !string.IsNullOrWhiteSpace(size.SizeName))
            {
                html = size.SizeName;
            }

            return(new MvcHtmlString(html));
        }
Exemple #17
0
        public static MvcHtmlString SizeNameByParentId_SectionGuid_PriceCurrent(this HtmlHelper helper, string ParentId, string SectionGuid)
        {
            shSizeService _size = new shSizeService();
            shSetSize     size  = _size.DanhSachSize()
                                  .Where(x => x.ParentId == ParentId &&
                                         x.SectionGuid == SectionGuid)
                                  .FirstOrDefault();

            string html = string.Empty;

            if (size != null && !string.IsNullOrEmpty(size.SizeName) && !string.IsNullOrWhiteSpace(size.SizeName))
            {
                html = Format.FormatDecimalToString(size.PriceCurrent.GetValueOrDefault(0)).Replace(',', '.');
            }

            return(new MvcHtmlString(html));
        }
        public ActionResult Details(int?id)
        {
            shProductService _product = new shProductService();

            shProduct product = _product.FindList().Where(x => x.ProductId == id).FirstOrDefault();

            shProductImageService        _productImage = new shProductImageService();
            IEnumerable <shProductImage> dsImage       = _productImage.DanhSachProductImage_ByProductGuid(product.ProductGuid);

            ViewBag.dsImageMauMa    = dsImage.Where(x => x.ProductImageCategory == Config.ProductImageCategory_Design);
            ViewBag.dsImageChatLieu = dsImage.Where(x => x.ProductImageCategory == Config.ProductImageCategory_Material);


            shSectionService           _section  = new shSectionService();
            IEnumerable <shProductSet> dsSection = _section.DanhSachSection_TheoProductGuid_ParentNull(product.ProductGuid);


            shProductSet section = new shProductSet();

            if (dsSection != null && dsSection.Count() > 0)
            {
                section = dsSection.FirstOrDefault();
            }

            shSizeService           _size  = new shSizeService();
            IEnumerable <shSetSize> dsSize = _size.DanhSachSize_BySectionGuid(section.SectionGuid, product.ProductGuid, null);


            ViewBag.ProductSize = section.SectionName + " --- " +
                                  CommonHelper.TinhToanKichThuocMaxMin(dsSize.FirstOrDefault(), dsSize.LastOrDefault());
            ViewBag.ProductPrice = CommonHelper.TinhToanGiaTienMaxMin(dsSize.FirstOrDefault(), dsSize.LastOrDefault());

            // Tính toán số tiền sau khuyến mại
            string productSale = CommonHelper.TinhToanGiaTienSauKhiGiam(dsSize.FirstOrDefault(), dsSize.LastOrDefault());

            if (!string.IsNullOrEmpty(productSale) && !string.IsNullOrWhiteSpace(productSale))
            {
                ViewBag.ProductSale = Format.FormatDecimalToString(Convert.ToDecimal(productSale));
            }


            ViewBag.ListSection = dsSection;

            return(View(product));
        }
Exemple #19
0
        public PartialViewResult ListSize(string ProductGuid, string SectionGuid, int?page, string SizeGuid, int?p)
        {
            int pageCurrent = 1;

            if (page.HasValue)
            {
                pageCurrent = page.Value;
            }

            shSizeService    _size    = new shSizeService();
            shSectionService _section = new shSectionService();

            IEnumerable <shSetSize> ListSize = _size.DanhSachSize_BySectionGuid_ParentNull(SectionGuid, ProductGuid, SizeGuid);

            IPagedList <shSetSize> dsSize = ListSize.OrderBy(x => x.SizeId).ToPagedList(pageCurrent, Config.PAGE_SIZE_20);

            ViewBag.ListSize = dsSize;
            ViewBag.p        = p;
            return(PartialView("ListSize", dsSize));
        }
Exemple #20
0
        public static MvcHtmlString SectionName_SizeName(this HtmlHelper helper, string SectionGuid, string SizeGuid)
        {
            string           html     = string.Empty;
            shSectionService _section = new shSectionService();
            shProductSet     section  = _section.FindByKey(SectionGuid);

            if (section != null)
            {
                html += section.SectionName;
            }

            shSizeService _size = new shSizeService();
            shSetSize     size  = _size.FindByKey(SizeGuid);

            if (size != null)
            {
                html += "    " + size.SizeName + "    " + size.Stuff;
            }
            return(new MvcHtmlString(html));
        }
Exemple #21
0
        public static MvcHtmlString IconUpdate_Delete(this HtmlHelper helper, string SizeGuid)
        {
            shSizeService _size = new shSizeService();
            shSetSize     size  = _size.FindByKey(SizeGuid);

            if (size == null)
            {
                size = new shSetSize();
            }

            string icon = "<a href='javascript:void(0)' onclick=Edit('" + SizeGuid + "','" + size.SectionGuid + "')>" +
                          "<span class='fa fa-pencil-square-o' aria-hidden='true' style='transform: scale(1.3, 1.3);' title='Sửa'></span>" +
                          "</a>";

            icon += "&nbsp;&nbsp;";

            icon += "<a href='javascript:void(0)' onclick=Delete('" + SizeGuid + "','" + size.SectionGuid + "')>" +
                    "<span class='fa fa-trash' aria-hidden='true' style='transform: scale(1.3, 1.3);' title='Xóa'></span> " +
                    "</a>";

            return(new MvcHtmlString(icon));
        }
Exemple #22
0
        public static string NoiDungDonHang(shOrder order, List <CartItem> cart)
        {
            shSectionService _section = new shSectionService();
            shSizeService    _size    = new shSizeService();
            string           noidung  = string.Empty;

            noidung += "<p content-attach> <i>Thông tin người nhận hàng: " + "</i> ";
            noidung += order.FullName;
            if (string.IsNullOrWhiteSpace(order.Phone))
            {
                noidung += " / " + order.Phone;
            }
            if (string.IsNullOrWhiteSpace(order.Email))
            {
                noidung += " / " + order.Email;
            }
            if (string.IsNullOrWhiteSpace(order.Address))
            {
                noidung += " / " + order.Address;
            }
            noidung += " </p>";

            noidung += "<p content-attach><i>Giá trị đơn hàng: " + Format.FormatDecimalToString(order.Total.GetValueOrDefault(0)) + "</i></p>";
            noidung += "<p content-attach><i>Phí ship: " + Format.FormatDecimalToString(order.FeeShip.GetValueOrDefault(0)) + "</i></p>";
            noidung += "<p content-attach><i>Ngày đặt: " + order.NgayDat.GetValueOrDefault(DateTime.Now).ToString("dd/MM/yyyy") + "</i></p>";

            noidung += "<p content-attach><i>Thông tin đơn hàng: ";

            foreach (var item in cart)
            {
                noidung += "<p>" + item.Product.ProductName;
                noidung += _section.SectionName(item.SectionGuid);
                noidung += _size.SizeName(item.SizeGuid) + "</p>";
            }

            noidung += "</i></p>";

            return(noidung);
        }
        public ActionResult XoaSanPhamDaChon(string ReceiptIsuueGuid, string SizeGuid, string SizeAdd)
        {
            string dsSize = string.Empty;
            List <shGoodReceiptIsuueDetail> dsNhap = new List <shGoodReceiptIsuueDetail>();
            shSizeService _size = new shSizeService();
            shSetSize     size  = new shSetSize();

            if (!string.IsNullOrEmpty(SizeAdd) || !string.IsNullOrWhiteSpace(SizeAdd))
            {
                string[] dsSizeAdd = SizeAdd.Split(';');

                foreach (var childSize in dsSizeAdd)
                {
                    string[] obj = childSize.Split('$');

                    if (obj != null && obj[0] != "" && obj[0] != null && obj[0] != SizeGuid)
                    {
                        dsSize += obj[0] + "$" + obj[1] + "$" + obj[2] + "$" + ";";
                    }
                }
            }

            return(dsNhap2(ReceiptIsuueGuid, null, null, dsSize));
        }
Exemple #24
0
        public ActionResult CheckOrderProcessing(string OrderGuid, int?OrderStatus, string Description)
        {
            shOrderService _order = new shOrderService();
            shOrder        order  = _order.FindByKey(OrderGuid);

            string message = "OK";

            shOrderDetailService        _orderdetail = new shOrderDetailService();
            IEnumerable <shOrderDetail> ds           = _orderdetail.DanhSachOrderDetailBy(order.OrderGuid, order.MemberGuid, null);

            bool          check = false;
            shSizeService _size = new shSizeService();
            shSetSize     size  = new shSetSize();

            foreach (var item in ds)
            {
                size = _size.FindByKey(item.SizeGuid);

                if (item.Number > size.Inventory)
                {
                    check = true;
                }
            }

            if (check)
            {
                message = "Số lượng hàng tồn trong kho không đủ. Xin vui lòng thao tác lại";
            }

            if (Request.IsAjaxRequest())
            {
                return(Json(message, JsonRequestBehavior.AllowGet));
            }

            return(RedirectToAction("Index"));
        }
Exemple #25
0
        public List <TreeView> GetProductTreeview(bool isSection, string ProductGuid)
        {
            shSectionService _section = new shSectionService();
            shSizeService    _size    = new shSizeService();

            IEnumerable <shProductSet> dsSection = _section.DanhSachSection().Where(x => x.ProductGuid == ProductGuid && string.IsNullOrWhiteSpace(x.ParentId));

            List <TreeView> dsTreeview = new List <TreeView>();
            TreeView        zTree      = null;
            TreeView        childZtree = null;

            foreach (var section in dsSection)
            {
                // cấp sản phẩm nhỏ
                zTree          = new TreeView();
                zTree.isParent = true;
                zTree.id       = section.SectionGuid;
                zTree.pId      = section.ProductGuid;

                List <TreeView> dsChildTreeview = null;

                //IEnumerable<shSize> dsChildSize = _size.DanhSachSize_BySectionGuid(section.SectionGuid, null, null);

                IEnumerable <shProductSet> dsChildSection = _section.DanhSachSection().Where(x => x.ParentId == section.SectionGuid).OrderBy(x => x.SortOrder);

                if (dsChildSection.Count() > 0)
                {
                    dsChildTreeview = new List <TreeView>();

                    foreach (var childSection in dsChildSection)
                    {
                        // Cấp kích thước + Giá tiền
                        childZtree      = new TreeView();
                        childZtree.id   = childSection.SectionGuid;
                        childZtree.pId  = childSection.ParentId;
                        childZtree.name = childSection.SectionName;

                        childZtree.isParent = false;
                        childZtree.children = null;
                        childZtree.click    = "shProduct('' , '" + childSection.SectionGuid + "', '', '1')";

                        dsChildTreeview.Add(childZtree);
                    }

                    zTree.children = dsChildTreeview;
                    zTree.open     = true;
                    zTree.click    = "shProduct('', '" + section.SectionGuid + "', '', '1')";
                    zTree.name     = section.SectionName + "[" + dsChildSection.Count() + "]";
                }
                else
                {
                    // Chưa có Kích Thước
                    zTree.click = "shProduct('' , '" + section.SectionGuid + "', '', '1')";
                    zTree.open  = false;
                    zTree.name  = section.SectionName;
                }
                //zTree.name += "<a href='javascript:void(0)' onclick='Edit()'>" +
                //              "<span class='fa fa-pencil-square-o' style='transform: scale(1.3, 1.3);' title='Sửa'>" +
                //              "</span></a>";
                dsTreeview.Add(zTree);
            }

            return(dsTreeview);
        }
Exemple #26
0
        public ActionResult Order(int?p, int?pay_type, string City, string Town, string order_name, string order_address, string order_phone, string order_email, string base_remark)
        {
            using (var context = new ShopOnlineDb())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        #region Get Infor login
                        string MemberGuid   = string.Empty;
                        bool   isCoTaiKhoan = false;

                        if (string.IsNullOrEmpty(User.Identity.GetMemberLogin().MemberGuid) ||
                            string.IsNullOrWhiteSpace(User.Identity.GetMemberLogin().MemberGuid))
                        {
                            //return Redirect("/dang-nhap?urlPrefix=/gio-hang");
                            isCoTaiKhoan = false;
                        }
                        else
                        {
                            isCoTaiKhoan = true;
                            MemberGuid   = User.Identity.GetMemberLogin().MemberGuid;
                        }

                        var cart = Session[CartSession];
                        if (cart == null)
                        {
                            TempData["Cart"] = "Giỏ hàng trống. Vui lòng thao tác lại.";
                            return(Redirect("/gio-hang"));
                        }

                        cart = cart as List <CartItem>;
                        shSizeService _size = new shSizeService();
                        decimal       price = _size.ListProductPrice_Quantity(cart as List <CartItem>, 0, 0, 0);

                        decimal Feeship = Config.FeeShip;
                        if (price > Config.FeeTotal)
                        {
                            Feeship = 0;
                        }

                        int _Status = OrderStatus.DangXuLy.GetHashCode();

                        shOrderService _order = new shOrderService();
                        #endregion

                        #region Tìm nhân viên random được chọn xử lý đơn hàng
                        // ds nhân viên được phân xử lý đơn hàng
                        qtUser        UserId             = new qtUser();
                        List <qtUser> dsUser_XuLyDonhang = CommonHelper.GetUserTheoMaCauHinhHeThong_GetTheoUser(Config.TAI_KHOAN_NHAN_DON_HANG, Units.ChiNhanhShowRoom.GetHashCode()).ToList();

                        int userid_dagiaoviec         = 0;
                        IEnumerable <shOrder> dsOrder = _order.DanhSachOrder()
                                                        .Where(x => x.UserId != null && x.UserId != 0)
                                                        .OrderByDescending(x => x.OrderId);

                        foreach (var item in dsOrder)
                        {
                            if (item.UserId != null && item.UserId != 0)
                            {
                                userid_dagiaoviec = item.UserId.Value;
                                break;
                            }
                        }

                        for (int i = 0; i < dsUser_XuLyDonhang.Count(); i++)
                        {
                            qtUser user = dsUser_XuLyDonhang[i];

                            if (user.UserId == userid_dagiaoviec)
                            {
                                if (i == (dsUser_XuLyDonhang.Count() - 1))
                                {
                                    UserId = dsUser_XuLyDonhang[0];
                                }
                                else if (i < (dsUser_XuLyDonhang.Count() - 1))
                                {
                                    UserId = dsUser_XuLyDonhang[i + 1];
                                }
                            }
                        }
                        #endregion

                        #region shOrder
                        shOrder order = _order.Insert_Update(
                            null,
                            null,
                            null,
                            MemberGuid,
                            order_name,
                            order_email,
                            order_phone,
                            order_address,
                            price,
                            _Status,
                            null,
                            TypeHelper.ToInt32(Town),
                            TypeHelper.ToInt32(City),
                            Feeship,
                            true,
                            DateTime.Now,
                            pay_type,
                            DateTime.Now,
                            UserId.UserId
                            );
                        #endregion

                        #region shOrderHistory
                        shOrderHistoryService _orderHistory = new shOrderHistoryService();
                        shOrderHistory        orderHistory  = _orderHistory.Insert_Update(
                            null,
                            order.OrderGuid,
                            _Status,
                            User.Identity.GetMemberLogin().MemberGuid,
                            "Đặt hàng",
                            null,
                            true,
                            DateTime.Now);

                        #endregion

                        #region shOrderDetail
                        shOrderDetailService _orderDetail = new shOrderDetailService();
                        price = 0;
                        decimal total = 0;
                        foreach (var item in cart as List <CartItem> )
                        {
                            price = _size.ProductPrice(item.SizeGuid);
                            total = price * item.Quantity;

                            _orderDetail.Insert_Update(
                                null,
                                null,
                                null,
                                order.OrderGuid,
                                MemberGuid,
                                item.Product.ProductGuid,
                                item.Product.ProductName,
                                item.SectionGuid,
                                item.SizeGuid,
                                item.Quantity,
                                price,
                                total,
                                true,
                                DateTime.Now,
                                DateTime.Now
                                );
                        }
                        #endregion

                        #region SEND EMAIL, MESSAGE
                        // 1. Gửi Email tới Quản trị viên xác nhận đơn hàng

                        /// ds User cấu hình nhận Email trong hệ thống
                        IEnumerable <qtUser> dsUser = CommonHelper.GetUserTheoMaCauHinhHeThong_GetTheoUser(Config.TAI_KHOAN_EMAIL_THONG_BAO_TIEP_NHAN_DON_HANG, Units.ChiNhanhShowRoom.GetHashCode());
                        string noidungdonhang       = EmailHelper.NoiDungDonHang(order, cart as List <CartItem>);
                        string noidungEmail         = string.Empty;
                        foreach (var user in dsUser)
                        {
                            noidungEmail = string.Empty;
                            qtUnitService _unit = new qtUnitService();
                            noidungEmail = EmailHelper.NoiDungMailThongBaoQuanTri(_unit.UnitName(Units.ChiNhanhShowRoom.GetHashCode()), 1, noidungdonhang);
                            EmailHelper.ThongBaoEmailDonHangMoi(user.Email, noidungEmail);
                        }

                        if (UserId.UserId > 0)
                        {
                            noidungEmail = string.Empty;
                            qtUnitService _unit = new qtUnitService();
                            noidungEmail = EmailHelper.NoiDungMailThongBaoQuanTri(_unit.UnitName(Units.ChiNhanhShowRoom.GetHashCode()), 1, noidungdonhang);
                            EmailHelper.ThongBaoEmailDonHangMoi(UserId.Email, noidungEmail);
                        }

                        // 2. Gửi Email xác nhận đơn hàng tới khách hàng
                        noidungEmail = "";
                        if (isCoTaiKhoan)
                        {
                            noidungEmail = EmailHelper.NoiDungMailThongBaoNguoiDatHang(noidungdonhang);
                            EmailHelper.ThongBaoEmailDonHangMoiToiNguoiDatHang(User.Identity.GetMemberLogin().Email, noidungEmail);
                        }
                        // 3. Gửi thông báo tới Quản trị viên nhận thông báo
                        ThongBaoService _thongbao = new ThongBaoService();
                        foreach (var user in dsUser)
                        {
                            int?Memberid = null;
                            if (isCoTaiKhoan)
                            {
                                Memberid = User.Identity.GetMemberLogin().MemberId;
                            }

                            _thongbao.InsertOrUpdate(
                                null,
                                "Thông báo đơn hàng mới. Người đặt hàng: " + order_name + ", giá trị: " + Format.FormatDecimalToString(price),
                                "Bạn có đơn hàng mới cần xử lý từ khách hàng: " + order_name +
                                " với đơn hàng tổng giá trị: " + Format.FormatDecimalToString(price) +
                                " lúc: " + DateTime.Now.ToString("dd/MM/yyyy HH:mm") +
                                ". Vui lòng truy cập hệ thống để xử lý",
                                "/DanhMuc/Order/Index/s=" + order.OrderGuid,
                                Memberid,
                                user.UserId,
                                DateTime.Now,
                                false,
                                Config.THONG_BAO_DON_HANG_MOI,
                                null
                                );
                        }

                        if (UserId.UserId > 0)
                        {
                            int?Memberid = null;
                            if (isCoTaiKhoan)
                            {
                                Memberid = User.Identity.GetMemberLogin().MemberId;
                            }

                            _thongbao.InsertOrUpdate(
                                null,
                                "Thông báo đơn hàng mới. Người đặt hàng: " + order_name + ", giá trị: " + Format.FormatDecimalToString(price),
                                "Bạn có đơn hàng mới cần xử lý từ khách hàng: " + order_name +
                                " với đơn hàng tổng giá trị: " + Format.FormatDecimalToString(price) +
                                " lúc: " + DateTime.Now.ToString("dd/MM/yyyy HH:mm") +
                                ". Vui lòng truy cập hệ thống để xử lý",
                                "/DanhMuc/Order/Index/s=" + order.OrderGuid,
                                Memberid,
                                UserId.UserId,
                                DateTime.Now,
                                false,
                                Config.THONG_BAO_DON_HANG_MOI,
                                null
                                );
                        }

                        #endregion

                        #region Clear data cookies after order
                        Session[CartSession] = null;
                        #endregion

                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }

            return(Redirect("/thong-tin-ca-nhan"));
        }
        public IEnumerable <TimKiemNangCao> TimKiemNangCao(string keyword)
        {
            List <TimKiemNangCao> ds      = new List <TimKiemNangCao>();
            TimKiemNangCao        timkiem = new TimKiemNangCao();

            // 1. Tìm kiếm trong bảng sản phẩm
            shProductService        _product  = new shProductService();
            IEnumerable <shProduct> dsProduct = _product.FindList().Where(x => TypeHelper.CompareString(x.ProductName, keyword));

            foreach (var product in dsProduct)
            {
                timkiem             = new TimKiemNangCao();
                timkiem.CategoryId  = TheLoaiTimKiemNangCao.SanPham.GetHashCode();
                timkiem.Category    = "Sản phẩm";
                timkiem.Name        = product.ProductName;
                timkiem.MetaTitle   = product.MetaTitle + "-" + product.ProductId;
                timkiem.keyword     = keyword;
                timkiem.CreatedDate = product.CreateDate;
                timkiem.Description = " Bộ sản phẩm có kết cấu và giá sản phẩm: &nbsp;&nbsp;&nbsp;&nbsp; Kích ...";
                timkiem.ProductGuid = product.ProductGuid;
                ds.Add(timkiem);
            }


            // 3. Tìm kiếm trong bảng set sản phẩm
            shSectionService           _section = new shSectionService();
            IEnumerable <shProductSet> dsSet    = _section.FindList().Where(x => TypeHelper.CompareString(x.SectionName, keyword));

            foreach (var set in dsSet)
            {
                shProduct product = _product.FindByKey(set.ProductGuid);

                timkiem             = new TimKiemNangCao();
                timkiem.CategoryId  = TheLoaiTimKiemNangCao.SetSanPham.GetHashCode();
                timkiem.Category    = "Sản phẩm";
                timkiem.Name        = product.ProductName + "- Set " + set.SectionName + keyword;
                timkiem.MetaTitle   = product.MetaTitle + "-" + product.ProductId;
                timkiem.keyword     = keyword;
                timkiem.CreatedDate = set.CreateDate;
                timkiem.Description = " Bộ sản phẩm có kết cấu và giá sản phẩm: &nbsp;&nbsp;&nbsp;&nbsp; Kích ...";
                timkiem.ProductGuid = product.ProductGuid;
                ds.Add(timkiem);
            }

            // 4. Tìm kiếm trong bảng kích thước theo set
            shSizeService           _size  = new shSizeService();
            IEnumerable <shSetSize> dsSize = _size.FindList().Where(x => TypeHelper.CompareString(x.SizeName, keyword));

            foreach (var size in dsSize)
            {
                shProduct product = _product.FindByKey(size.ProductGuid);

                timkiem             = new TimKiemNangCao();
                timkiem.CategoryId  = TheLoaiTimKiemNangCao.SetSanPham.GetHashCode();
                timkiem.Category    = "Sản phẩm";
                timkiem.Name        = product.ProductName + " - Kích thước: " + size.SizeName;
                timkiem.MetaTitle   = product.MetaTitle + "-" + product.ProductId;
                timkiem.keyword     = keyword;
                timkiem.CreatedDate = size.CreateDate;
                timkiem.Description = " Bộ sản phẩm có kết cấu và giá sản phẩm: &nbsp;&nbsp;&nbsp;&nbsp; Kích ...";
                timkiem.ProductGuid = product.ProductGuid;
                ds.Add(timkiem);
            }


            // 2. Tìm kiếm trong bảng tin tức
            shNewService        _new  = new shNewService();
            IEnumerable <shNew> dsNew = _new.FindList().Where(x => TypeHelper.CompareString(x.TitleNew, keyword));

            foreach (var news in dsNew)
            {
                timkiem             = new TimKiemNangCao();
                timkiem.CategoryId  = TheLoaiTimKiemNangCao.TinTuc.GetHashCode();
                timkiem.Category    = "Tin Tức";
                timkiem.Name        = news.TitleNew;
                timkiem.MetaTitle   = news.MetaTitle + "-" + news.NewId;
                timkiem.keyword     = keyword;
                timkiem.CreatedDate = news.CreatedDate;
                timkiem.Description = news.Summary;
                ds.Add(timkiem);
            }

            return(ds);
        }