public IHttpActionResult GetBansOrder(int status)
        {
            IList <TableDTO> tableDTO = null;

            using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
            {
                if (status == 1)
                {
                    tableDTO = entities.Bans.Include("BanID").Where(b => b.Status == status)
                               .Select(b => new TableDTO()
                    {
                        BanID  = b.BanID,
                        TenBan = b.TenBan,
                        Status = b.Status
                    }).ToList <TableDTO>();
                }
            }
            if (tableDTO.Count == 0)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(tableDTO));
            }
        }
Exemple #2
0
        public IHttpActionResult GetSanPham()
        {
            IList <SanPhamDTO> productDTO = null;

            using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
            {
                productDTO = entities.SanPhams.Include("SanPhamID")
                             .Select(b => new SanPhamDTO()
                {
                    SanPhamID = b.SanPhamID,
                    TenSP     = b.TenSP,
                    Gia       = b.Gia,
                    MoTa      = b.MoTa,
                    LinkImage = b.LinkImage
                }).ToList <SanPhamDTO>();
            }
            if (productDTO.Count == 0)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(productDTO));
            }
        }
Exemple #3
0
        public IHttpActionResult GetSanPhamByCategory(int id)
        {
            IList <SanPhamDTO> sanPhamDTO = null;

            using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
            {
                sanPhamDTO = entities.SanPhams.Include("SanPhamID").Where(b => b.LoaiSP.LoaiSPID == id)
                             .Select(b => new SanPhamDTO()
                {
                    SanPhamID = b.SanPhamID,
                    TenSP     = b.TenSP,
                    Gia       = b.Gia,
                    MoTa      = b.MoTa,
                    LinkImage = b.LinkImage,
                    LoaiSPID  = b.LoaiSP.LoaiSPID
                }).ToList <SanPhamDTO>();
            }
            if (sanPhamDTO == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(sanPhamDTO));
            }
        }
Exemple #4
0
        public IHttpActionResult PutSanPham(SanPhamDTO sanPham)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid data"));
            }
            using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
            {
                var sanpham = entities.SanPhams.Where(s => s.SanPhamID == sanPham.SanPhamID)
                              .FirstOrDefault <SanPham>();
                if (sanpham != null)
                {
                    sanpham.TenSP           = sanPham.TenSP;
                    sanpham.MoTa            = sanPham.MoTa;
                    sanpham.LinkImage       = sanPham.LinkImage;
                    sanpham.Gia             = sanPham.Gia;
                    sanpham.LoaiSP.LoaiSPID = sanPham.LoaiSPID;

                    entities.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }
            return(Ok());
        }
Exemple #5
0
        public IHttpActionResult GetByIdTable(int id)
        {
            HoaDonXuatDTO hdxDTO = null;

            using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
            {
                hdxDTO = entities.HoaDonXuats.Where(s => s.BanID == id && s.DaThanhToan == false)
                         .Select(s => new HoaDonXuatDTO()
                {
                    BanID             = s.BanID,
                    ChiNhanhID        = s.ChiNhanhID,
                    DaThanhToan       = s.DaThanhToan,
                    HinhThucThanhToan = s.HinhThucThanhToan,
                    HoaDonXuatID      = s.HoaDonXuatID,
                    NgayGio           = s.NgayGio,
                    TongTien          = s.TongTien,
                    TenKhachHang      = s.TenKhachHang
                }).FirstOrDefault <HoaDonXuatDTO>();
            }
            if (hdxDTO == null)
            {
                return(NotFound());
            }

            return(Ok(hdxDTO));
        }
