예제 #1
0
        public JsonResult CapNhatProccess(CapNhatUserVM model)
        {
            rs        r;
            SimpleAES __aes = new SimpleAES();

            if (ModelState.IsValid)
            {
                var __id = MySsAuthUsers.GetAuth().ID;
                using (var __db = new vuong_cms_context())
                {
                    var user = __db.Users.Find(__id);

                    user.Phone    = model.Phone;
                    user.Address  = model.Address;
                    user.Fullname = model.Fullname;
                    __db.SaveChanges();
                    r = rs.T("Ok");
                }
            }
            else
            {
                r = rs.F("Vui lòng điền đầy đủ thông tin!");
            }
            return(Json(r, JsonRequestBehavior.DenyGet));
        }
예제 #2
0
        public JsonResult DoiMatKhauProccess(DoiMatKhauVM model)
        {
            rs        r;
            SimpleAES __aes = new SimpleAES();

            if (ModelState.IsValid)
            {
                var __oldpw = __aes.EncryptToString(model.MatKhauHienTai);
                var __newpw = __aes.EncryptToString(model.MatKhauMoi);
                var __id    = MySsAuthUsers.GetAuth().ID;
                using (var __db = new vuong_cms_context())
                {
                    var user = __db.Users.Find(__id);
                    if (user.Password == __oldpw)
                    {
                        user.Password = __newpw;
                        __db.SaveChanges();
                        r = rs.T("Ok");
                    }
                    else
                    {
                        r = rs.F("Mật khẩu hiện tại không chính xác!");
                    }
                }
            }
            else
            {
                r = rs.F("Vui lòng điền đầy đủ thông tin!");
            }
            return(Json(r, JsonRequestBehavior.DenyGet));
        }
예제 #3
0
        public JsonResult editSLSP(int ctid, int sl)
        {
            rs r;

            using (var __db = new vuong_cms_context())
            {
                using (var tx = new TransactionScope())
                {
                    try
                    {
                        var en = __db.CTDonHangs.Find(ctid);
                        en.SoLuong   = sl;
                        en.ThanhTien = en.DonGia * en.SoLuong;
                        __db.SaveChanges();

                        var parent = __db.DonHangs.Find(en.DonHangID);
                        parent.TongTienHang = parent.CTDonHangs.Sum(s => s.DonGia * s.SoLuong);
                        __db.SaveChanges();
                        tx.Complete();

                        r = rs.T("Cập nhật thành công!", new
                        {
                            TongTien  = parent.TongTienHang.ToMoneyStr(),
                            ThanhTien = en.ThanhTien.ToMoneyStr(),
                        });
                    }
                    catch (Exception ex)
                    {
                        r = rs.F(ex.Message);
                    }
                }
            }

            return(Json(r, JsonRequestBehavior.DenyGet));
        }
예제 #4
0
        public IEnumerable <ArticleVM> layds()
        {
            vuong_cms_context __db = new vuong_cms_context();
            var data = __db.Article.Where(w => w.CategoryId == 1 || w.CategoryId == 3).OrderByDescending(o => o.Id);

            return(ArticleVM.map(data));
        }
예제 #5
0
        public rs goitinhtien(GoiTinhTienForm model)
        {
            rs r;

            using (var __db = new vuong_cms_context())
            {
                if (ModelState.IsValid)
                {
                    var entity = __db.DonHangs.Find(model.DonHangID);
                    if (model.TienKhachDua < entity.TongTienHang)
                    {
                        throw new Exception("Tiền khách đưa không đủ!");
                    }
                    entity.SoLanGoiTinhTien++;
                    entity.TienKhachDua       = model.TienKhachDua;
                    entity.LanCuoiGoiTinhTien = DateTime.Now;
                    __db.SaveChanges();
                    r = rs.T("Quán đã nhận được yêu cầu gọi tính tiền!", DonHangVM.map(entity));
                    IHubContext context = GlobalHost.ConnectionManager.GetHubContext <UsersOnLine>();
                    context.Clients.All.notify_goitinhtien(entity.BaseUserId, "Yêu cầu tính tiền bàn: " + entity.Ban);
                }
                else
                {
                    //all error
                    r = rs.F("Lỗi, vui lòng thử lại. " + string.Join(";", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).Distinct()));
                }
            }
            return(r);
        }
