public void Update(DbContext DbContext,StaffStation entity) { EntityState state = DbContext.Entry(entity).State; if (state == EntityState.Detached) { DbContext.Entry(entity).State = EntityState.Modified; } }
public override OperationResult Create(StaffInfo info) { OperationResult result = new OperationResult(OperationResultType.Error, "操作失败,请稍后重试!"); using (var DbContext = new UCDbContext()) { Staff entity = new Staff(); DESwap.StaffDTE(info, entity); StaffRpt.Insert(DbContext, entity); /*关联角色是否为空*/ if (info.StaffStationInfoList != null) { /*****新增列表*********/ List<StaffStation> insertlist = new List<StaffStation>(); /*****删除列表*********/ List<StaffStation> deletelist = new List<StaffStation>(); /*原有列表*/ var existlist = (from i in DbContext.StaffStation where i.StaffId.Equals(info.Id) select i).ToList(); /*************如果为选中且没有关联表id则为新增******************/ foreach (var rfinfo in info.StaffStationInfoList) { if (string.IsNullOrEmpty(rfinfo.Id) && rfinfo.Selected) { /*************如果为选中且没有关联表id则为新增******************/ rfinfo.Id = System.Guid.NewGuid().ToString(); rfinfo.StaffId = info.Id; StaffStation staffStation = new StaffStation(); DESwap.StaffStationDTE(rfinfo, staffStation); insertlist.Add(staffStation); } else if (!string.IsNullOrEmpty(rfinfo.Id) && rfinfo.Selected == false) { /*************如果为未选中且有关联表id则为删除******************/ var staffStation = existlist.Where(x => x.Id.Equals(rfinfo.Id)).FirstOrDefault(); if (staffStation == null) { deletelist.Add(staffStation); } } } StaffStationRpt.Insert(DbContext, insertlist); StaffStationRpt.Delete(DbContext, deletelist); } DbContext.SaveChanges(); result.ResultType = OperationResultType.Success; result.Message = "操作成功!"; return result; } }
public virtual OperationResult Create(StaffStationInfo info) { OperationResult result = new OperationResult(OperationResultType.Error, "操作失败,请稍后重试!"); using (var DbContext = new UCDbContext()) { StaffStation entity = new StaffStation(); DESwap.StaffStationDTE(info, entity); StaffStationRpt.Insert(DbContext, entity); DbContext.SaveChanges(); } result.ResultType = OperationResultType.Success; result.Message = "操作成功!"; return result; }
public virtual OperationResult Create(IEnumerable<StaffStationInfo> infoList) { OperationResult result = new OperationResult(OperationResultType.Error, "操作失败,请稍后重试!"); List<StaffStation> eList = new List<StaffStation>(); infoList.ForEach(x => { StaffStation entity = new StaffStation(); DESwap. StaffStationDTE(x, entity); eList.Add(entity); }); using (var DbContext = new UCDbContext()) { StaffStationRpt.Insert(DbContext, eList); DbContext.SaveChanges(); } result.ResultType = OperationResultType.Success; result.Message = "操作成功!"; return result; }
public void Insert(DbContext DbContext,StaffStation entity) { DbContext.Entry(entity).State = EntityState.Added; }
public void Delete(DbContext DbContext,StaffStation entity) { DbContext.Entry(entity).State = EntityState.Deleted; }
public static void StaffStationETD(StaffStation entity, StaffStationInfo info) { info.Id = entity.Id; info._IdIsDirty = 0; info.StaffId = entity.StaffId; info._StaffIdIsDirty = 0; info.StationId = entity.StationId; info._StationIdIsDirty = 0; info.SYS_OrderSeq = entity.SYS_OrderSeq; info._SYS_OrderSeqIsDirty = 0; info.SYS_IsValid = entity.SYS_IsValid; info._SYS_IsValidIsDirty = 0; info.SYS_IsDeleted = entity.SYS_IsDeleted; info._SYS_IsDeletedIsDirty = 0; info.SYS_Remark = entity.SYS_Remark; info._SYS_RemarkIsDirty = 0; info.SYS_StaffId = entity.SYS_StaffId; info._SYS_StaffIdIsDirty = 0; info.SYS_StationId = entity.SYS_StationId; info._SYS_StationIdIsDirty = 0; info.SYS_DepartmentId = entity.SYS_DepartmentId; info._SYS_DepartmentIdIsDirty = 0; info.SYS_CompanyId = entity.SYS_CompanyId; info._SYS_CompanyIdIsDirty = 0; info.SYS_AppId = entity.SYS_AppId; info._SYS_AppIdIsDirty = 0; info.SYS_CreateTime = entity.SYS_CreateTime; info._SYS_CreateTimeIsDirty = 0; info.SYS_ModifyTime = entity.SYS_ModifyTime; info._SYS_ModifyTimeIsDirty = 0; info.SYS_DeleteTime = entity.SYS_DeleteTime; info._SYS_DeleteTimeIsDirty = 0; }
public static void StaffStationDTE(StaffStationInfo info, StaffStation entity) { if (info._IdIsDirty == 1) { entity.Id = info.Id; info._IdIsDirty = 0; } if (info._StaffIdIsDirty == 1) { entity.StaffId = info.StaffId; info._StaffIdIsDirty = 0; } if (info._StationIdIsDirty == 1) { entity.StationId = info.StationId; info._StationIdIsDirty = 0; } if (info._SYS_OrderSeqIsDirty == 1) { entity.SYS_OrderSeq = info.SYS_OrderSeq; info._SYS_OrderSeqIsDirty = 0; } if (info._SYS_IsValidIsDirty == 1) { entity.SYS_IsValid = info.SYS_IsValid; info._SYS_IsValidIsDirty = 0; } if (info._SYS_IsDeletedIsDirty == 1) { entity.SYS_IsDeleted = info.SYS_IsDeleted; info._SYS_IsDeletedIsDirty = 0; } if (info._SYS_RemarkIsDirty == 1) { entity.SYS_Remark = info.SYS_Remark; info._SYS_RemarkIsDirty = 0; } if (info._SYS_StaffIdIsDirty == 1) { entity.SYS_StaffId = info.SYS_StaffId; info._SYS_StaffIdIsDirty = 0; } if (info._SYS_StationIdIsDirty == 1) { entity.SYS_StationId = info.SYS_StationId; info._SYS_StationIdIsDirty = 0; } if (info._SYS_DepartmentIdIsDirty == 1) { entity.SYS_DepartmentId = info.SYS_DepartmentId; info._SYS_DepartmentIdIsDirty = 0; } if (info._SYS_CompanyIdIsDirty == 1) { entity.SYS_CompanyId = info.SYS_CompanyId; info._SYS_CompanyIdIsDirty = 0; } if (info._SYS_AppIdIsDirty == 1) { entity.SYS_AppId = info.SYS_AppId; info._SYS_AppIdIsDirty = 0; } if (info._SYS_CreateTimeIsDirty == 1) { entity.SYS_CreateTime = info.SYS_CreateTime; info._SYS_CreateTimeIsDirty = 0; } if (info._SYS_ModifyTimeIsDirty == 1) { entity.SYS_ModifyTime = info.SYS_ModifyTime; info._SYS_ModifyTimeIsDirty = 0; } if (info._SYS_DeleteTimeIsDirty == 1) { entity.SYS_DeleteTime = info.SYS_DeleteTime; info._SYS_DeleteTimeIsDirty = 0; } }