| | |
| | | /// <summary> |
| | | /// 插入拓展 |
| | | /// </summary> |
| | | public long InsertEx(Entity.XhsProject project, Entity.XhsProjectSite site) |
| | | public long InsertEx(Entity.XhsProject entityProject, List<Entity.XhsProjectSite> entityProjectSiteList) |
| | | { |
| | | if (project == null) |
| | | if (entityProject == null) |
| | | { |
| | | return default; |
| | | } |
| | |
| | | try |
| | | { |
| | | db.BeginTran(); |
| | | if (project.ID < 1) |
| | | if (entityProject.ID < 1) |
| | | { |
| | | project.ID = db.Insertable(project).ExecuteReturnSnowflakeId(); |
| | | if (project.ID < 1) |
| | | entityProject.ID = db.Insertable(entityProject).ExecuteReturnSnowflakeId(); |
| | | if (entityProject.ID < 1) |
| | | { |
| | | db.RollbackTran(); |
| | | return default; |
| | |
| | | } |
| | | else |
| | | { |
| | | var bol = db.Insertable(project).ExecuteCommand() > 0; |
| | | var bol = db.Insertable(entityProject).ExecuteCommand() > 0; |
| | | if (!bol) |
| | | { |
| | | db.RollbackTran(); |
| | |
| | | } |
| | | } |
| | | |
| | | if (site != null) |
| | | if (entityProjectSiteList != null && entityProjectSiteList.Count > 0) |
| | | { |
| | | site.ProjectID = project.ID; |
| | | if (site.ID < 1) |
| | | foreach (var entityProjectSite in entityProjectSiteList) |
| | | { |
| | | site.ID = db.Insertable(site).ExecuteReturnSnowflakeId(); |
| | | if (site.ID < 1) |
| | | entityProjectSite.ProjectID = entityProject.ID; |
| | | if (entityProjectSite.ID < 1) |
| | | { |
| | | db.RollbackTran(); |
| | | return default; |
| | | entityProjectSite.ID = db.Insertable(entityProjectSite).ExecuteReturnSnowflakeId(); |
| | | if (entityProjectSite.ID < 1) |
| | | { |
| | | db.RollbackTran(); |
| | | return default; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var bol = db.Insertable(site).ExecuteCommand() >= 0; |
| | | if (!bol) |
| | | else |
| | | { |
| | | db.RollbackTran(); |
| | | return default; |
| | | var bol = db.Insertable(entityProjectSite).ExecuteCommand() >= 0; |
| | | if (!bol) |
| | | { |
| | | db.RollbackTran(); |
| | | return default; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return project.ID; |
| | | db.CommitTran(); |
| | | return entityProject.ID; |
| | | } |
| | | catch |
| | | { |
| | |
| | | /// <summary> |
| | | /// 编辑拓展 |
| | | /// </summary> |
| | | public bool UpdateEx(Entity.XhsProject project, Entity.XhsProjectSite site) |
| | | public bool UpdateEx(Entity.XhsProject entityProject, List<Entity.XhsProjectSite> entityProjectSiteList) |
| | | { |
| | | if (project == null) |
| | | if (entityProject == null) |
| | | { |
| | | return false; |
| | | } |
| | | if (project.ID < 1) |
| | | if (entityProject.ID < 1) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | try |
| | | { |
| | | db.BeginTran(); |
| | | var bol = db.Updateable(project).ExecuteCommandHasChange(); |
| | | var bol = db.Updateable(entityProject).ExecuteCommandHasChange(); |
| | | if (!bol) |
| | | { |
| | | db.RollbackTran(); |
| | | return false; |
| | | } |
| | | if (site != null) |
| | | if (entityProjectSiteList != null && entityProjectSiteList.Count > 0) |
| | | { |
| | | site.ProjectID = project.ID; |
| | | if (site.ID < 1) |
| | | foreach (var entityProjectSite in entityProjectSiteList) |
| | | { |
| | | db.RollbackTran(); |
| | | return false; |
| | | } |
| | | bol = db.Updateable(site).ExecuteCommandHasChange(); |
| | | if (!bol) |
| | | { |
| | | db.RollbackTran(); |
| | | return false; |
| | | entityProjectSite.ProjectID = entityProject.ID; |
| | | if (entityProjectSite.ID < 1) |
| | | { |
| | | db.RollbackTran(); |
| | | return false; |
| | | } |
| | | bol = db.Updateable(entityProjectSite).ExecuteCommandHasChange(); |
| | | if (!bol) |
| | | { |
| | | db.RollbackTran(); |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | catch |
| | | { |
| | | db.RollbackTran(); |
| | | throw; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新开始时间 |
| | | /// </summary> |
| | | public virtual bool UpdateStartTime(long ID, DateTime StartTime) |
| | | { |
| | | using (SqlSugarClient db = new(ConnectionConfig)) |
| | | { |
| | | return db.Updateable<Entity.XhsProject>() |
| | | .SetColumns(x => x.StartTime == StartTime) |
| | | .Where(x => x.ID == ID) |
| | | .ExecuteCommand() > 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新结束时间 |
| | | /// </summary> |
| | | public virtual bool UpdateEndTime(long ID, DateTime EndTime) |
| | | { |
| | | using (SqlSugarClient db = new(ConnectionConfig)) |
| | | { |
| | | return db.Updateable<Entity.XhsProject>() |
| | | .SetColumns(x => x.EndTime == EndTime) |
| | | .Where(x => x.ID == ID) |
| | | .ExecuteCommand() > 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过 ID 删除 (拓展) |
| | | /// </summary> |
| | | public bool DeleteExByID(long ID) |
| | | { |
| | | if (ID < 1) |
| | | { |
| | | return false; |
| | | } |
| | | using (var db = new SqlSugarClient(ConnectionConfig)) |
| | | { |
| | | try |
| | | { |
| | | db.BeginTran(); |
| | | var bol = db.Deleteable<Entity.XhsProject>().Where(x => x.ID == ID).ExecuteCommandHasChange(); |
| | | if (!bol) |
| | | { |
| | | db.RollbackTran(); |
| | | return false; |
| | | } |
| | | db.Deleteable<Entity.XhsProjectSite>().Where(x => x.ProjectID == ID).ExecuteCommandHasChange(); |
| | | db.CommitTran(); |
| | | return true; |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | } |