public int add(DonHang obj) { //tinh toán tong tiền int sum = 0; foreach (var item in obj.ds_chitiet_donhang) { item.dongia = item.sanpham_chitiet.sanpham.gia;//for sure sum += item.dongia * item.soluong; //cập nhật tồn kho trên sản phẩm item.sanpham_chitiet.tonkho -= item.soluong; if (item.sanpham_chitiet.tonkho < 0) { item.sanpham_chitiet.tonkho = 0; } //thêm log tồn kho TonKho tk = new TonKho(); tk.ngay = obj.ngay; tk.soluong = item.sanpham_chitiet.tonkho; item.sanpham_chitiet.ds_tonkho.Add(tk); } obj.tongtien = sum; //call add this._db.ds_donhang.Add(obj); //commit this.save(); //return ma moi nhat return this._db.ds_donhang.Max(x => x.id); }
public int add(TonKho obj) { this._db.ds_tonkho.Add(obj); //commit this.save(); //return ma moi nhat return this._db.ds_tonkho.Max(x => x.id); }
public Boolean delete(TonKho obj) { try { //get entity obj = this.get_by_id(obj.id); //remove this._db.ds_tonkho.Remove(obj); //commit return this.save(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); return false; } }
public void update_tonkho(int quantity, DateTime ngay) { //set so luong this.tonkho = quantity; //them lich su ton kho TonKho tk = new TonKho(); tk.soluong = quantity; tk.ngay = ngay; this.ds_tonkho.Add(tk); }