/// <summary> /// 创建一个附件 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="db">数据库上下文</param> /// <param name="entity">一个附件</param> /// <returns></returns> public bool Create(ref ValidationErrors validationErrors, FileUploader entity) { try { repository.Create(entity); return true; } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return false; }
/// <summary> /// Create a new FileUploader object. /// </summary> /// <param name="id">Initial value of the Id property.</param> public static FileUploader CreateFileUploader(global::System.String id) { FileUploader fileUploader = new FileUploader(); fileUploader.Id = id; return fileUploader; }
/// <summary> /// Deprecated Method for adding a new object to the FileUploader EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToFileUploader(FileUploader fileUploader) { base.AddObject("FileUploader", fileUploader); }
public ActionResult Create(FileUploader entity) { if (entity != null && ModelState.IsValid) { string currentPerson = GetCurrentPerson(); entity.CreateTime = DateTime.Now; entity.CreatePerson = currentPerson; entity.Id = Result.GetNewId(); string returnValue = string.Empty; if (m_BLL.Create(ref validationErrors, entity)) { LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",附件的信息的Id为" + entity.Id,"附件" );//写入日志 return Json(Suggestion.InsertSucceed); } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return true; }); } LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",附件的信息," + returnValue,"附件" );//写入日志 return Json(Suggestion.InsertFail + returnValue); //提示插入失败 } } return Json(Suggestion.InsertFail + ",请核对输入的数据的格式"); //提示输入的数据的格式不对 }
public ActionResult Edit(string id, FileUploader entity) { if (entity != null && ModelState.IsValid) { //数据校验 string currentPerson = GetCurrentPerson(); //entity.UpdateTime = DateTime.Now; //entity.UpdatePerson = currentPerson; string returnValue = string.Empty; if (m_BLL.Edit(ref validationErrors, entity)) { LogClassModels.WriteServiceLog(Suggestion.UpdateSucceed + ",附件信息的Id为" + id,"附件" );//写入日志 return Json(Suggestion.UpdateSucceed); //提示更新成功 } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return true; }); } LogClassModels.WriteServiceLog(Suggestion.UpdateFail + ",附件信息的Id为" + id + "," + returnValue, "附件" );//写入日志 return Json(Suggestion.UpdateFail + returnValue); //提示更新失败 } } return Json(Suggestion.UpdateFail + "请核对输入的数据的格式"); //提示输入的数据的格式不对 }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; var filde = context.Request["queueId"]; HttpPostedFile file = context.Request.Files["Filedata"]; string uploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\"; if (file != null) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } FileUploader entity = new FileUploader(); entity.Id = Common.Result.GetNewId(); //存储到服务器 file.SaveAs(uploadPath + entity.Id + file.FileName); #region 记录到数据库 entity.CreatePerson = AccountModel.GetCurrentPerson(); entity.CreateTime = DateTime.Now; entity.Id = Common.Result.GetNewId(); string returnValue = string.Empty; IFileUploaderBLL m_BLL = new FileUploaderBLL(); Common.ValidationErrors validationErrors = new Common.ValidationErrors(); entity.Size = file.ContentLength; entity.Suffix = file.FileName.Substring(file.FileName.IndexOf('.') + 1); entity.Path = uploadPath; entity.FullPath = uploadPath + file.FileName; entity.Name = file.FileName; if (m_BLL.Create(ref validationErrors, entity)) {//下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失 context.Response.Write(entity.Id); LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",附件的信息的Id为" + entity.Id, "附件" );//写入日志 } else {//下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失 context.Response.Write("0"); if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return true; }); } LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",附件的信息," + returnValue, "附件" );//写入日志 } #endregion } else { context.Response.Write("0"); } }