public HttpResponseMessage update([FromBody] RM0015 values) { using (DB db = new DB()) { result <object> rel = new result <object>(); var check = db.RM0015.SingleOrDefault(p => p.RM0015_ID == values.RM0015_ID); if (check != null) { check.ghiChu = values.ghiChu; check.ketQua = values.ketQua; check.RM0008_ID = values.RM0008_ID; check.RM0010_ID = values.RM0010_ID; check.thoiGianPhongVan = values.thoiGianPhongVan; check.trangThai = values.trangThai; check.vongPhongVan = values.vongPhongVan; check.kqChung = values.kqChung; check.ngoaingu = values.ngoaingu; check.IQ = values.IQ; try { db.SaveChanges(); db.RM0015A.RemoveRange(check.RM0015A); db.SaveChanges(); check.RM0015A = values.RM0015A; db.SaveChanges(); rel.set("OK", getallRM0015(new filter() { id = check.RM0015_ID }), "Thành công."); } catch (Exception fd) { rel.set("ERR", null, "Thất bại: " + fd.Message); } } else { rel.set("NaN", null, "Không thấy dữ liệu."); } return(rel.ToHttpResponseMessage()); } }
public HttpResponseMessage add([FromBody] addlichhen values) { using (DB db = new DB()) { results <object> list = new results <object>(); values.RM0010.ToList().ForEach(value => { result <object> rel = new result <object>(); var check = db.RM0010.SingleOrDefault(p => p.RM0010_ID == value.RM0010_ID); if (check != null) { RM0015 rm0015 = new RM0015() { RM0010_ID = value.RM0010_ID, thoiGianPhongVan = values.thoigian, trangThai = false, RM0008_ID = values.diadiem, vongPhongVan = db.RM0015.Where(p => p.RM0010_ID == value.RM0010_ID).Count() + 1, //ghiChu = "Thời gian tạo lịch hẹn" + DateTime.Now, }; db.RM0015.Add(rm0015); try { db.SaveChanges(); values.MKV9999.ToList().ForEach(mkv9999 => { RM0015A temp = new RM0015A() { MKV9999_ID = mkv9999.MKV9999_ID, RM0015_ID = rm0015.RM0015_ID, }; db.RM0015A.Add(temp); db.RM0006.Where(lk => lk.maTieuChiDG != "NS").ToList().ForEach(val => { var check3 = db.RM0007.SingleOrDefault(p => p.MKV9999_ID == mkv9999.MKV9999_ID && val.RM0006_ID == p.RM0006_ID); if (check3 == null) { db.RM0007.Add(new RM0007() { MKV9999_ID = mkv9999.MKV9999_ID, RM0006_ID = val.RM0006_ID, trangThai = true }); try { db.SaveChanges(); } catch (Exception fd) { rel.set("ERR", null, "Thất bại: " + fd.Message); } } }); }); check.trangthai = false; db.SaveChanges(); rel.set("OK", getallRM0015(new filter() { id = rm0015.RM0015_ID }), "Thành công."); }catch (Exception tr) { rel.set("ERR", null, "Thất bại: " + tr.Message); } } else { rel.set("NaN", null, "Không tìm thấy dữ liệu."); } list.add(rel); }); return(list.ToHttpResponseMessage()); } }