예제 #6
0
        public ArticleVM get_by_id(int id)
        {
            vuong_cms_context __db = new vuong_cms_context();
            var data = __db.Article.FirstOrDefault(f => f.Id == id);

            return(ArticleVM.map(data));
        }
예제 #7
0
        public rs dat_hang(DatHangForm model)
        {
            rs r;

            using (var __db = new vuong_cms_context())
            {
                if (ModelState.IsValid)
                {
                    using (var tx = __db.Database.BeginTransaction())
                    {
                        try
                        {
                            //donhang
                            DonHang donhang = new DonHang();
                            donhang.UserId               = model.UserId;
                            donhang.GhiChuDonHang        = model.GhiChu;
                            donhang.TrangThaiGiaoHangId  = 1;
                            donhang.TrangThaiThanhToanId = 1;
                            //ctdh
                            donhang.CTDonHangs = new Collection <CTDonHang>();
                            foreach (var gio in model.ChiTietDonHang)
                            {
                                var       sanphamdb = __db.Product.Find(gio.SanPhamId);
                                CTDonHang newct     = new CTDonHang()
                                {
                                    SanPhamId = gio.SanPhamId,
                                    SoLuong   = gio.SoLuong,
                                };
                                newct.ThanhTien = newct.DonGia * newct.SoLuong;
                                donhang.CTDonHangs.Add(newct);
                            }
                            var __tongtiendonhang = donhang.CTDonHangs.Sum(s => s.DonGia * s.SoLuong);
                            donhang.TongTienHang = __tongtiendonhang;

                            //user
                            __db.DonHangs.Add(donhang);
                            __db.SaveChanges();

                            //com
                            tx.Commit();
                            r = rs.T("Đặt hàng thành công");
                        }
                        catch (Exception ex)
                        {
                            r = rs.F("Lỗi máy chủ " + ex.Message);
                            tx.Rollback();
                        }
                    }
                }
                else
                {
                    //all error
                    r = rs.F(string.Join(";", ModelState.Values
                                         .SelectMany(x => x.Errors)
                                         .Select(x => x.ErrorMessage).Distinct()));
                }
            }
            return(r);
        }
예제 #8
0
        public ActionResult CTDonHang(int Id)
        {
            int _id = MySsAuthUsers.GetAuth().ID;
            vuong_cms_context __db = new vuong_cms_context();
            var model = __db.DonHangs.FirstOrDefault(w => w.Id == Id);

            return(View(model));
        }
예제 #9
0
        public ActionResult DonHang()
        {
            int _id = MySsAuthUsers.GetAuth().ID;
            vuong_cms_context __db = new vuong_cms_context();
            var model = __db.DonHangs.Where(w => w.UserId == _id).OrderByDescending(o => o.CreatedDate);

            return(View(model));
        }
예제 #10
0
        public ActionResult LichSuNapThe()
        {
            int _id = MySsAuthUsers.GetAuth().ID;
            vuong_cms_context __db = new vuong_cms_context();
            var model = __db.LichSuNapThe.Where(w => w.UserId == _id).OrderByDescending(o => o.ngay);

            return(View(model));
        }