Exemple #6
0
        public IHttpActionResult getHDXbyStt(bool stt = false)
        {
            IList <HoaDonXuatDTO> hoadonxuatDTO = null;

            using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
            {
                hoadonxuatDTO = entities.HoaDonXuats.Include("stt").Where(b => b.DaThanhToan == stt)
                                .Select(b => new HoaDonXuatDTO()
                {
                    HoaDonXuatID      = b.HoaDonXuatID,
                    NgayGio           = b.NgayGio,
                    HinhThucThanhToan = b.HinhThucThanhToan,
                    TongTien          = b.TongTien,
                    DaThanhToan       = b.DaThanhToan,
                    TenKhachHang      = b.TenKhachHang,
                    ChiNhanhID        = b.ChiNhanhID,
                    TenBan            = b.Ban.TenBan,
                    BanID             = b.BanID
                }).ToList <HoaDonXuatDTO>();
            }
            if (hoadonxuatDTO == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(hoadonxuatDTO));
            }
        }
 public IHttpActionResult UpdateTable(TableDTO tb)
 {
     using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
     {
         Ban ban = entities.Bans.Find(tb.BanID);
         if (ban == null)
         {
             return(NotFound());
         }
         ban.Status = tb.Status;
         entities.SaveChanges();
         return(Ok());
     }
 }
Exemple #8
0
        public IHttpActionResult DeleteSanPham(int id)
        {
            using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
            {
                SanPham sanPham = entities.SanPhams.Find(id);
                if (sanPham == null)
                {
                    return(NotFound());
                }
                entities.SanPhams.Remove(sanPham);
                entities.SaveChanges();

                return(Ok("Deleted successfully"));
            }
        }
Exemple #9
0
        public IHttpActionResult Delete(int id)
        {
            using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
            {
                HoaDonXuat hdx = entities.HoaDonXuats.Find(id);
                if (hdx == null)
                {
                    return(NotFound());
                }
                entities.HoaDonXuats.Remove(hdx);
                entities.SaveChanges();

                return(Ok("Deleted successfully"));
            }
        }
Exemple #10
0
 public IHttpActionResult GetLoaiSanPhamByid(int id)
 {
     using (QuanLyCoffeeDbContext db = new QuanLyCoffeeDbContext())
     {
         LoaiSP loaisp = db.LoaiSPs.Find(id);
         if (loaisp == null)
         {
             return(NotFound());
         }
         LoaiSanPhamDTO lspdto = new LoaiSanPhamDTO()
         {
             LoaiSPID = loaisp.LoaiSPID,
             TenLoai  = loaisp.TenLoai
         };
         return(Ok(lspdto));
     }
 }
Exemple #11
0
        public IHttpActionResult GetLoaiSPs()
        {
            using (QuanLyCoffeeDbContext db = new QuanLyCoffeeDbContext())
            {
                var loaispdto = db.LoaiSPs.Select(
                    s => new LoaiSanPhamDTO {
                    LoaiSPID = s.LoaiSPID, TenLoai = s.TenLoai
                })
                                .ToList();
                if (loaispdto.Count() == 0)
                {
                    return(NotFound());
                }

                return(Ok(loaispdto));
            }
        }
Exemple #12
0
 public IHttpActionResult Update(HoaDonXuatDTO hdx)
 {
     using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
     {
         HoaDonXuat hd = entities.HoaDonXuats.Find(hdx.HoaDonXuatID);
         if (hdx == null)
         {
             return(NotFound());
         }
         hd.HoaDonXuatID      = hdx.HoaDonXuatID;
         hd.BanID             = hdx.BanID;
         hd.DaThanhToan       = hdx.DaThanhToan;
         hd.HinhThucThanhToan = hdx.HinhThucThanhToan;
         hd.TongTien          = hdx.TongTien;
         hd.TenKhachHang      = hdx.TenKhachHang;
         entities.SaveChanges();
         return(Ok(hdx));
     }
 }
Exemple #13
0
 public IHttpActionResult CreateSanPham(SanPhamDTO sanPham)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Not a valid data"));
     }
     using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
     {
         entities.SanPhams.Add(new SanPham()
         {
             TenSP     = sanPham.TenSP,
             MoTa      = sanPham.MoTa,
             LinkImage = sanPham.LinkImage,
             LoaiSPID  = sanPham.LoaiSPID,
             Gia       = sanPham.Gia,
         });
         entities.SaveChanges();
     }
     return(Ok("Created Successfully"));
 }
