public IHttpActionResult GetJoinSanPhamsMatHangs(string id)
        {
            var joinSanPhams = new List <SanPhamMatHang>();

            using (var db = new BanHangDBContext())
            {
                var sp = db.sanPhams.ToList();
                var mh = db.matHangs.ToList();
                joinSanPhams = sp.Join(                        // outer sequence
                    mh,                                        // inner sequence
                    sanpham => sanpham.IDMH,                   // outerKeySelector
                    mathang => mathang.IDMH,                   // innerKeySelector
                    (sanpham, mathang) => new SanPhamMatHang() // result selector
                {
                    IDSP        = sanpham.IDSP,
                    TenSP       = sanpham.TenSP,
                    IDHSX       = sanpham.IDHSX,
                    DonGia      = sanpham.DonGia,
                    NgayCapNhat = sanpham.NgayCapNhat,
                    IDMH        = mathang.IDMH,
                    TenMH       = mathang.TenMH
                })
                               .Where(x => x.IDSP == id)
                               .ToList();

                //sanPhamMatHang = joinSanPhams.Find(x => x.IDSP == id);
            }

            return(Ok(joinSanPhams));
        }
Beispiel #2
0
        public string GetIdentity()
        {
            string ID = "";

            using (var entity = new BanHangDBContext())
            {
                var list = entity.nhapKhos.ToList();
                if (list.Count == 0)
                {
                    ID = "NK000";
                }
                else
                {
                    int temp;
                    ID   = "NK";
                    temp = Convert.ToInt32(list[list.Count - 1].IDNK.ToString().Substring(2, 3));
                    temp = temp + 1;
                    if (temp < 10)
                    {
                        ID = ID + "00";
                    }
                    else if (temp < 100)
                    {
                        ID = ID + "0";
                    }
                    ID = ID + temp.ToString();
                }
                return(ID);
            }
        }
        public IHttpActionResult PostHoaDonGetIdentity(HoaDon hoaDon)
        {
            using (var entity = new BanHangDBContext())
            {
                hoaDon.IDHD = GetIdentity();
                entity.hoaDons.Add(hoaDon);

                entity.SaveChanges();
            }

            return(Ok(hoaDon));
        }
Beispiel #4
0
        public IHttpActionResult PostKhachHangGetIdentity(KhachHang khachHang)
        {
            using (var entity = new BanHangDBContext())
            {
                khachHang.IDKH = GetIdentity();
                entity.khachHangs.Add(khachHang);

                entity.SaveChanges();
            }

            return(Ok(khachHang));
        }
Beispiel #5
0
        public IHttpActionResult PostNhapHoaDonGetIdentity(NhapHoaDon nhapHoaDon)
        {
            using (var entity = new BanHangDBContext())
            {
                nhapHoaDon.IDNHD = GetIdentity();
                entity.nhapHoaDons.Add(nhapHoaDon);

                entity.SaveChanges();
            }

            return(Ok(nhapHoaDon));
        }
        public IHttpActionResult PostPhieuNhapGetIdentity(PhieuNhap phieuNhap)
        {
            using (var entity = new BanHangDBContext())
            {
                phieuNhap.IDPN = GetIdentity();
                entity.phieuNhaps.Add(phieuNhap);

                entity.SaveChanges();
            }

            return(Ok(phieuNhap));
        }
Beispiel #7
0
        public IHttpActionResult PostListNhapKho(NhapKho[] nhapKhos)
        {
            if (nhapKhos != null)
            {
                for (int i = 0; i < nhapKhos.Length; i++)
                {
                    using (var entity = new BanHangDBContext())
                    {
                        nhapKhos[i].IDNK = GetIdentity();
                        entity.nhapKhos.Add(nhapKhos[i]);
                        entity.SaveChanges();
                    }
                }
                return(Ok(nhapKhos));
            }


            return(NotFound());
        }