예제 #11
0
        public ActionResult Profile()
        {
            var au = MySsAuthUsers.GetAuth();
            vuong_cms_context __db = new vuong_cms_context();
            var model = __db.Users.Find(au.ID);

            return(View(model));
        }
        protected override void Seed(vuong_cms_context context)
        {
            CacheServ.ClearAll();

            return;

            context.Confs.Add(new Conf()
            {
                Key          = "html_taikhoannganhang",
                Content      = "",
                IsHtmlEditor = true,
                Description  = "Tài khoản ngân hàng"
            });
            context.SaveChanges();

            context.Category.AddOrUpdate(Category.seed());
            context.SaveChanges();
            context.Article.AddOrUpdate(Article.seed());
            context.SaveChanges();
            context.Product.AddOrUpdate(Product.seed());
            context.SaveChanges();
            //settings:
            context.Settings.AddOrUpdate(Setting.seed());
            context.SaveChanges();

            //role
            context.Roles.AddOrUpdate(Role.seed());
            context.SaveChanges();

            //flag
            context.Langs.AddOrUpdate(Lang.seed());
            context.SaveChanges();

            //Confs
            context.Confs.AddOrUpdate(Conf.seed());
            context.SaveChanges();


            //LogType
            context.LogType.AddOrUpdate(LogType.seed());
            context.SaveChanges();

            //UserStatus
            context.UserStatus.AddOrUpdate(UserStatus.seed());
            context.SaveChanges();

            //user
            context.Users.AddOrUpdate(User.seed());
            context.SaveChanges();


            context.ThongTin.AddOrUpdate(ThongTin.seed());
            context.SaveChanges();

            //
            context.ThongBao.AddOrUpdate(ThongBao.seed());
            context.SaveChanges();
        }
예제 #13
0
        public JsonResult LayGiaShip(int district_id)
        {
            int gia_ship = 0;

            using (var __db = new vuong_cms_context())
            {
                gia_ship = __db.District.Find(district_id).GiaShip;
            }
            return(Json(gia_ship, JsonRequestBehavior.AllowGet));
        }
예제 #14
0
        public rs SendEmail(sendMailObj obj, bool is_robot = false, bool is_send_to_adm = false)
        {
            rs rss;

            try
            {
                vuong_cms_context __db = new vuong_cms_context();
                var confemail          = __db.Settings.Find(1);

                SmtpClient client = new SmtpClient();
                client.Port = confemail.smpt_port; //587;
                client.Host = confemail.smpt_host; //"mail.worldofpledges.com";

                client.Timeout               = 10000;
                client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                client.EnableSsl             = confemail.smpt_enable_ssl;
                client.UseDefaultCredentials = confemail.smpt_use_default_credentials;
                string _email_robot = "";
                if (is_robot)
                {
                    SimpleAES _aes  = new SimpleAES();
                    var       _conf = __db.Confs.Find(1);
                    _email_robot = confemail.sys_email_robot;;
                    string _pw = _aes.DecryptString(confemail.sys_email_robot_pw);
                    client.Credentials = new System.Net.NetworkCredential(_email_robot, _pw);
                }
                else
                {
                    client.Credentials = new System.Net.NetworkCredential(obj.emailGui, obj.passEmailGui);
                }


                MailMessage message = new MailMessage();
                message.From    = new MailAddress(is_robot ? _email_robot : obj.emailGui);//"*****@*****.**"
                message.Subject = obj.tieude;
                message.Body    = obj.noidung;
                if (is_send_to_adm)
                {
                    message.To.Add(confemail.sys_email);//system
                }
                else
                {
                    message.To.Add(obj.emailNhan); //""Email nhận
                }

                message.IsBodyHtml = true;
                client.Send(message);
                rss = rs.T("Gửi mail thành công");
            }
            catch (Exception ex)
            {
                rss = rs.F("Lỗi: " + ex.Message);
            }
            return(rss);
        }