Exemple #14
0
 public IHttpActionResult GetSanPhamById(int id)
 {
     using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
     {
         SanPham sanPham = entities.SanPhams.Find(id);
         if (sanPham == null)
         {
             return(NotFound());
         }
         SanPhamDTO sanPhamDTO = new SanPhamDTO
         {
             SanPhamID = sanPham.SanPhamID,
             TenSP     = sanPham.TenSP,
             Gia       = sanPham.Gia,
             MoTa      = sanPham.MoTa,
             LinkImage = sanPham.LinkImage
         };
         return(Ok(sanPhamDTO));
     }
 }
Exemple #15
0
 public IHttpActionResult GetHoaDonXuats()
 {
     using (QuanLyCoffeeDbContext db = new QuanLyCoffeeDbContext())
     {
         var hoadonxuatdto = db.HoaDonXuats.Select(
             hdx => new HoaDonXuatDTO
         {
             HoaDonXuatID      = hdx.HoaDonXuatID,
             BanID             = hdx.Ban.BanID,
             ChiNhanhID        = hdx.ChiNhanh.ChiNhanhID,
             HinhThucThanhToan = hdx.HinhThucThanhToan,
             NgayGio           = hdx.NgayGio,
             TongTien          = hdx.TongTien,
             TenKhachHang      = hdx.TenKhachHang,
         }).ToList();
         if (hoadonxuatdto.Count == 0)
         {
             return(NotFound());
         }
         return(Ok(hoadonxuatdto));
     }
 }
        public IHttpActionResult GetTableById(int id)
        {
            TableDTO tableDTO = null;

            using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
            {
                tableDTO = entities.Bans.Include("BanID").Where(b => b.BanID == id)
                           .Select(b => new TableDTO()
                {
                    BanID  = b.BanID,
                    TenBan = b.TenBan,
                    Status = b.Status
                }).FirstOrDefault <TableDTO>();
            }
            if (tableDTO == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(tableDTO));
            }
        }
Exemple #17
0
        public IHttpActionResult GetById(int id)
        {
            using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
            {
                HoaDonXuat hdx = entities.HoaDonXuats.Find(id);
                if (hdx == null)
                {
                    return(NotFound());
                }
                HoaDonXuatDTO hdxDTO = new HoaDonXuatDTO
                {
                    BanID             = hdx.Ban.BanID,
                    ChiNhanhID        = hdx.ChiNhanh.ChiNhanhID,
                    DaThanhToan       = hdx.DaThanhToan,
                    HinhThucThanhToan = hdx.HinhThucThanhToan,
                    HoaDonXuatID      = hdx.HoaDonXuatID,

                    NgayGio      = hdx.NgayGio,
                    TongTien     = hdx.TongTien,
                    TenKhachHang = hdx.TenKhachHang
                };
                return(Ok(hdxDTO));
            }
        }
Exemple #18
0
 public IHttpActionResult Create(HoaDonXuatDTO hoadonxuat)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Not a valid data"));
     }
     using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
     {
         HoaDonXuat hdx = new HoaDonXuat()
         {
             HoaDonXuatID      = hoadonxuat.HoaDonXuatID,
             BanID             = hoadonxuat.BanID,
             ChiNhanhID        = hoadonxuat.ChiNhanhID,
             DaThanhToan       = hoadonxuat.DaThanhToan,
             HinhThucThanhToan = hoadonxuat.HinhThucThanhToan,
             NgayGio           = DateTime.Now,
             TongTien          = hoadonxuat.TongTien,
             TenKhachHang      = hoadonxuat.TenKhachHang
         };
         entities.HoaDonXuats.Add(hdx);
         entities.SaveChanges();
         return(Ok(hdx));
     }
 }