public JsonResult Edit(string c, tb_WMS_PhieuNhap PhieuNhap, tb_WMS_ChiTietPhieuNhap ChiTiet, tb_WMS_IMEI Imeis) { if (c != "[]") { JArray jsonArray = JArray.Parse(c); var jsonObjects = jsonArray.OfType <JObject>().ToList(); var idphieu = int.Parse(jsonObjects[0]["idphieu"].ToString()); var tongtien = int.Parse(jsonObjects[0]["tongtien"].ToString().Replace(",", "")); var tongsoluong = int.Parse(jsonObjects[0]["tongsoluong"].ToString()); var ghichu = jsonObjects[0]["ghichu"].ToString(); var phieunhap = (from N in _context.tb_WMS_PhieuNhap where N.ID == idphieu select N).FirstOrDefault(); phieunhap.TongTien = tongtien; phieunhap.SoLuong = tongsoluong; phieunhap.GhiChu = ghichu; _context.Update(phieunhap); _context.SaveChanges(); var chitiet = (from N in _context.tb_WMS_ChiTietPhieuNhap where N.IDPN == idphieu select N).ToArray(); foreach (var item in chitiet) { _context.Remove(item); _context.SaveChanges(); } var q = jsonObjects.Count(); for (var h = 0; h < q; h++) { var idend_chitiet = (from u in _context.tb_WMS_ChiTietPhieuNhap orderby u.ID descending select u.ID).Take(1).FirstOrDefault(); var dg = int.Parse(jsonObjects[h]["dongia"].ToString().Replace(",", "")); var ma = int.Parse(jsonObjects[h]["ma"].ToString()); var soluong = int.Parse(jsonObjects[h]["soluong"].ToString()); var thanhtien = int.Parse(jsonObjects[h]["thanhtien"].ToString().Replace(",", "")); var idpn = idphieu; var imeis = jsonObjects[h]["imei"].ToString(); ChiTiet.Imei = imeis; ChiTiet.IDPN = idpn; ChiTiet.IDPBSP = ma; ChiTiet.SoLuong = soluong; ChiTiet.ThanhTien = thanhtien; ChiTiet.DonGia = dg; ChiTiet.ID = idend_chitiet + 1; _context.tb_WMS_ChiTietPhieuNhap.Add(ChiTiet); _context.SaveChanges(); } return(Json(idphieu)); } else { return(Json("")); } }
public JsonResult Save(string c, tb_WMS_PhieuNhap phieuNhap, tb_WMS_ChiTietPhieuNhap ChiTiet) { if (c != "[]") { var idend = (from u in _context.tb_WMS_PhieuNhap orderby u.ID descending select u.ID).Take(1).FirstOrDefault(); var nhanvien = int.Parse(@User.FindFirst("IdNV").Value); JArray jsonArray = JArray.Parse(c); var jsonObjects = jsonArray.OfType <JObject>().ToList(); var kho = int.Parse(jsonObjects[0]["kho"].ToString()); var nhacungcap = int.Parse(jsonObjects[0]["nhacungcap"].ToString()); var tongtien = int.Parse(jsonObjects[0]["tongtien"].ToString().Replace(",", "")); var tongsoluong = int.Parse(jsonObjects[0]["tongsoluong"].ToString()); var ghichu = jsonObjects[0]["ghichu"].ToString(); phieuNhap.IDKho = kho; phieuNhap.IDNCC = nhacungcap; phieuNhap.SoLuong = tongsoluong; phieuNhap.TongTien = tongtien; DateTime date = DateTime.Now; phieuNhap.NgayLap = date; phieuNhap.MaPhieuNhap = "CE" + (idend + 1); phieuNhap.ID = idend + 1; phieuNhap.TrangThai = 0; phieuNhap.IDNV = nhanvien; phieuNhap.GhiChu = ghichu; _context.tb_WMS_PhieuNhap.Add(phieuNhap); _context.SaveChanges(); var q = jsonObjects.Count(); for (var h = 0; h < q; h++) { var idend_chitiet = (from u in _context.tb_WMS_ChiTietPhieuNhap orderby u.ID descending select u.ID).Take(1).FirstOrDefault(); var dg = int.Parse(jsonObjects[h]["dongia"].ToString().Replace(",", "")); var ma = int.Parse(jsonObjects[h]["ma"].ToString()); var soluong = int.Parse(jsonObjects[h]["soluong"].ToString()); var thanhtien = int.Parse(jsonObjects[h]["thanhtien"].ToString().Replace(",", "")); var idpn = idend + 1; var imeis = jsonObjects[h]["imei"].ToString(); ChiTiet.Imei = imeis; ChiTiet.IDPN = idpn; ChiTiet.IDPBSP = ma; ChiTiet.SoLuong = soluong; ChiTiet.ThanhTien = thanhtien; ChiTiet.DonGia = dg; ChiTiet.ID = idend_chitiet + 1; _context.tb_WMS_ChiTietPhieuNhap.Add(ChiTiet); _context.SaveChanges(); } return(Json(idend + 1)); } else { return(Json("")); } }