public async Task <ActionResult <ThucPham> > PostThucPham(ThucPham food) { food.ID_KM = 2; dbContext.ThucPhams.Add(food); await dbContext.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { ID_ThucPham = food.ID_ThucPham }, food)); }
private void HienThiThongTinThucPham(int id) { ThucPham x = new ThucPham(); x = food.HienThiThongTinThucPham(id); txtMaThucPham.Text = x.maTP.ToString(); txtTenThucPham.Text = x.tenTP; txtDonGia.Text = x.donGia.ToString(); }
public async Task <ActionResult <KhoHang> > PostKhoHang(KhoHang khohang) { ThucPham ThucPham = dbContext.ThucPhams.FirstOrDefault(e => e.ID_ThucPham == khohang.ID_ThucPham); khohang.TenThucPham = ThucPham.Name; dbContext.KhoHangs.Add(khohang); await dbContext.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { ID_KhoHang = khohang.ID_KhoHang }, khohang)); }
public async Task <ActionResult <ChiTietDonHang> > PostUser(ChiTietDonHang chitietdonhang) { ThucPham thucPham = dbContext.ThucPhams.FirstOrDefault(e => e.ID_ThucPham == chitietdonhang.ID_ThucPham); chitietdonhang.TenThucPham = thucPham.Name; dbContext.ChiTietDonHangs.Add(chitietdonhang); await dbContext.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { ID_ChiTiet = chitietdonhang.ID_ChiTiet }, chitietdonhang)); }
public bool ThemThucPham(ThucPham x) { try { db.ThucPhams.InsertOnSubmit(x); db.SubmitChanges(); return(true); } catch { return(false); } }
public void Put(int id, [FromBody] ThucPham food) { food.ID_KM = 2; var entity = dbContext.ThucPhams.FirstOrDefault(e => e.ID_ThucPham == id); entity.Name = food.Name; entity.LoaiThucPham = food.LoaiThucPham; entity.ID_KM = food.ID_KM; entity.GiaGoc = food.GiaGoc; entity.MoTa = food.MoTa; entity.Link_Anh = food.Link_Anh; dbContext.SaveChanges(); }
public bool XoaThucPham(int id) { try { ThucPham food = db.ThucPhams.Single(x => x.maTP == id); db.ThucPhams.DeleteOnSubmit(food); db.SubmitChanges(); return(true); } catch { return(false); } }
public bool SuaThucPham(ThucPham t) { try { ThucPham food = db.ThucPhams.Single(x => x.maTP == t.maTP); food.maLoaiTP = t.maLoaiTP; food.tenTP = t.tenTP; food.dvt = t.dvt; food.donGia = t.donGia; db.SubmitChanges(); return(true); } catch { return(false); } }
public static void Insert(ThucPham tp) { string sql = @"INSERT INTO [dbo].[thucPham] ([tenThucPham] ,[donVi] ,[soLuong] ,[tenRap] ,[giaNhap] ,[giaBan]) VALUES (@tenThucPham ,@donVi ,@soLuong ,@tenRap ,@giaNhap ,@giaBan)"; SqlParameter pr1 = new SqlParameter("@tenThucPham", SqlDbType.NVarChar); pr1.Value = tp.Ten; SqlParameter pr2 = new SqlParameter("@donVi", SqlDbType.NVarChar); pr2.Value = tp.donVi; SqlParameter pr3 = new SqlParameter("@soLuong", SqlDbType.Int); pr3.Value = tp.soLuong; SqlParameter pr5 = new SqlParameter("@tenRap", SqlDbType.NVarChar); pr5.Value = tp.Rap; SqlParameter pr6 = new SqlParameter("@giaNhap", SqlDbType.Int); pr6.Value = tp.GiaNhap; SqlParameter pr7 = new SqlParameter("@giaBan", SqlDbType.Int); pr7.Value = tp.GiaBan; DAO.ExecuteSQLWithParameters(sql, pr1, pr2, pr3, pr5, pr6, pr7); }
private void btnTaoMoi_Click(object sender, EventArgs e) { if (ValidateOfMe.ValidateOfMe.isHaveEmptyTextBox(ref panel1)) { return; } ThucPham tp = new ThucPham(); tp.Ten = txtTenThucPham.Text; tp.donVi = txtDonVi.Text; tp.soLuong = 0; tp.GiaNhap = Convert.ToInt32(txtGiaNhap.Text); tp.GiaBan = Convert.ToInt32(txtGiaBan.Text); if (tp.GiaNhap > tp.GiaBan) { MessageBox.Show("Bạn có chắc giá nhập cao hơn giá bán không???", "Chú ý", MessageBoxButtons.OK, MessageBoxIcon.Question); } tp.Rap = tenRap; DataAccess.DAOthucPham.Insert(tp); MessageBox.Show("Tạo Thành Công!!!"); }
private void btnLuu_Click(object sender, EventArgs e) { if (isADD)// nếu thêm thực phẩm { ThucPham x = new ThucPham(); x.maLoaiTP = Convert.ToInt32(cbLoaiThucPham.SelectedValue.ToString()); // x.maTP = Convert.ToInt32(txtMaThucPham.Text); x.tenTP = txtTenThucPham.Text; x.donGia = Convert.ToDecimal(txtDonGia.Text); bool success = food.ThemThucPham(x); if (success) { MessageBox.Show("Thêm thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Thêm thất bại!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else // nếu sửa thực phẩm { ThucPham x = new ThucPham(); x.maLoaiTP = Convert.ToInt32(cbLoaiThucPham.SelectedValue.ToString()); x.maTP = Convert.ToInt32(txtMaThucPham.Text); x.tenTP = txtTenThucPham.Text; x.donGia = Convert.ToDecimal(txtDonGia.Text); bool success = food.SuaThucPham(x); if (success == true) { MessageBox.Show("Sửa thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Sửa thất bại!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } EnableProject(false); HienThiDanhSachThucPhamTheoLoai(Convert.ToInt32(cbLoaiThucPham.SelectedValue)); }
public bool SuaThucPham(ThucPham x) { return(tp.SuaThucPham(x)); }
public bool ThemThucPham(ThucPham x) { return(tp.ThemThucPham(x)); }
public ThucPham Chitiet(ThucPham thucpham) { ThucPham thucPham = dbContext.ThucPhams.FirstOrDefault(e => e.ID_ThucPham == thucpham.ID_ThucPham); return(thucPham); }
public String Get(int id) { ThucPham thucPham = dbContext.ThucPhams.FirstOrDefault(e => e.ID_ThucPham == id); return(thucPham.Name); }