private static void dependency_OnChange(object sender, SqlNotificationEventArgs e) { MyHub.Show(); }
public MyHub() { _instance = this; }
public HubLogService(MyHub hub) : base(hub) { }
public override void Execute(CliParser parser) { Setup(parser); //get all resource var resourceList = MyHub.GetAllLocalResources(); var resultStrings = new List <string>(); //check if --all is off then fielter if (!IsAll) { //if current resource is null throw if (MySession.CurrentResource == null) { throw new Exception("currently not on a legal resource"); } //check if --child, pick child if (IsChild) { foreach (var resource in resourceList) { if (resource.Key.ToLower() != MySession.CurrentPath.ToLower() && resource.Key.ToLower().StartsWith(MySession.CurrentPath.ToLower())) //is a child { if (resource.Key.Remove(0, MySession.CurrentPath.Length + 1).Contains(@"/") == false) //it's a direct child { resultStrings.Add(resource.Key); } } } } else { //just myself resultStrings.Add(MySession.CurrentPath); } } else { resultStrings.AddRange(resourceList.Select(r => r.Key)); } //check if -t is on, filter non things if (IsThings) { var toRemove = new List <string>(); foreach (string result in resultStrings) { if (MyHub.GetLocalResouce(result).ResourceType != ResourceTypes.Thing) { toRemove.Add(result); } } foreach (var item in toRemove) { resultStrings.Remove(item); } } //generate ou put, check -d is on, add detial to out put string if (IsDetail) { for (int i = 0; i < resultStrings.Count; i++) { resultStrings[i] = resultStrings[i] + "\t" + Enum.GetName(typeof(ResourceTypes), MyHub.GetLocalResouce(resultStrings[i]).ResourceType); } } //print for (int i = 0; i < resultStrings.Count; i++) { Console.WriteLine(resultStrings[i]); } if (resultStrings.Count == 0) { Console.WriteLine("No thing found!"); } }
public Logic() { MyHub myhub = new MyHub(); }
public ActionResult UploadExcel(int Type) { int location = 0; try { var file = Request.Files[0]; var filecombin = file.FileName.Split('.'); if (file == null || String.IsNullOrEmpty(file.FileName) || file.ContentLength == 0 || filecombin.Length < 2) { return(Json(new { code = "201", msg = "上传出错请检查文件名或文件内容" })); } using (ExcelPackage package = new ExcelPackage(file.InputStream)) { int count = package.Workbook.Worksheets.Count; ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; //获取表格的列数和行数 int rowCount = worksheet.Dimension.Rows; int ColCount = worksheet.Dimension.Columns; var sysAdditionalDatas = new List <SysAdditionalData>(); //插入数据 using (DataWallContext db = new DataWallContext()) { for (int row = 2; row <= rowCount; row++) { location = row; int PeopleNum = 0; int BookNum = 0; int StillPeopleNum = 0; int StillBookNum = 0; DateTime DataDatetime = DateTime.Now; switch (Type) { case 0: PeopleNum = int.Parse(worksheet.Cells[row, 3].Value.ToString()); DataDatetime = DateTime.Parse(worksheet.Cells[row, 4].Value.ToString()); break; case 1: PeopleNum = int.Parse(worksheet.Cells[row, 3].Value.ToString()); BookNum = int.Parse(worksheet.Cells[row, 4].Value.ToString()); StillPeopleNum = int.Parse(worksheet.Cells[row, 5].Value.ToString()); StillBookNum = int.Parse(worksheet.Cells[row, 6].Value.ToString()); DataDatetime = DateTime.Parse(worksheet.Cells[row, 7].Value.ToString()); break; } SysAdditionalData sysAdditionalData = new SysAdditionalData() { PeopleNum = PeopleNum, BookNum = BookNum, StillPeopleNum = StillPeopleNum, StillBookNum = StillBookNum, DataDatetime = DataDatetime, SysLibraryId = int.Parse(worksheet.Cells[row, 2].Value.ToString()), CrateTime = DateTime.Now, EditTime = DateTime.Now, DelState = 0, Type = Type }; sysAdditionalDatas.Add(sysAdditionalData); //数据检查 if (!CheckLibraryId(worksheet.Cells[row, 2].Value.ToString(), worksheet.Cells[row, 1].Value.ToString())) { return(Json(new { code = "201", msg = "场馆不存在或您没有场馆" + worksheet.Cells[row, 1].Value.ToString() + "(ID:" + worksheet.Cells[row, 2].Value.ToString() + ")" + "的数据导入权限" })); } //推送客流更新 string ToLibraryName = db.SysLibrarys.Find(sysAdditionalData.SysLibraryId).LibraryName; int type = 3; var msg = "客流数据更新"; MyHub.Show(ToLibraryName, JsonConvert.SerializeObject(new { msg = msg, action = "CustData", type = type })); } sysAdditionalDatas.ForEach(s => db.SysAdditionalDatas.Add(s)); db.SaveChanges(); } Lg.AddLog("导入额外数据", "Other", 1, GetUserName()); return(Json(new { code = "200", msg = "导入成功" })); } } catch (Exception ex) { LogHelper.ErrorLog("数据导入失败:" + ex.Message); return(Json(new { code = "201", msg = "导入失败,请检查内容格式,错误行号:" + location })); } }
private void Uploading() { while (true) { //初始无效值 uptodataShotNo = -1; uptodataCtrlVal = -255; //更新炮号,double check for (int i = 0; i < 3; i++) { try { int shotNo1 = Convert.ToInt32(myJtextEpcisClient.GetPV(config.ShotNoPvName)); int shotNo2 = Convert.ToInt32(myJtextEpcisClient.GetPV(config.ShotNoPvName)); int shotNo3 = Convert.ToInt32(myJtextEpcisClient.GetPV(config.ShotNoPvName)); if (shotNo1 == shotNo2 && shotNo2 == shotNo3) { uptodataShotNo = shotNo1; break; } } catch (Exception exc) { continue; } } if (config.IsControlPvOn) { //更新中控,double check for (int i = 0; i < 3; i++) { try { int ctrlVal1 = Convert.ToInt32(myJtextEpcisClient.GetPV(config.ControlPvName)); int ctrlVal2 = Convert.ToInt32(myJtextEpcisClient.GetPV(config.ControlPvName)); int ctrlVal3 = Convert.ToInt32(myJtextEpcisClient.GetPV(config.ControlPvName)); if (ctrlVal1 == ctrlVal2 && ctrlVal2 == ctrlVal3) { uptodataCtrlVal = ctrlVal1; break; } } catch (Exception exc) { continue; } } } if (uptodataCtrlVal == config.ControlPvValue || config.IsControlPvOn == false) { if (uptodataShotNo >= config.ShotNoLowerLimit && uptodataShotNo <= config.ShotNoUpperLimit) { MyHub.TryInvokeSampleResourceWithUri(config.CFETPathToUploadShotNo, new object[1] { uptodataShotNo }); } } Thread.Sleep(config.UploadTimeIntervalInSecond * 1000); } }
/// <summary> /// 主方法 /// </summary> /// <param name="args"></param> public static void Main(string[] args) { AutoMapperConfig.Register(); MyHub.Init(); CreateWebHostBuilder(args).Build().Run(); }
public static string fillAnswer(string bitVar) { MyHub.Answer(); return("Successful"); }
public static void Main(string[] args) { MyHub.Init(); CreateWebHostBuilder(args).Build().Run(); }
public int OtherBase(string otherBaseUri) { var otherBaseValue = (int)MyHub.TryGetResourceSampleWithUri(otherBaseUri).ObjectVal; return(Base * otherBaseValue); }
public ApiController(IPostRepository postRepository, MyHub myHub) { _postRepo = postRepository; _myHub = myHub; }
private void AddThings() { #region Nancy,ViewCopy以及Dic配置 //nancy HTTP var nancyCM = new NancyCommunicationModule(new Uri("http://*****:*****@"D:\Run\ConfigFile\DAQFamilyBucket\Dic.txt"); //Epcis EPCISThing epcis = new EPCISThing(); MyHub.TryAddThing(epcis, "/", "epcis", @"D:\Run\ConfigFile\DAQFamilyBucket\PVs.txt"); #endregion //注意,下面加了多少个卡,在左边: //解决方案资源管理器 -> CFET2App -> Views -> ViewSelector.json 中的 childpath 字段中 //就要加对应多少个卡,且名字和卡名要一样,否则网页上不能显示 //另外,卡名需要以Card开头,否则页面看不到波形 //说明在 NI 采集卡中,不同卡是类似的 #region NI采集卡,若使用NI请展开 //------------------------------NI采集卡,每增加一个采集卡要增加以下4行代码------------------------------// //这个niNonSync每张卡要不一样 var niNonSync = new AIThing(); //这个除了niNonSync不一样其余都一样 niNonSync.basicAI = new NIAI(); niNonSync.DataFileFactory = new HDF5DataFileFactory(); //这个括号里面的不一样 MyHub.TryAddThing(niNonSync, //上面的niNonSync @"/", //Thing挂载路径,都一样,不要改!!! "Card0", //卡名,也就是在网页上看到的卡名称 //下面引号中的要改,前面的是配置文件路径,后面的是采集数据保存到本地的路径 new { ConfigFilePath = @"D:\Run\ConfigFile\DAQFamilyBucket\niNonSync.txt", DataFileParentDirectory = @"D:\Data\ni\Card0" }); //var niMaster = new AIThing(); //niMaster.basicAI = new NIAI(); //niMaster.DataFileFactory = new HDF5DataFileFactory(); //MyHub.TryAddThing(niMaster, // @"/", // "Card1", // new { ConfigFilePath = @"D:\Run\ConfigFile\DAQFamilyBucket\niMaster.txt", DataFileParentDirectory = @"D:\Data\ni\Card1" }); //var niSlave = new AIThing(); //niSlave.basicAI = new NIAI(); //niSlave.DataFileFactory = new HDF5DataFileFactory(); //MyHub.TryAddThing(niSlave, // @"/", // "Card2", // new { ConfigFilePath = @"D:\Run\ConfigFile\DAQFamilyBucket\niSlave.txt", DataFileParentDirectory = @"D:\Data\ni\Card2" }); #endregion #region JY采集卡,若使用JY请展开 ////------------------------------JY采集卡,格式和NI一样------------------------------// //var jyNonSync = new AIThing(); //jyNonSync.basicAI = new JYAI(); //jyNonSync.DataFileFactory = new HDF5DataFileFactory(); //MyHub.TryAddThing(jyNonSync, // @"/", // "CardA", // new { ConfigFilePath = @"D:\Run\ConfigFile\DAQFamilyBucket\jyNonSync.txt", DataFileParentDirectory = @"D:\Data\jy\CardA" }); //var jyMaster = new AIThing(); //jyMaster.basicAI = new JYAI(); //jyMaster.DataFileFactory = new HDF5DataFileFactory(); //MyHub.TryAddThing(jyMaster, // @"/", // "CardB", // new { ConfigFilePath = @"D:\Run\ConfigFile\DAQFamilyBucket\jyMaster.txt", DataFileParentDirectory = @"D:\Data\jy\CardB" }); //var jySlave = new AIThing(); //jySlave.basicAI = new JYAI(); //jySlave.DataFileFactory = new HDF5DataFileFactory(); //MyHub.TryAddThing(jySlave, // @"/", // "CardC", // new { ConfigFilePath = @"D:\Run\ConfigFile\DAQFamilyBucket\jySlave.txt", DataFileParentDirectory = @"D:\Data\jy\CardC" }); #endregion #region NIScope采集卡,若使用NIScope请展开 //------------------------------NIScope采集卡,每增加一个采集卡要增加以下4行代码------------------------------// //var scopeNonSync = new AIThing(); //scopeNonSync.basicAI = new NIScopeAI(); //scopeNonSync.DataFileFactory = new HDF5DataFileFactory(); //MyHub.TryAddThing(scopeNonSync, // @"/", // "Cards0", // new { ConfigFilePath = @"D:\Run\ConfigFile\DAQFamilyBucket\scopeNonSync.txt", DataFileParentDirectory = @"D:\Data\ni\Cards0" }); //var scopeSlave = new AIThing(); //scopeSlave.basicAI = new NIScopeAI(); //scopeSlave.DataFileFactory = new HDF5DataFileFactory(); //MyHub.TryAddThing(scopeSlave, // @"/", // "Cards2", // new { ConfigFilePath = @"D:\Run\ConfigFile\DAQFamilyBucket\scopeSlave.txt", DataFileParentDirectory = @"D:\Data\ni\Cards2" }); //var scopeMaster = new AIThing(); //scopeMaster.basicAI = new NIScopeAI(); //scopeMaster.DataFileFactory = new HDF5DataFileFactory(); //MyHub.TryAddThing(scopeMaster, // @"/", // "Cards1", // new { ConfigFilePath = @"D:\Run\ConfigFile\DAQFamilyBucket\scopeMaster.txt", DataFileParentDirectory = @"D:\Data\ni\Cards1" }); #endregion //------------------------------自动 Arm 采集卡与发布上传事件的,只有一个这个------------------------------// var aiManagement = new AIManagementThing(); //监控EPCIS //MyHub.TryAddThing(aiManagement, @"/", "aimanagement", @"D:\Run\ConfigFile\DAQFamilyBucket\AIManagement.json"); //不监控EPCIS MyHub.TryAddThing(aiManagement, @"/", "aimanagement", @"D:\Run\ConfigFile\DAQFamilyBucket\AIManagementNoEPCIS.json"); //------------------------------上传文件的,只有一个这个------------------------------// var uploader = new DataUpLoadThing(); //前面的别改,后面的.txt路径是配置文件的完整路径 MyHub.TryAddThing(uploader, @"/", "uploader", new string[] { @"D:\Run\ConfigFile\DAQFamilyBucket\DataUploadConfig.json", @"D:\Run\ConfigFile\DAQFamilyBucket\DataUpload.csv" }); //------------------------------上传MDS的,只有一个这个------------------------------// //var mdsthing = new Jtext103.CFET2.Things.MDSUpload.MdsThing(); ////如果是 Master 用这行,注释掉下面 Slave,注意都不带后缀(因为有两个,一个.json一个.csv) //MyHub.TryAddThing(mdsthing, @"/", "mds", new string[]{ // @"D:\Run\ConfigFile\DAQFamilyBucket\MdsUploadMaster.json", // @"D:\Run\ConfigFile\DAQFamilyBucket\MdsUpload.csv" } // ); ////如果是 Slave 用这行,同时一定要将 AIManagementThing 注释掉!!! //MyHub.TryAddThing(mdsthing, @"/", "mds", new string[]{ // @"D:\Run\ConfigFile\DAQFamilyBucket\MdsUploadSlave.json", // @"D:\Run\ConfigFile\DAQFamilyBucket\MdsUpload.csv" } // ); //说明: //一键注释:选中代码并按 Ctrl+K Ctrl+C //一键解除注释:选中代码并按 Ctrl+K Ctrl+U //退程序不要点右上角的 X !输入 exit 回车退出 }
private void AddThings() { //If you don't want dynamic load things, please comment out the line below //var loader = new DynamicThingsLoader(this); //------------------------------Pipeline------------------------------// MyHub.Pipeline.AddMiddleware(new ResourceInfoMidware()); MyHub.Pipeline.AddMiddleware(new NavigationMidware()); //------------------------------Nancy HTTP通信模块------------------------------// var nancyCM = new NancyCommunicationModule(new Uri("http://*****:*****@".\ConfigFile\PVs.json"); //------------------------------模拟采集卡------------------------------// var fakeAI = new FakeAIThing(); MyHub.TryAddThing(fakeAI, "/", "fakeCard", 16); //------------------------------NI采集卡------------------------------// var niNonSync = new AIThing(); niNonSync.basicAI = new NIAI(); niNonSync.DataFileFactory = new HDF5DataFileFactory(); MyHub.TryAddThing(niNonSync, @"/", "Card0", new { ConfigFilePath = @".\ConfigFile\niNonSync.json", DataFileParentDirectory = @"D:\Data\ni\Card0" }); ////------------------------------自动 Arm 采集卡与发布上传事件------------------------------// //var aiManagement = new AIManagementThing(); //MyHub.TryAddThing(aiManagement, @"/", "aimanagement", @".\ConfigFile\AIManagement.json"); ////------------------------------上传文件的------------------------------// //var uploader = new DataUpLoadThing(); //MyHub.TryAddThing(uploader, @"/", "uploader", new string[] { // @".\ConfigFile\DataUploadConfig.json", // @".\ConfigFile\DataUpload.csv" // }); ////------------------------------上传炮号提供者------------------------------// //var dic = new DicServerThing(); //MyHub.TryAddThing(dic, "/", "dicServer", @".\ConfigFile\Dic.json"); //------------------------------文件数据服务------------------------------// var dataServer = new DataServerThing(@".\ConfigFile\BasePath.json"); dataServer.dataFileFactoty = new HDF5DataFileFactory(); MyHub.TryAddThing(dataServer, "/", "dataServer"); //------------------------------Mds数据服务------------------------------// var mdsServer = new MdsPlusReaderThing(); MyHub.TryAddThing(mdsServer, "/", "mdsServer", @".\ConfigFile\mdsServer.json"); }
public UserService(MyHub hub) : base(hub) { }
public static void Main(string[] args) { LicenseManager.AddLicense("67;100-MASUIT", "809739091397182EC1ECEA8770EB4218"); MyHub.Init(); CreateWebHostBuilder(args).Build().Run(); }
public ActionResult AdditionalDataEdit(FormCollection AdditionalData) { try { using (DataWallContext db = new DataWallContext()) { //当前用户可管理场馆 List <SysLibrary> libList = GetLibraryList(); if (libList.Count == 0) { return(Json(new { code = "202", msg = "当前用户未分配可管理场馆,请联系系统管理员!" })); } ViewData["datalist"] = libList; //额外数据 if (AdditionalData["Library"] != null) { int BookNum = 0; int StillPeopleNum = 0; int StillBookNum = 0; int LibraryId = int.Parse(AdditionalData["Library"]); string ToLibraryName = db.SysLibrarys.Find(LibraryId).LibraryName; if (AdditionalData["Type"] == "0") { BookNum = 0; StillPeopleNum = 0; StillPeopleNum = 0; int type = 3; var msg = "客流数据更新"; MyHub.Show(ToLibraryName, JsonConvert.SerializeObject(new { msg = msg, action = "Other", type = type })); } else { BookNum = int.Parse(AdditionalData["BookNum"]); StillPeopleNum = int.Parse(AdditionalData["StillPeopleNum"]); StillBookNum = int.Parse(AdditionalData["StillBookNum"]); int type = 4; var msg = "借还数据更新"; MyHub.Show(ToLibraryName, JsonConvert.SerializeObject(new { msg = msg, action = "Other", type = type })); } SysAdditionalData sysAdditionalData = new SysAdditionalData() { ID = int.Parse(AdditionalData["ID"]), PeopleNum = int.Parse(AdditionalData["PeopleNum"]), BookNum = BookNum, StillPeopleNum = StillPeopleNum, StillBookNum = StillBookNum, DataDatetime = DateTime.Parse(AdditionalData["DataDatetime"]), SysLibraryId = int.Parse(AdditionalData["Library"]), EditTime = DateTime.Now }; db.Entry(sysAdditionalData).State = EntityState.Modified; //不更新的字段 db.Entry(sysAdditionalData).Property(x => x.Type).IsModified = false; db.Entry(sysAdditionalData).Property(x => x.CrateTime).IsModified = false; db.Entry(sysAdditionalData).Property(x => x.IsEnable).IsModified = false; db.Entry(sysAdditionalData).Property(x => x.DelState).IsModified = false; db.SaveChanges(); Lg.AddLog("修改额外数据", "Other", 2, GetUserName()); return(Json(new { code = "200", msg = "修改成功!" })); } else { return(Json(new { code = "202", msg = "请选择内容所属场馆!" })); } } } catch (Exception ex) { LogHelper.ErrorLog("额外数据修改失败:" + ex.Message); return(Json(new { code = "201", msg = "修改失败,请重试或联系管理员!" })); } }
/// <summary> /// upload 1/all channels in 1 shot /// </summary> private void Upload(int localShot, int mdsShot, string localChannelDataSourceUri) { MDSplus mds = new MDSplus(); mds.Connect(myConfig.ServerConfig.Host); mds.MdsOpen(myConfig.ServerConfig.Tree, mdsShot); int status = 0; //如果没有传入 channelNo 的获取路径 if (localChannelDataSourceUri == null) { foreach (var s in myConfig.RealChannelsDic) { //利用短路,可以同时判断 null 和 false if (s.Value.Enable == false) { continue; } status = 0; //获取采样率 sampleRate = Convert.ToDouble(MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeSampleRateSrcUri(s.Value, localShot)).ObjectVal); //获取长度 length = Convert.ToInt32(MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeLengthSrcUri(s.Value, localShot)).ObjectVal); //获取开始时间 startTime = Convert.ToDouble(MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeStartTimeSrcUri(s.Value, localShot)).ObjectVal); //获取数据 data = (double[])MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeDataSrcUri(s.Value, localShot, length)).ObjectVal; //利用数据的 double数组、BUILD_SIGNAL(开始时间,总时间,1/采样率) 上传一个 Mds 的 signal 类型数据 mds.MdsPut("\\" + s.Value.Tag, "BUILD_SIGNAL($1,*,MAKE_DIM(*,$2 : $3 : $4))", data, startTime, length * 1.0 / sampleRate + startTime, 1.0 / sampleRate, ref status); } } //必定手动上传 else { try { if (myConfig.RealChannelsDic[localChannelDataSourceUri] != null && myConfig.RealChannelsDic[localChannelDataSourceUri].Enable == true) { string uri = AiRequestUriComposer.ComposeSampleRateSrcUri(myConfig.RealChannelsDic[localChannelDataSourceUri], localShot); sampleRate = Convert.ToDouble(MyHub.TryGetResourceSampleWithUri(uri).ObjectVal); length = Convert.ToInt32(MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeLengthSrcUri(myConfig.RealChannelsDic[localChannelDataSourceUri], localShot)).ObjectVal); startTime = Convert.ToDouble(MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeStartTimeSrcUri(myConfig.RealChannelsDic[localChannelDataSourceUri], localShot)).ObjectVal); data = (double[])MyHub.TryGetResourceSampleWithUri(AiRequestUriComposer.ComposeDataSrcUri(myConfig.RealChannelsDic[localChannelDataSourceUri], localShot, length)).ObjectVal; mds.MdsPut("\\" + myConfig.RealChannelsDic[localChannelDataSourceUri].Tag, "BUILD_SIGNAL($1,*,MAKE_DIM(*,$2 : $3 : $4))", data, startTime, length * 1.0 / sampleRate + startTime, 1.0 / sampleRate, ref status); } } catch { // unlock after finished lock (myStateLock) { State = Status.Idle; } logger.Error("手动上传错误!数据源:" + localChannelDataSourceUri); throw new Exception("手动上传错误!请检查相关参数设置!"); } } System.Diagnostics.Debug.WriteLine("Upload finished!", DateTime.Now.ToLocalTime().ToString("HH:mm:ss.fff")); logger.Info("上传成功!"); mds.DisConnect(); // unlock after finished lock (myStateLock) { State = Status.Idle; } if (myConfig.MasterOrSlave == 2) { Process.GetCurrentProcess().Kill(); } }
public string UploadFiles() { var httpPostedFile = HttpContext.Current.Request.Files["fileInput"];//lấy file if (httpPostedFile != null) { //đường dẫn lưu file //string temp = RandomString(10, true) + "-"; var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/Upload/"), httpPostedFile.FileName);//tên file //lưu file vào đường dẫn httpPostedFile.SaveAs(fileSavePath); } var title = HttpContext.Current.Request["title"]; var describe = HttpContext.Current.Request["describe"]; var author = HttpContext.Current.Request["author"]; var year = HttpContext.Current.Request["year"]; var userid = HttpContext.Current.Request["userid"]; var subid = HttpContext.Current.Request["subid"]; var date_upload = DateTime.Now; int user_id = Convert.ToInt32(userid); int sub_id = Convert.ToInt32(subid); string strExtexsion = Path.GetExtension(httpPostedFile.FileName).Trim();//lấy đuôi file string a = ""; if (strExtexsion == ".pdf")//chỉ cho up pdf { string temp = RandomString(10, true) + "-"; using (LibraryOnlineFinalEntities db = new LibraryOnlineFinalEntities()) { //Add vô bảng ebook db.Ebooks.Add( new Ebook { ebook_id = "", title = title, describe = describe, author = author, year = year, filename = httpPostedFile.FileName, date_upload = date_upload, user_id = user_id, sub_id = sub_id, }); db.SaveChanges();//lưu dât thôi cái này t chưa chạy t mới test gửi data từ ajax qua thôi var user = db.Users.Where(x => x.id == user_id).Select(x => x.username).FirstOrDefault(); var subject = db.Subject_Ebook.Where(x => x.id == sub_id).Select(x => x.name).FirstOrDefault(); var fileinfo = db.Ebooks.OrderByDescending(x => x.id).FirstOrDefault(); var date_up = date_upload.ToString("MM/dd/yyyy"); MyHub.PostFileEbook(fileinfo.id, fileinfo.title, fileinfo.author, fileinfo.describe, fileinfo.year, fileinfo.filename, date_up, user, subject); a = "Thành công"; } } else { a = "lỗi"; } return(a); }