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()); }
public IHttpActionResult CreateCTHD(ChiTietHoaDonDTO CTHDDTO) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } { ChiTietHoaDon chitiethoadon = new ChiTietHoaDon() { SanPhamID = CTHDDTO.SanPhamID, HoaDonXuatID = CTHDDTO.HoaDonXuatID, SoLuong = CTHDDTO.SoLuong }; entities.ChiTietHoaDons.Add(chitiethoadon); entities.SaveChanges(); return(Ok(CTHDDTO)); } }
// POST: api/HoaDonNhaps (Create) /** * @api {post} api/HoaDonNhaps/ Create HoaDonNhap * @apiVersion 0.1.0 * @apiName PostHoaDonNhap * @apiGroup HoaDonNhap * @apiParam {int} HoaDonNhapID Id of the HoaDonNhap. * @apiParam {int} NguyenLieuID Id of the NguyenLieu. * @apiParam {int} SoLuong Quantinty of the NguyenLieu. * @apiParam {int} ChiNhanhID Id of the ChiNhanh. * @apiParam {DateTime} NgayNhap Create day of the HoaDonNhap. * @apiParam {int} TongTienNhap Total payment the HoaDonNhap. * * @apiSuccessExample Success-Response: * HTTP/1.1 200 OK * "Created Successfully" * * @apiError HoaDonNhapNotFound The HoaDonNhap was not found. * * @apiErrorExample Error-Response: * HTTP/1.1 400 Bad Request * { * "error": "The server can not understand the request due to invalid syntax." * } */ //[ResponseType(typeof(HoaDonNhap))] public IHttpActionResult PostHoaDonNhap([FromBody] HoaDonNhap hoaDonNhap) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.HoaDonNhaps.Add(hoaDonNhap); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = hoaDonNhap.HoaDonNhapID }, hoaDonNhap)); }
public IHttpActionResult DeleteChiNhanh(int id) { ChiNhanh chiNhanh = db.ChiNhanhs.Find(id); if (chiNhanh == null) { return(NotFound()); } db.ChiNhanhs.Remove(chiNhanh); db.SaveChanges(); return(Ok(chiNhanh)); }
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()); } }
public IHttpActionResult DeleteNguyenLieu(int id) { NguyenLieu nguyenLieu = db.NguyenLieus.Find(id); if (nguyenLieu == null) { return(NotFound()); } db.NguyenLieus.Remove(nguyenLieu); db.SaveChanges(); return(Ok(nguyenLieu)); }
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")); } }
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")); } }
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)); } }
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")); }
public IHttpActionResult UpdateUser(UserDTO userDTO) { if (!ModelState.IsValid) { return(BadRequest("not a valid model")); } var user = db.Users.Where(s => s.UserName == userDTO.UserName) .FirstOrDefault(); if (user == null) { return(NotFound()); } user.FullName = userDTO.FullName; user.Email = userDTO.Email; user.NamSinh = userDTO.NamSinh; user.GioiTinh = userDTO.GioiTinh; user.DiaChi = userDTO.DiaChi; user.DienThoai = userDTO.DienThoai; db.SaveChanges(); return(Ok()); }
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)); } }