public int Insert(T_FileInfo entity) { using (var dbContext = new DuPont_TestContext()) { try { dbContext.T_FileInfo.Add(entity); return(dbContext.SaveChanges()); } catch (DbEntityValidationException dbEx) { var sbMessage = new StringBuilder("【EF错误】:\r\n"); if (dbEx.EntityValidationErrors != null) { foreach (var error in dbEx.EntityValidationErrors) { foreach (var errorChild in error.ValidationErrors) { sbMessage.AppendLine(string.Format("{0}:{1}", errorChild.PropertyName, errorChild.ErrorMessage)); } } } throw new Exception(sbMessage.ToString()); } } }
private string Delete(HttpContext context) { try { int Id = 0; try { Id = int.Parse(context.Request.QueryString["Id"]); } catch { } T_FileInfo file = GetById(context); try { string fp = HttpContext.Current.Server.MapPath("~/files/" + file.FilePath); File.Delete(fp); } catch { } if (dal.Delete(Id)) { return("删除操作成功!"); } else { return("删除操作失败,错误代码:500 "); } } catch { return("Error 500"); } }
public int Delete(T_FileInfo entity) { if (entity != null) { using (var dbContext = new DuPont_TestContext()) { dbContext.T_FileInfo.Remove(entity); return(dbContext.SaveChanges()); } } return(0); }
public int Update(T_FileInfo entity) { using (var dbContext = new DuPont_TestContext()) { var dbEntry = dbContext.T_FileInfo.Find(entity.Id); if (dbEntry != null) { ClassValueCopyHelper.Copy(dbEntry, entity); return(dbContext.SaveChanges()); } } return(0); }
private T_FileInfo GetModel(HttpContext context) { T_FileInfo model = new T_FileInfo(); try { model.Id = int.Parse(context.Request.Form["Id"].ToString()); } catch { } model.FileName = context.Request.Form["FileName"].ToString(); HttpPostedFile hf = HttpContext.Current.Request.Files[0];//获取上传图片对象 model.FileTypeSuffix = Path.GetExtension(hf.FileName); try { model.FileTypeName = int.Parse(context.Request.Form["FileTypeName"].ToString()); } catch { } model.FilePath = new UpLoad().UpLoadFile("~/files/"); model.Editor = admin.AdminLogName; return(model); }
/// <summary> /// /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Update(T_FileInfo model) { try { object[] obj = { model.FileName, model.FileTypeSuffix, model.FileTypeName, model.FilePath, model.Editor, model.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"), model.Id }; string strSql = string.Format(" update [T_FileInfo] set [FileName] = '{0}',[FileTypeSuffix] = '{1}',[FileTypeName] = {2},[FilePath] = '{3}',[Editor] = '{4}',[CreateDate] ='{5}' where Id= {6} ", obj); if (DbHelper.Factory().ExecuteNonQuery(strSql) > 0) { return(true); } else { return(false); } } catch { return(false); } }
/// <summary> /// /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Create(T_FileInfo model) { try { object[] obj = { model.FileName, model.FileTypeSuffix, model.FileTypeName, model.FilePath, model.Editor, model.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") }; string strSql = string.Format("insert into [T_FileInfo]([FileName],[FileTypeSuffix],[FileTypeName],[FilePath],[Editor],[CreateDate]) values('{0}','{1}',{2},'{3}','{4}','{5}')", obj); if (DbHelper.Factory().ExecuteNonQuery(strSql) > 0) { return(true); } else { return(false); } } catch { return(false); } }
public T_FileInfo GetModel(int id) { T_FileInfo model = null; string strSql = string.Format("select [Id],[FileName],[FileTypeSuffix],[FileTypeName],[FilePath],[Editor],[CreateDate] from [T_FileInfo] where Id= {0}", id); using (dynamic read = DbHelper.Factory().ExecuteReader(strSql)) { model = new T_FileInfo(); if (read.Read()) { try { model.Id = int.Parse(read["Id"].ToString()); } catch { } model.FileName = read["FileName"].ToString(); model.FileTypeSuffix = read["FileTypeSuffix"].ToString(); try { model.FileTypeName = int.Parse(read["FileTypeName"].ToString()); } catch { } model.FilePath = read["FilePath"].ToString(); model.Editor = read["Editor"].ToString(); model.CreateDate = DateTime.Parse(read["CreateDate"].ToString()); } read.Dispose(); } return(model); }