public bool DeleteAdvertisement(int systemId, string companyId, string advertisementId) { try { int intnum = 0; var dbContext = new DAL.BaseDAL(LdCmsDbEntitiesContext); using (var db = dbContext.DbEntities()) { using (var trans = db.Database.BeginTransaction()) { try { dbContext.Delete <Ld_Extend_Advertisement>(m => m.SystemID == systemId && m.CompanyID == companyId && m.AdvertisementID == advertisementId); dbContext.Delete <Ld_Extend_AdvertisementDetails>(m => m.SystemID == systemId && m.CompanyID == companyId && m.AdvertisementID == advertisementId); intnum = db.SaveChanges(); trans.Commit(); } catch (Exception) { trans.Rollback(); } return(intnum > 0); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
public List <CountSearchKeywordByKeywordResult> CountSearchKeywordByKeyword(int systemId, string companyId, int count) { try { int total = GetTopTotal(count); var expression = ExtLinq.True <Ld_Extend_SearchKeyword>(); expression = expression.And(m => m.SystemID == systemId && m.CompanyID == companyId); var dbContext = new DAL.BaseDAL(LdCmsDbEntitiesContext); var db = dbContext.DbEntities(); var lists = db.Ld_Extend_SearchKeyword.Where(expression) .GroupBy(m => m.Keyword).Select(m => new { ID = m.Max(x => x.ID), Keyword = m.Key, Total = m.Count(), MinDate = m.Min(x => x.CreateDate), MaxDate = m.Max(x => x.CreateDate) }).Take(total).ToList(); return(lists.ToJson().ToObject <List <CountSearchKeywordByKeywordResult> >()); } catch (Exception ex) { throw new Exception(ex.Message); } }
public int SaveTable(Log_Table entity, List <Log_TableDetails> list) { try { try { string tableName = entity.TableName; if (IsTableByName(tableName)) { throw new Exception("表名已存在!"); } int intnum = 0; var dbContext = new DAL.BaseDAL(CTMSContext); using (var db = dbContext.DbEntities()) { // using (var trans = db.Database.BeginTransaction()) // { // try // { // entity.CreateDate = DateTime.Now; // db.Add(entity); // foreach (var m in list) // { // m.CreateDate = DateTime.Now; // db.Add(m); // } // intnum = db.SaveChanges(); // trans.Commit(); // } // catch (Exception) // { // trans.Rollback(); // } // return intnum; // } db.Orm.Transaction(() => { entity.CreateDate = DateTime.Now; db.Add(entity); foreach (var m in list) { m.CreateDate = DateTime.Now; db.Add(m); } intnum = db.SaveChanges(); }); return(intnum); } } catch (Exception ex) { throw new Exception(ex.Message); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public List <CountSearchKeywordByKeywordResult> CountSearchKeywordByKeyword(int systemId, string companyId, string startTime, string endTime, string keyword, int count) { try { DateTime dateStartTime = Utility.ToStartTime(startTime); DateTime dateEndTime = Utility.ToEndTime(endTime); int total = Utility.ToTopTotal(count); //条件 var expression = ExtLinq.True <Extend_SearchKeyword>(); expression = expression.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.CreateDate.Value.Date >= dateStartTime.Date && m.CreateDate.Value.Date <= dateEndTime.Date && (m.Keyword.Contains(keyword))); //执行 var dbContext = new DAL.BaseDAL(CTMSContext); var db = dbContext.DbEntities(); var lists = db.Extend_SearchKeyword .Where(expression) .ToList() .GroupBy(m => m.Keyword).Select(m => new { ID = m.Max(x => x.ID), Keyword = m.Key, Total = m.Count(), MinDate = m.Min(x => x.CreateDate), MaxDate = m.Max(x => x.CreateDate) }).Take(count).ToList(); return(lists.ToJson().ToObject <List <CountSearchKeywordByKeywordResult> >()); } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool SaveAdvertisement(Ld_Extend_Advertisement entity, List <Ld_Extend_AdvertisementDetails> lists) { try { var advertisement = PrimaryKeyHelper.PrimaryKeyType.ExtendAdvertisement; var advertisementDetails = PrimaryKeyHelper.PrimaryKeyType.ExtendAdvertisementDetails; var version = PrimaryKeyHelper.PrimaryKeyLen.V1; string advertisementId = PrimaryKeyHelper.MakePrimaryKey(advertisement, version); entity.AdvertisementID = advertisementId; entity.Sort = entity.Sort.ToInt(); entity.State = entity.State.ToBool(); entity.CreateDate = DateTime.Now; if (lists == null) { throw new Exception("广告列表不能为空!"); } List <Ld_Extend_AdvertisementDetails> details = new List <Ld_Extend_AdvertisementDetails>(); foreach (var m in lists) { string advertisementDetailsId = PrimaryKeyHelper.MakePrimaryKey(advertisementDetails, version); m.SystemID = entity.SystemID; m.CompanyID = entity.CompanyID; m.DetailsID = advertisementDetailsId; m.AdvertisementID = advertisementId; m.Sort = m.Sort.ToInt(); m.State = m.State.ToBool(); m.CreateDate = DateTime.Now; details.Add(m); } int intnum = 0; var dbContext = new DAL.BaseDAL(LdCmsDbEntitiesContext); using (var db = dbContext.DbEntities()) { using (var trans = db.Database.BeginTransaction()) { try { dbContext.Add(entity); dbContext.Add(details); intnum = db.SaveChanges(); trans.Commit(); } catch (Exception) { trans.Rollback(); } return(intnum > 0); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
public int DeleteClass(int systemId, string companyId, string classId) { try { var expressionPage = ExtLinq.True <Info_Page>(); var expressionClass = ExtLinq.True <Info_Class>(); var expressionPageFindByClassId = expressionPage.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.ClassID == classId); var expressionClassFind = expressionClass.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.ClassID == classId); var expressionClassFindByParentId = expressionClass.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.ParentID == classId); if (IsExists(expressionClassFindByParentId)) { throw new Exception("分类、栏目还有下级栏目不能删除!"); } var entity = Find(expressionClassFind); int classType = entity.ClassType.ToInt(); int intnum = 0; var dbContext = new DAL.BaseDAL(CTMSContext); using (var db = dbContext.DbEntities()) { //using (var trans = db.Database.BeginTransaction()) //{ // try // { // if (classType == 1) // dbContext.Delete(expressionPageFindByClassId); // dbContext.Delete(expressionClassFind); // intnum = db.SaveChanges(); // trans.Commit(); // } // catch (Exception) // { // trans.Rollback(); // } // return intnum; //} db.Orm.Transaction(() => { if (classType == 1) { dbContext.Delete(expressionPageFindByClassId); } dbContext.Delete(expressionClassFind); intnum = db.SaveChanges(); }); return(intnum); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public int MediaInterface(string appId, List <Basics_Media> lists) { try { if (lists == null) { throw new Exception("写入列表不能为空!"); } lists.ForEach(m => { m.State = true; m.CreateDate = DateTime.Now; }); List <Basics_MediaInterface> listMediaInterface = new List <Basics_MediaInterface>(); foreach (var m in lists) { listMediaInterface.Add(new Basics_MediaInterface() { SystemID = m.SystemID, CompanyID = m.CompanyID, MediaID = m.MediaID, AppID = appId }); } int intnum = 0; var dbContext = new DAL.BaseDAL(CTMSContext); using (var db = dbContext.DbEntities()) { //using (var trans = db.Database.BeginTransaction()) //{ // try // { // dbContext.Add(lists); // dbContext.Add(listMediaInterface); // intnum = db.SaveChanges(); // trans.Commit(); // } // catch (Exception) // { // trans.Rollback(); // } // return intnum; //} db.Orm.Transaction(() => { dbContext.Add(lists); dbContext.Add(listMediaInterface); intnum = db.SaveChanges(); }); return(intnum); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public int MediaInterface(string appId, Basics_Media entity) { try { int systemId = entity.SystemID; string companyId = entity.CompanyID; string mediaId = entity.MediaID; entity.State = true; entity.CreateDate = DateTime.Now; var mediaInterface = new Basics_MediaInterface() { SystemID = systemId, CompanyID = companyId, MediaID = mediaId, AppID = appId }; int intnum = 0; var dbContext = new DAL.BaseDAL(CTMSContext); using (var db = dbContext.DbEntities()) { //using (var trans = db.Database.BeginTransaction()) //{ // try // { // db.Add(entity); // db.Add(mediaInterface); // intnum = db.SaveChanges(); // trans.Commit(); // } // catch (Exception) // { // trans.Rollback(); // } // return intnum; //} db.Orm.Transaction(() => { db.Add(entity); db.Add(mediaInterface); intnum = db.SaveChanges(); }); return(intnum); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public int DeleteAccountAll(int systemId, string companyId, string memberId) { try { var entity = GetAccount(systemId, companyId, memberId); if (entity == null) { throw new Exception("会员ID不存在!"); } var expressionAddress = ExtLinq.True <Member_Address>(); expressionAddress = expressionAddress.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.MemberID == memberId); var expressionInvoice = ExtLinq.True <Member_Invoice>(); expressionInvoice = expressionInvoice.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.MemberID == memberId); int intnum = 0; var dbContext = new DAL.BaseDAL(CTMSContext); using (var db = dbContext.DbEntities()) { //using (var trans = db.Database.BeginTransaction()) //{ // try // { // dbContext.Delete(expressionAddress); // dbContext.Delete(expressionInvoice); // db.Set<Member_Account>().Remove(entity); // intnum = db.SaveChanges(); // trans.Commit(); // } // catch (Exception) // { // trans.Rollback(); // } // return intnum; //} db.Orm.Transaction(() => { dbContext.Delete(expressionAddress); dbContext.Delete(expressionInvoice); db.Set <Member_Account>().Remove(entity); intnum = db.SaveChanges(); }); return(intnum); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public int SaveTable(Ld_Log_Table entity, List <Ld_Log_TableDetails> list) { try { try { string tableName = entity.TableName; if (IsTableByName(tableName)) { throw new Exception("表名已存在!"); } int intnum = 0; var dbContext = new DAL.BaseDAL(LdCmsDbEntitiesContext); using (var db = dbContext.DbEntities()) { using (var trans = db.Database.BeginTransaction()) { try { entity.CreateDate = DateTime.Now; db.Add(entity); foreach (var m in list) { m.CreateDate = DateTime.Now; db.Add(m); } intnum = db.SaveChanges(); trans.Commit(); } catch (Exception) { trans.Rollback(); } return(intnum); } } } catch (Exception ex) { throw new Exception(ex.Message); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public int SaveMediaMember(string memberId, List <Ld_Basics_Media> lists) { try { if (lists == null) { throw new Exception("写入列表不能为空!"); } lists.ForEach(m => { m.State = true; m.CreateDate = DateTime.Now; }); List <Ld_Basics_MediaMember> listMediaMember = new List <Ld_Basics_MediaMember>(); foreach (var m in lists) { listMediaMember.Add(new Ld_Basics_MediaMember() { SystemID = m.SystemID, CompanyID = m.CompanyID, MediaID = m.MediaID, MemberID = memberId }); } int intnum = 0; var dbContext = new DAL.BaseDAL(LdCmsDbEntitiesContext); using (var db = dbContext.DbEntities()) { using (var trans = db.Database.BeginTransaction()) { try { dbContext.Add(lists); dbContext.Add(listMediaMember); intnum = db.SaveChanges(); trans.Commit(); } catch (Exception) { trans.Rollback(); } return(intnum); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
public int MediaInterface(string appId, Ld_Basics_Media entity) { try { int systemId = entity.SystemID; string companyId = entity.CompanyID; string mediaId = entity.MediaID; entity.State = true; entity.CreateDate = DateTime.Now; var mediaInterface = new Ld_Basics_MediaInterface() { SystemID = systemId, CompanyID = companyId, MediaID = mediaId, AppID = appId }; int intnum = 0; var dbContext = new DAL.BaseDAL(LdCmsDbEntitiesContext); using (var db = dbContext.DbEntities()) { using (var trans = db.Database.BeginTransaction()) { try { db.Add(entity); db.Add(mediaInterface); intnum = db.SaveChanges(); trans.Commit(); } catch (Exception) { trans.Rollback(); } return(intnum); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool DeleteAdvertisement(int systemId, string companyId, string advertisementId) { try { var expressionAdvertisement = ExtLinq.True <Extend_Advertisement>(); expressionAdvertisement = expressionAdvertisement.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.AdvertisementID == advertisementId); var expressionAdvertisementDetails = ExtLinq.True <Extend_AdvertisementDetails>(); expressionAdvertisementDetails = expressionAdvertisementDetails.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.AdvertisementID == advertisementId); int intnum = 0; var dbContext = new DAL.BaseDAL(CTMSContext); using (var db = dbContext.DbEntities()) { //using (var trans = db.Database.BeginTransaction()) //{ // try // { // dbContext.Delete(expressionAdvertisement); // dbContext.Delete(expressionAdvertisementDetails); // intnum = db.SaveChanges(); // trans.Commit(); // } // catch (Exception) // { // trans.Rollback(); // } // return intnum > 0; //} db.Orm.Transaction(() => { dbContext.Delete(expressionAdvertisement); dbContext.Delete(expressionAdvertisementDetails); intnum = db.SaveChanges(); }); return(intnum > 0); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public List <Ld_Extend_SearchKeyword> GetSearchKeyword(int systemId, string companyId, int count) { try { var expression = ExtLinq.True <Ld_Extend_SearchKeyword>(); expression = expression.And(m => m.SystemID == systemId && m.CompanyID == companyId); var dbContext = new DAL.BaseDAL(LdCmsDbEntitiesContext); var db = dbContext.DbEntities(); return(db.Ld_Extend_SearchKeyword.Where(expression) .OrderByDescending(m => m.IsTop) .ThenByDescending(m => m.ID) .Take(count) .ToList()); } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool UpdateTableDetailsPrimaryKey(long id, bool isPrimaryKey) { try { var entity = GetTableDetails(id); if (entity == null) { throw new Exception("table details id invalid!"); } string tableId = entity.TableID; int intnum = 0; var dbContext = new DAL.BaseDAL(CTMSContext); using (var db = dbContext.DbEntities()) { //using (var trans = db.Database.BeginTransaction()) //{ // try // { // entity.IsPrimaryKey = isPrimaryKey; // dbContext.Update(entity); // List<string> arrPrimaryKey = new List<string>(); // var lists = dbContext.FindList<Log_TableDetails>(m => m.TableID == tableId & m.IsPrimaryKey == true); // if (isPrimaryKey) // { // var entityDetails = dbContext.Find<Log_TableDetails>(m => m.ID == id); // arrPrimaryKey.Add(entityDetails.ColumnName); // } // var listDetails = from m in lists where !isPrimaryKey ? m.ID != id : true select m; // foreach (var m in listDetails) // arrPrimaryKey.Add(m.ColumnName); // var table = dbContext.Find<Log_Table>(m => m.TableID == tableId); // string strPrimaryKey = string.Empty; // foreach (var m in arrPrimaryKey.OrderBy(i => i).ToList()) // strPrimaryKey += string.IsNullOrWhiteSpace(strPrimaryKey) ? m : string.Format(",{0}", m); // table.PrimaryKey = strPrimaryKey; // dbContext.Update(table); // intnum = db.SaveChanges(); // trans.Commit(); // } // catch (Exception) // { // trans.Rollback(); // } // return intnum > 0; //} db.Orm.Transaction(() => { entity.IsPrimaryKey = isPrimaryKey; dbContext.Update(entity); List <string> arrPrimaryKey = new List <string>(); var lists = dbContext.FindList <Log_TableDetails>(m => m.TableID == tableId & m.IsPrimaryKey == true); if (isPrimaryKey) { var entityDetails = dbContext.Find <Log_TableDetails>(m => m.ID == id); arrPrimaryKey.Add(entityDetails.ColumnName); } var listDetails = from m in lists where !isPrimaryKey ? m.ID != id : true select m; foreach (var m in listDetails) { arrPrimaryKey.Add(m.ColumnName); } var table = dbContext.Find <Log_Table>(m => m.TableID == tableId); string strPrimaryKey = string.Empty; foreach (var m in arrPrimaryKey.OrderBy(i => i).ToList()) { strPrimaryKey += string.IsNullOrWhiteSpace(strPrimaryKey) ? m : string.Format(",{0}", m); } table.PrimaryKey = strPrimaryKey; dbContext.Update(table); intnum = db.SaveChanges(); //trans.Commit(); }); return(intnum > 0); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool UpdateAdvertisement(Extend_Advertisement entity, List <Extend_AdvertisementDetails> lists) { try { var advertisementDetails = PrimaryKeyHelper.PrimaryKeyType.ExtendAdvertisementDetails; var version = PrimaryKeyHelper.PrimaryKeyLen.V1; int systemId = entity.SystemID; string companyId = entity.CompanyID; string advertisementId = entity.AdvertisementID; entity.Sort = entity.Sort.ToInt(); entity.State = entity.State.ToBool(); entity.CreateDate = DateTime.Now; if (lists == null) { throw new Exception("广告列表不能为空!"); } List <Extend_AdvertisementDetails> details = new List <Extend_AdvertisementDetails>(); foreach (var m in lists) { string advertisementDetailsId = PrimaryKeyHelper.MakePrimaryKey(advertisementDetails, version); m.SystemID = entity.SystemID; m.CompanyID = entity.CompanyID; m.DetailsID = advertisementDetailsId; m.AdvertisementID = advertisementId; m.Sort = m.Sort.ToInt(); m.State = m.State.ToBool(); m.CreateDate = DateTime.Now; details.Add(m); } var expression = ExtLinq.True <Extend_AdvertisementDetails>(); expression = expression.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.AdvertisementID == advertisementId); int intnum = 0; var dbContext = new DAL.BaseDAL(CTMSContext); using (var db = dbContext.DbEntities()) { //using (var trans = db.Database.BeginTransaction()) //{ // try // { // dbContext.Update(entity); // dbContext.Delete(expression); // dbContext.Add(details); // intnum = db.SaveChanges(); // trans.Commit(); // } // catch (Exception) // { // trans.Rollback(); // } // return intnum > 0; //} db.Orm.Transaction(() => { dbContext.Update(entity); dbContext.Delete(expression); dbContext.Add(details); intnum = db.SaveChanges(); }); return(intnum > 0); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool SaveClass(Info_Class entity) { try { var infoClass = PrimaryKeyHelper.PrimaryKeyType.InfoClass; var primaryKeyLen = PrimaryKeyHelper.PrimaryKeyLen.V1; int systemId = entity.SystemID; string companyId = entity.CompanyID; string classId = PrimaryKeyHelper.MakePrimaryKey(infoClass, primaryKeyLen); string className = entity.ClassName; int classType = entity.ClassType.ToInt(); string parentId = string.IsNullOrEmpty(entity.ParentID) ? "0" : entity.ParentID; bool state = entity.State.ToBool(); if (parentId != "0") { bool verifyParentId = IsExists(m => m.SystemID == systemId && m.CompanyID == companyId && m.ClassID == parentId); if (!verifyParentId) { throw new Exception("上级分类ID不存在!"); } } bool verifyClassName = IsExists(m => m.SystemID == systemId && m.CompanyID == companyId && m.ParentID == parentId && m.ClassName == className); if (verifyClassName) { throw new Exception("分类名称已存在!"); } if (parentId == "0") { entity.ParentID = "0"; entity.ParentPath = "0"; entity.ClassRank = 1; entity.OrderID = 0; entity.OrderPath = classId; } else { var entityClass = Find(m => m.SystemID == systemId && m.CompanyID == companyId && m.ClassID == parentId); int classRank = entityClass.ClassRank.ToInt(); string parentPath = entityClass.ParentPath; string orderPath = entityClass.OrderPath; entity.ParentID = parentId; entity.ParentPath = string.Format("{0},{1}", parentPath, parentId); entity.ClassRank = (classRank + 1).ToByte(); entity.OrderID = 0; entity.OrderPath = string.Format("{0}{1}", orderPath, classId); } entity.ClassID = classId; entity.State = state; entity.CreateDate = DateTime.Now; var infoPage = PrimaryKeyHelper.PrimaryKeyType.InfoPage; var infoPageVersion = PrimaryKeyHelper.PrimaryKeyLen.V1; string pageId = PrimaryKeyHelper.MakePrimaryKey(infoPage, infoPageVersion); var entityPage = new Info_Page() { SystemID = systemId, CompanyID = companyId, PageID = pageId, Title = entity.ClassName, ClassID = entity.ClassID, ClassName = entity.ClassName, Sort = 0, State = true, CreateDate = DateTime.Now }; int intnum = 0; var dbContext = new DAL.BaseDAL(CTMSContext); using (var db = dbContext.DbEntities()) { //using (var trans = db.Database.BeginTransaction()) //{ // try // { // dbContext.Add(entity); // if (classType == 1) // dbContext.Add(entityPage); // intnum = db.SaveChanges(); // trans.Commit(); // } // catch (Exception) // { // trans.Rollback(); // } // return intnum > 0; //} db.Orm.Transaction(() => { dbContext.Add(entity); if (classType == 1) { dbContext.Add(entityPage); } intnum = db.SaveChanges(); }); return(intnum > 0); } } catch (Exception ex) { throw new Exception(ex.Message); } }