예제 #1
0
        public JsonResult CreateDonhang(string Hoten, string Mail, string Diachi, string GhiChuKhac,
                                        string SDT, string ngaydathang, string Duyet, string Xungho,
                                        string Tongtienhang, string Hinhthucgiaohang, string Tiengiamgia)
        {
            try
            {
                if (MySession.TongTien != 0)
                {
                    CTdonhang_Model modelCTDonhang = new CTdonhang_Model();
                    Donhang_Model   modelDonhang   = new Donhang_Model();//gọi model data
                    //xử lý Đơn hàng
                    modelDonhang.IDuser            = 0;
                    modelDonhang.SDT               = SDT;
                    modelDonhang.Hoten             = Hoten;
                    modelDonhang.Mail              = Mail;
                    modelDonhang.Diachi            = Diachi;
                    modelDonhang.Tinh              = "";
                    modelDonhang.Huyen             = "";
                    modelDonhang.Xungho            = Xungho;
                    modelDonhang.Hinhthucthanhtoan = "";
                    modelDonhang.Goidichvu         = "";
                    modelDonhang.Tongtienhang      = Convert.ToDouble(MySession.TongTien);
                    modelDonhang.Thanhtoan         = 0;
                    modelDonhang.ngaydathang       = DateTime.Now;
                    modelDonhang.KH               = "";
                    modelDonhang.Duyet            = "0";
                    modelDonhang.Khuyenmai        = "";
                    modelDonhang.Hinhthucgiaohang = "";
                    modelDonhang.GhiChuKhac       = GhiChuKhac;
                    modelDonhang.Tiengiamgia      = 0;

                    ///Xử lý chi tiết đơn hàng
                    /////////////////////////////
                    ConnectDonhang.Create(modelDonhang);
                    var donhangmax = connect_entity.Donhang_Max().FirstOrDefault();
                    int id         = Convert.ToInt32(donhangmax);
                    foreach (var s in MySession.GioHang)
                    {
                        modelCTDonhang.IDhd           = id;
                        modelCTDonhang.IDsanpham      = Convert.ToString(s.IDsanpham);
                        modelCTDonhang.Tensanpham     = s.TenSanPham;
                        modelCTDonhang.Soluong        = Convert.ToInt32(s.SoLuong);
                        modelCTDonhang.Giacu          = Convert.ToDouble(s.Giacu);
                        modelCTDonhang.Giaban         = Convert.ToDouble(s.Giaban);
                        modelCTDonhang.Size           = s.Size;
                        modelCTDonhang.Mausac         = _resurtTenmau(Convert.ToInt32(s.Mausac));
                        modelCTDonhang.Dungluong      = s.Dungluong;
                        modelCTDonhang.Hinhanh        = s.Hinhanh;
                        modelCTDonhang.Giamthem       = s.Giamthem;
                        modelCTDonhang.danhmucsanpham = s.danhmucsanpham;
                        modelCTDonhang.chitietsanpham = s.chitietsanpham;
                        modelCTDonhang.Giamthem       = s.Giamthem;
                        modelCTDonhang.phantramkm     = s.phantramkm;
                        modelCTDonhang.Baohanh        = Convert.ToInt32(s.Baohanh);
                        modelCTDonhang.tinhtrang      = s.tinhtrang;
                        ConnectCTDonhang.Create(modelCTDonhang);
                    }
                    //sendmail(modelDonhang.Mail, modelDonhang.Hoten, modelDonhang.Xungho, modelDonhang.SDT, Convert.ToInt32(modelDonhang.Hinhthucgiaohang), modelDonhang.Diachi, 0 );
                    MySession.GioHang.Clear();
                    MySession.TongTien = 0;
                }

                resurt = 1;

                return(Json(resurt, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }