public JsonResult Update(VideoFolder model) { if (ModelState.IsValid) { try { string json = this.superService.FindOneById<VideoFolder>(model.Id); VideoFolder record = JsonConvert.DeserializeObject<VideoFolder>(json);// SuperManager.Instance.FindOneById<VideoFolder>(model.Id); Dictionary<string, object> updates = new Dictionary<string, object>() { { "VideoType", model.VideoType }, { "DisplayName", model.DisplayName } }; // if (!record.DisplayName.Equals(model.DisplayName) && Directory.Exists(base.CurrentLoginUser().UserFolderPath + record.Path.Replace(record.DisplayName, model.DisplayName))) // return Json(new { result = false, text = "Folder is exist!", callbackapi = " " }); bool jsonResult = this.superService.UpdateFields<VideoFolder>(updates, new QueryModel("id", model.Id)); // SuperManager.Instance.UpdateById<Video>(update); //if (jsonResult && !record.DisplayName.Equals(model.DisplayName)) //{ // string path = base.CurrentLoginUser().UserFolderPath + record.Path; // RobinCore.Instance.ModifyDirectoryName(path, record.DisplayName, model.DisplayName); //} BootstrapMvc2015GitHub.Framework.Log.Instance.RecordActionLog(new System.Diagnostics.StackFrame(0).GetMethod().Name, this.ServiceKey, "Media", jsonResult); return Json(new { result = jsonResult, text = jsonResult ? "record updated successfully!" : "something was wrong!", callbackapi = "Media/Video" }); } catch (Exception ex) { BootstrapMvc2015GitHub.Framework.Log.Instance.RecordActionLog(new System.Diagnostics.StackFrame(0).GetMethod().Name, this.ServiceKey, "Media", false, ex.Message); throw ex; } } else throw new Exception("ModelState.IsValid is false"); }
public JsonResult Create(VideoFolder model) { if (ModelState.IsValid) { try { string uploadPath = base.CurrentLoginUser().UserFolderPath + "\\Video\\" + model.DisplayName; if (Directory.Exists(uploadPath)) return Json(new { result = false, text = "Folder is exist!", callbackapi = " " }); Directory.CreateDirectory(uploadPath); // model.RecordUser = base.CurrentLoginUser().UserName; model.Path = "Video\\" + model.DisplayName; // model.RecordDate = DateTime.Now; bool jsonResult = this.superService.Insert<VideoFolder>(model); //SuperManager.Instance.Create<Video>(model); BootstrapMvc2015GitHub.Framework.Log.Instance.RecordActionLog(new System.Diagnostics.StackFrame(0).GetMethod().Name, this.ServiceKey, "Media", jsonResult); return Json(new { result = jsonResult, text = jsonResult ? "One record created successfully!" : "something was wrong!", callbackapi = "Media/Video" }); } catch (Exception ex) { BootstrapMvc2015GitHub.Framework.Log.Instance.RecordActionLog(new System.Diagnostics.StackFrame(0).GetMethod().Name, this.ServiceKey, "Media", false, ex.Message); throw ex; } } else throw new Exception("ModelState.IsValid is false"); }
public Task<bool> RunS(VideoFolder videoFolder) { return Task.Run(() => { #region tongbu string basePath = DataCache.Instance.LoginUser.UserFolderPath + videoFolder.Path; string baseUrlPath = DataCache.Instance.LoginUser.UserFolderUrlPath + videoFolder.Path; //get files in folder DirectoryInfo dir = new DirectoryInfo(basePath); List<FileInfo> files = dir.GetFiles().ToList<FileInfo>(); //get data in datatable QueryModel query = new QueryModel("UploadUserName", DataCache.Instance.LoginUser.UserName); query.AddAndQuery(new QueryInfo("FolderId", "=", videoFolder.Id)); string json = UnityInstance.Instance.GetObject<ISuperService>().FindList<Video>(query); List<Video> videos = JsonConvert.DeserializeObject<List<Video>>(json);// string[] filter = new string[] { ".wmv", ".mp4" }; foreach (FileInfo file in files) { if (!filter.Contains(file.Extension.ToLower())) continue;//只加载对应格式的 Video data = videos.FirstOrDefault(item => item.FileName.Equals(file.Name)); if (data == null) { Video record = new Video() { FileName = file.Name, FolderId = videoFolder.Id, CreationTime = DateTime.Now, Evaluation = Convert.ToInt32(EvaluationType.一般), FileExtention = file.Extension.ToLower(), FilePath = "User\\" + DataCache.Instance.LoginUser.UserName + "\\" + videoFolder.Path + "\\" + file.Name, FileUrlPath = baseUrlPath + "\\" + file.Name, FileSize = file.Length, UploadDate = DateTime.Now, UploadUserDisplayName = DataCache.Instance.LoginUser.UserDisplayName, UploadUserName = DataCache.Instance.LoginUser.UserName, LastAccessTime = file.LastAccessTime }; UnityInstance.Instance.GetObject<ISuperService>().Insert<Video>(record);// SuperManager.Instance.Create<Video>(record); } else { videos.Remove(data); } } List<string> toDelete = new List<string>(); foreach (Video item in videos) { toDelete.Add(item.Id); } UnityInstance.Instance.GetObject<ISuperService>().DeleteByIds<Video>(String.Join(",", toDelete)); #endregion return true; }); }