public JsonResult ajax_pick_sanpham_vao_thucdon(int ProductId, int ThucDonId)
        {
            rs r;

            try
            {
                if (__db.ThucDonCT.Any(a => a.ThucDonId == ThucDonId && a.ProductId == ProductId))
                {
                    throw new Exception("Sản phẩm đã tồn tại trong thực đơn");
                }
                ThucDonCT ct = new ThucDonCT();
                ct.ThucDonId = ThucDonId;
                ct.ProductId = ProductId;
                __db.ThucDonCT.Add(ct);
                __db.SaveChanges();

                var s = __db.ThucDonCT.Include(i => i.Product).FirstOrDefault(f => f.Id == ct.Id);
                var v = new ThucDonCTVM()
                {
                    TenSanPham = s.Product.ProductName,
                    HinhAnh    = s.Product.ThumbnailImage,
                    SanPhamId  = s.ProductId,
                    ThucDonId  = s.ThucDonId,
                    Id         = s.Id,
                };
                r = rs.T("Ok", v);
            }
            catch (Exception ex)
            {
                r = rs.F("Lỗi: " + ex.Message);
            }
            return(Json(r, JsonRequestBehavior.DenyGet));
        }
Exemple #2
0
        public static SanPham map2(ThucDonCT item, int?thucdonid)
        {
            return(new SanPham()
            {
                ID = item.Id,
                ThucDonId = thucdonid,
                MaSo = item.Product.MaSo,
                HinhAnh = Utils.site + item.Product.ThumbnailImage,
                TenSanPham = item.Product.ProductName,

                MoTa = item.Product.Infomation,

                DanhMucId = item.Product.ProductCatId,
                TenDanhMuc = item.Product.ProductCat.Name,
                Hot = item.Product.Hot,
                New = item.Product.New,

                KM = item.Product.IsGiamGia,
                Gia = item.Product.Price,
                SoLuongGia = item.Product.SoLuongGia,
                BangGiaCT = item.Product.BangGiaCT.Select(s => new BangGiaCTJson()
                {
                    Id = s.Id,
                    Ten = s.Ten,
                    Price = s.Price
                }).ToList()
            });
        }
        public SanPham laysp(int id, string search = "")
        {
            ThucDonCT find = __db.ThucDonCT.Find(id);

            return(SanPham.map(find));
        }