public int Update(int RouteId, int PortalId, int ContentItemId, string CultureCode, string RouteName, string RouteUrl, string PhysicalFile, bool CheckPhysicalUrlAccess, string RouteValueDictionary, string Description, bool Discontinued) { int i = 0; using (CommonEntities dbContext = new CommonEntities()) { using (System.Transactions.TransactionScope transcope = new System.Transactions.TransactionScope()) { dbContext.Connection.Open(); aspnet_Routes entity = dbContext.aspnet_Routes.Single(x => x.RouteId == RouteId); entity.PortalId = PortalId; entity.ContentItemId = ContentItemId; entity.CultureCode = CultureCode; entity.RouteName = RouteName; entity.RouteUrl = RouteUrl; entity.PhysicalFile = PhysicalFile; entity.CheckPhysicalUrlAccess = CheckPhysicalUrlAccess; entity.RouteValueDictionary = RouteValueDictionary; entity.Description = Description; entity.Discontinued = Discontinued; i = dbContext.SaveChanges(); dbContext.Connection.Close(); transcope.Complete(); } } return(i); }
////INSERT- UPDATE - DELETE public int Insert(int PortalId, int ContentItemId, string CultureCode, string RouteName, string RouteUrl, string PhysicalFile, bool CheckPhysicalUrlAccess, string RouteValueDictionary, string Description, bool Discontinued) { int returnValue = 0; using (CommonEntities dbContext = new CommonEntities()) { using (System.Transactions.TransactionScope transcope = new System.Transactions.TransactionScope()) { int ListOrder = (from u in dbContext.aspnet_Routes select u.ListOrder).DefaultIfEmpty(0).Max() + 1; aspnet_Routes entity = new aspnet_Routes(); entity.PortalId = PortalId; entity.ContentItemId = ContentItemId; entity.CultureCode = CultureCode; entity.RouteName = RouteName; entity.RouteUrl = RouteUrl; entity.PhysicalFile = PhysicalFile; entity.CheckPhysicalUrlAccess = CheckPhysicalUrlAccess; entity.RouteValueDictionary = RouteValueDictionary; entity.Description = Description; entity.ListOrder = ListOrder; entity.Discontinued = Discontinued; dbContext.AddToaspnet_Routes(entity); returnValue = dbContext.SaveChanges(); dbContext.Connection.Close(); transcope.Complete(); } } return(returnValue); }
/// <summary> /// 添加 /// </summary> /// <param name="entity">数据实体</param> /// <returns>实体</returns> public T InsertReturnEntity <T>(T entity) where T : class { using (CommonEntities db = new CommonEntities()) { db.Entry <T>(entity).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); return(entity); } }
public int UpdateSortKey(int RouteId, int ListOrder) { using (CommonEntities dbContext = new CommonEntities()) { dbContext.CommandTimeout = Settings.CommandTimeout; aspnet_Routes album_obj = dbContext.aspnet_Routes.Single(x => x.RouteId == RouteId); album_obj.ListOrder = ListOrder; int i = dbContext.SaveChanges(); return(i); } }
public int UpdateStatus(int RouteId, bool Discontinued) { using (CommonEntities dbContext = new CommonEntities()) { dbContext.CommandTimeout = Settings.CommandTimeout; aspnet_Routes entity = dbContext.aspnet_Routes.Single(x => x.RouteId == RouteId); entity.Discontinued = Discontinued; int i = dbContext.SaveChanges(); return(i); } }
public static void Delete(int RouteId) { using (CommonEntities dbContext = new CommonEntities()) { using (System.Transactions.TransactionScope transcope = new System.Transactions.TransactionScope()) { dbContext.Connection.Open(); aspnet_Routes entity = dbContext.aspnet_Routes.Single(x => x.RouteId == RouteId); dbContext.aspnet_Routes.DeleteObject(entity); dbContext.SaveChanges(); dbContext.Connection.Close(); transcope.Complete(); } } }
/// <summary> /// 修改 /// </summary> /// <param name="entity">实体数据</param> /// <returns>布尔值(修改结果)</returns> public bool Update <T>(T entity) where T : class { bool result = false; using (CommonEntities db = new CommonEntities()) { db.Entry <T>(entity).State = System.Data.Entity.EntityState.Modified; try { db.SaveChanges(); result = true; } catch (Exception) { result = false; } } return(result); }
/// <summary> /// 添加 /// </summary> /// <param name="entity">数据实体</param> /// <returns>布尔值</returns> public bool Insert(T entity) { bool result = false; using (CommonEntities db = new CommonEntities()) { db.Entry <T>(entity).State = System.Data.Entity.EntityState.Added; try { db.SaveChanges(); result = true; } catch (Exception) { result = false; } return(result); } }
/// <summary> /// 添加集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public bool InsertIQueryable <T>(List <T> lstentity) where T : class { bool result = false; using (CommonEntities db = new CommonEntities()) { foreach (var item in lstentity) { db.Entry <T>(item).State = System.Data.Entity.EntityState.Added; } try { db.SaveChanges(); result = true; } catch (Exception) { result = false; } return(result); } }
/// <summary> /// 删除集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public bool DeleteIQueryable(List <T> entity) { bool result = false; using (CommonEntities db = new CommonEntities()) { foreach (var item in entity) { db.Entry <T>(item).State = System.Data.Entity.EntityState.Deleted; } try { db.SaveChanges(); result = true; } catch (Exception) { result = false; } return(result); } }