예제 #15
0
        public JsonResult ddlDistrict(int province_id)
        {
            vuong_cms_context __db = new vuong_cms_context();
            var obj = __db.District.Where(w => w.ProvinceId == province_id).Select(s => new
            {
                s.ProvinceId,
                s.Id,
                s.Name
            });

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
예제 #16
0
        public PartialViewResult Footer()
        {
            vuong_cms_context __db  = new vuong_cms_context();
            FooterView        model = new FooterView()
            {
                Statistic           = this._counterRepo.GetCounter(),
                DanhMucSanPhamChinh = new List <ProductCat>(),
                DsBaiVietFooter     = __db.Article.Where(w => w.CategoryId == 3).OrderByDescending(q => q.ModifiedDate).ToList()
            };

            return(PartialView(model));
        }
예제 #17
0
        public JsonResult ddlWard(int district_id)
        {
            vuong_cms_context __db = new vuong_cms_context();
            var obj = __db.Ward.Where(w => w.DistrictID == district_id).Select(s => new
            {
                s.DistrictID,
                s.Id,
                s.Name
            });

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
예제 #18
0
        public JsonResult AjaxGetCatShow()
        {
            using (var _mycontext = new vuong_cms_context())
            {
                _mycontext.Configuration.LazyLoadingEnabled   = false;
                _mycontext.Configuration.ProxyCreationEnabled = false;

                var rs = _mycontext.ProductCat.Select(s => new {
                    s.Id,
                    s.Name
                }).ToList();
                return(Json(rs, JsonRequestBehavior.AllowGet));
            }
        }
예제 #19
0
        public ActionResult CapNhat()
        {
            var           __id  = MySsAuthUsers.GetAuth().ID;
            CapNhatUserVM model = new CapNhatUserVM();

            using (var __db = new vuong_cms_context())
            {
                var user = __db.Users.Find(__id);
                model.Username = user.Username;
                model.Phone    = user.Phone;
                model.Address  = user.Address;
                model.Fullname = user.Fullname;
            }
            return(View(model));
        }
예제 #20
0
        public ListPagingJson <DonHangVM> layds(int userid, string token, int page, int pageSize)
        {
            vuong_cms_context __db = new vuong_cms_context();
            //initial
            var paging = new ListPagingJson <DonHangVM>();

            paging.Paging.RecordsPerPage = pageSize;
            paging.Paging.CurrentPage    = page;
            //calculator
            var query = __db.DonHangs.Where(w => w.UserId == userid);

            paging.Number1             = query.Count(c => c.TrangThaiThanhToanId == 1);
            paging.Paging.TotalRecords = query.Count();
            paging.List = DonHangVM.map(query.OrderByDescending(o => o.Id).Skip((page - 1) * pageSize).Take(pageSize));
            return(paging);
        }
예제 #21
0
        public ActionResult Index(string back_url = "")
        {
            ViewBag.back_url = back_url;
            ThanhToanVM vm = new ThanhToanVM();

            using (var __db = new vuong_cms_context())
            {
                //user
                var uuu = MySsAuthUsers.GetAuth();
                if (uuu != null)
                {
                    var user = __db.Users.Find(uuu.ID);
                    vm.DiaChiGiaohang = user.Address;
                }
            }

            return(View(vm));
        }
        public void Insert(Exception ex)
        {
            vuong_cms_context db    = new vuong_cms_context();
            LogException      logEx = new LogException();

            logEx.ExceptionMsg    = ex.Message;
            logEx.ExceptionType   = ex.GetType().Name.ToString();
            logEx.ExceptionURL    = HttpContext.Current.Request.Url.ToString();
            logEx.ExceptionSource = ex.StackTrace.ToString();
            logEx.Logdate         = DateTime.Now;

            Log log = new Log();

            log.LogException = logEx;
            log.LogTypeId    = 3;
            log.Message      = ex.Message;
            Insert(log);
            Save();
        }
예제 #23
0
        public JsonResult toggleHetHang(int id)
        {
            rs r;

            try
            {
                using (var __db = new vuong_cms_context())
                {
                    var en = __db.CTDonHangs.Find(id);
                    __db.SaveChanges();
                    r = rs.T("Cập nhật thành công!");
                }
            }
            catch (Exception ex)
            {
                r = rs.F(ex.Message);
                throw;
            }
            return(Json(r, JsonRequestBehavior.DenyGet));
        }
예제 #24
0
        public PartialViewResult Header()
        {
            vuong_cms_context __db = new vuong_cms_context();

            HeaderView model = new HeaderView();

            model._current_culture = base.__langid;
            model.ProductCats      = __db.ProductCat.ToList();
            model.Langs            = _langRepo.GetList(orderBy: q => q.OrderBy(o => o.Order));

            if (mySessions.Get("gio_hang") == null)
            {
                model.SLSPGioHang = 0;
            }
            else
            {
                model.SLSPGioHang = ((GioHang)mySessions.Get("gio_hang")).CTGioHangs.Count;
            }

            return(PartialView(model));
        }
예제 #25
0
        public ActionResult ThemSanPham(ThemSanPhamGioHangVM vm)
        {
            rd = new Random();

            try
            {
                vuong_cms_context __db = new vuong_cms_context();
                var sanpham            = __db.Product.Find(vm.SanPhamId);

                CTGioHang ct = new CTGioHang();
                ct.SanPhamId  = vm.SanPhamId;
                ct.TenSanPham = sanpham.ProductName;
                ct.HinhAnh    = sanpham.ThumbnailImage;
                ct.SoLuong    = vm.SoLuong;
                ct.Link       = Url.Action("Detail", "SanPham", new { id = sanpham.Id, seo_title = sanpham.ProductName.URLFriendly() });
                GioHang.ThemSanPham(ct);
            }
            catch (Exception ex)
            {
                return(Content("Lỗi: " + ex.Message));
            }
            return(RedirectToAction("Index"));
        }
예제 #26
0
        public ListPagingJson <DonHangVM> laydsdevice(string uniqueID, int trangthaithanhtoanid, int page, int pageSize)
        {
            //initial
            var paging = new ListPagingJson <DonHangVM>();

            paging.Paging.RecordsPerPage = pageSize;
            paging.Paging.CurrentPage    = page;

            vuong_cms_context __db = new vuong_cms_context();

            //calculator
            var query = __db.DonHangs.Where(w => w.UniqueID == uniqueID);

            paging.Number1 = query.Count(c => c.TrangThaiThanhToanId == 1);
            if (trangthaithanhtoanid != -1)
            {
                query = query.Where(w => w.TrangThaiThanhToanId == trangthaithanhtoanid);
            }
            paging.Paging.TotalRecords = query.Count();
            paging.List = DonHangVM.map(query.OrderByDescending(o => o.Id).Skip((page - 1) * pageSize).Take(pageSize));
            //so don hang chua thanh toan
            return(paging);
        }
예제 #27
0
        public rs gopy(GopYDonHangForm model)
        {
            rs r;

            using (var __db = new vuong_cms_context())
            {
                if (ModelState.IsValid)
                {
                    var  entity = __db.DonHangs.Find(model.DonHangID);
                    GopY gop    = new GopY();
                    gop.DonHangId   = model.DonHangID;
                    gop.NoiDungGopY = model.NoiDung;
                    gop.CreatedDate = DateTime.Now;
                    __db.GopY.Add(gop);
                    __db.SaveChanges();
                    r = rs.T("Chúng tôi đã ghi nhận góp ý của bạn, xin cám ơn!", DonHangVM.map(entity));

                    IHubContext context = GlobalHost.ConnectionManager.GetHubContext <UsersOnLine>();
                    if (entity.HinhThucMuaHangId == 1)
                    {
                        context.Clients.All.notify_gopy(entity.BaseUserId, "Nhận được góp ý tại bàn: " + entity.Ban);
                    }
                    else
                    {
                        context.Clients.All.notify_gopy(entity.BaseUserId, "Nhận được góp ý *" + entity.HinhThucMuaHang.Ten + "*");
                    }
                }
                else
                {
                    //all error
                    r = rs.F("Lỗi, vui lòng thử lại. " + string.Join(";", ModelState.Values
                                                                     .SelectMany(x => x.Errors)
                                                                     .Select(x => x.ErrorMessage).Distinct()));
                }
            }
            return(r);
        }
예제 #28
0
        public JsonResult SetMain(int id)
        {
            rs rs;

            try
            {
                using (var dbcontext = new vuong_cms_context())
                {
                    using (var tx = new TransactionScope())
                    {
                        var tim = dbcontext.ImgTmpDetail.FirstOrDefault(f => f.Id == id);
                        dbcontext.Database.ExecuteSqlCommand("UPDATE ImgTmpDetails SET [IsMain]=0 WHERE [ImgTmpId]=" + tim.ImgTmpId);
                        dbcontext.Database.ExecuteSqlCommand("UPDATE ImgTmpDetails SET [IsMain]=1 WHERE Id=" + id);
                        tx.Complete();
                        rs = rs.T("Ok");
                    }
                }
            }
            catch (Exception ex)
            {
                rs = rs.F(ex.Message);
            }
            return(Json(rs, JsonRequestBehavior.AllowGet));
        }
예제 #29
0
        public rs dat_hang_qr(DatHangQRForm model)
        {
            rs r;

            using (var __db = new vuong_cms_context())
            {
                if (ModelState.IsValid)
                {
                    using (var tx = __db.Database.BeginTransaction())
                    {
                        try
                        {
                            var quan = __db.Quan.FirstOrDefault(f => f.Id == model.QuanId);

                            //var ban = __db.Ban.First(f => f.Id == model.BanId && f.QuanId == model.QuanId);
                            if (quan == null)
                            {
                                throw new Exception("Bàn và quán không hợp lệ, vui lòng thử lại!");
                            }

                            var BanArr = new List <int>();
                            if (!string.IsNullOrWhiteSpace(quan.BanArr))
                            {
                                try
                                {
                                    BanArr = quan.BanArr.Split(',').Select(Int32.Parse).Distinct().ToList();
                                }
                                catch
                                {
                                }
                            }
                            if (model.HinhThucMuaHangId == 1 && !BanArr.Contains(model.Ban))
                            {
                                throw new Exception("Số Bàn nhập không tồn tại trong quán " + quan.TenQuan + ", vui lòng thử lại!");
                            }
                            //donhang
                            DonHang donhang = new DonHang();
                            //donhang.BanId = model.BanId;
                            donhang.Ban                  = model.Ban;
                            donhang.QuanId               = model.QuanId;
                            donhang.GhiChuDonHang        = "";
                            donhang.TrangThaiGiaoHangId  = 1;
                            donhang.TrangThaiThanhToanId = 1;
                            donhang.UserId               = null;
                            donhang.BaseUserId           = quan.UserId;
                            donhang.DeviceType           = 2;//mobile
                            donhang.UniqueID             = model.UniqueID;
                            donhang.ModelNumber          = model.ModelNumber;
                            donhang.HinhThucMuaHangId    = model.HinhThucMuaHangId;
                            donhang.SDT                  = model.SDT;
                            donhang.YeuCauKhac           = model.YeuCauKhac;
                            donhang.DiaChiGiaoHang       = model.DiaChiGiaoHang;
                            donhang.TienKhachDua         = 0;
                            //ctdh
                            donhang.CTDonHangs = new Collection <CTDonHang>();
                            foreach (var gio in model.ChiTietDonHang)
                            {
                                Product sp = __db.Product.FirstOrDefault(f => f.Id == gio.SanPhamId && f.ProductCat.QuanId == model.QuanId);

                                if (sp == null)
                                {
                                    throw new Exception("Sản phẩm không tồn tại, vui lòng xóa tất cả sản phẩm giỏ hàng và chọn lại!");
                                }
                                var    price  = sp.Price;
                                string tengia = "";
                                if (gio.GiaId != 0)
                                {
                                    var check_gia = __db.BangGiaCT.FirstOrDefault(f => f.Id == gio.GiaId);
                                    if (check_gia == null)
                                    {
                                        throw new Exception("Bảng giá sản phẩm đã cũ, vui lòng tạo lại đơn hàng!");
                                    }
                                    else
                                    {
                                        price  = check_gia.Price;
                                        tengia = check_gia.Ten;
                                    }
                                }
                                CTDonHang newct = new CTDonHang()
                                {
                                    SanPhamId = gio.SanPhamId,
                                    SoLuong   = gio.SoLuong,
                                    DonGia    = price,
                                    ThucDonId = gio.ThucDonId,
                                    TenGia    = tengia,
                                    GiaId     = gio.GiaId,
                                };
                                newct.ThanhTien = newct.DonGia * newct.SoLuong;
                                donhang.CTDonHangs.Add(newct);
                            }
                            var __tongtiendonhang = donhang.CTDonHangs.Sum(s => (int?)s.DonGia * s.SoLuong) ?? 0;
                            donhang.TongTienHang = __tongtiendonhang;

                            //user
                            __db.DonHangs.Add(donhang);
                            __db.SaveChanges();

                            //com
                            tx.Commit();
                            r = rs.T("Đặt hàng thành công");
                            IHubContext context = GlobalHost.ConnectionManager.GetHubContext <UsersOnLine>();
                            context.Clients.All.notify_new_donhang(donhang.BaseUserId, "Đơn hàng mới tại bàn: " + donhang.Ban);
                        }
                        catch (Exception ex)
                        {
                            r = rs.F(ex.Message);
                            tx.Rollback();
                        }
                    }
                }
                else
                {
                    //all error
                    r = rs.F("Lỗi, vui lòng thử lại. " + string.Join(";", ModelState.Values
                                                                     .SelectMany(x => x.Errors)
                                                                     .Select(x => x.ErrorMessage).Distinct()));
                }
            }
            return(r);
        }
예제 #30
0
        public ActionResult Index(ThanhToanVM model)
        {
            var giohang = GioHang.Lay();

            if (!giohang.CTGioHangs.Any())
            {
                ModelState.AddModelError(string.Empty, "Giỏ hàng rỗng");
            }
            var uuu = MySsAuthUsers.GetAuth();

            if (uuu == null)
            {
                ModelState.AddModelError(string.Empty, "Vui lòng đăng nhập");
            }
            bool status = false;

            using (var __db = new vuong_cms_context())
            {
                if (ModelState.IsValid)
                {
                    using (var tx = __db.Database.BeginTransaction())
                    {
                        try
                        {
                            //donhang
                            DonHang donhang = new DonHang();
                            donhang.TongTienHang         = giohang.TongTienHang;
                            donhang.TrangThaiGiaoHangId  = 1;
                            donhang.TrangThaiThanhToanId = 1;

                            //ctdh
                            donhang.CTDonHangs = new Collection <CTDonHang>();
                            foreach (var gio in giohang.CTGioHangs)
                            {
                                donhang.CTDonHangs.Add(new CTDonHang()
                                {
                                    SanPhamId = gio.SanPhamId,
                                    SoLuong   = gio.SoLuong,
                                    ThanhTien = gio.ThanhTien,
                                    DonGia    = gio.DonGia,
                                });
                            }
                            //user

                            if (uuu != null)
                            {
                                donhang.UserId = uuu.ID;
                            }

                            __db.DonHangs.Add(donhang);
                            __db.SaveChanges();



                            //com
                            tx.Commit();
                        }
                        catch (Exception ex)
                        {
                            tx.Rollback();
                        }
                    }
                }
            }
            return(View(model));
        }