public NhapSanPham_model(NhapSanPham nsp) { this.Id = nsp.Id; this.SoLuong = nsp.SoLuong; this.NgayNhap = nsp.NgayNhap; this.GiaNhap = nsp.GiaNhap; this.ChiNhanhId = nsp.ChiNhanh.Id; this.SanPhamId = nsp.SanPham.Id; }
public int DeleteImportProduct(int id) { int success = 0; using (var context = new BanDoDienTuEntities()) { NhapSanPham deleteimportproduct = context.NhapSanPhams.Where(mansp => mansp.MaNhap == id).FirstOrDefault(); if (deleteimportproduct != null) { context.NhapSanPhams.Remove(deleteimportproduct); success = context.SaveChanges(); } } return(success); }
public ActionResult AddImportProdutcToDatabase(FormCollection form) { using (var context = new BanDoDienTuEntities()) { NhapSanPham nsp = new NhapSanPham(); nsp.MaSP = int.Parse(form["SanPham"].ToString()); nsp.SoLuong = int.Parse(form["SoLuong"].ToString()); nsp.DonGia = int.Parse(form["DonGia"].ToString()); nsp.NgayNhap = DateTime.Parse(form["NgayNhap"].ToString()); nsp.GhiChu = form["Ghichu"].ToString(); nsp.TongTien = int.Parse(form["SoLuong"].ToString()) * int.Parse(form["DonGia"].ToString()); context.NhapSanPhams.Add(nsp); SanPham pro = context.SanPhams.ToList <SanPham>().Where(masp => masp.MaSP == int.Parse(form["SanPham"].ToString())).FirstOrDefault <SanPham>(); pro.SoLuongTrongKho += int.Parse(form["SoLuong"].ToString()); context.SaveChanges(); } return(RedirectToAction("ImportProduct")); }