public void SubmitWorkItemForm(ProfileSanitationCarWorkItemEntity entity, string keyValue) { if (!string.IsNullOrEmpty(keyValue)) { entity.Modify(keyValue); workItemService.Update(entity); } else { entity.Create(); workItemService.Insert(entity); } }
/// <summary> /// 单条 /// 批量导入 /// </summary> /// <param name="entity"></param> /// <param name="skipWhere"></param> /// <param name="coverWhere"></param> public void BatchCarWorkItemSubmitFrom(ProfileSanitationCarWorkItemEntity entity, Func <ProfileSanitationCarWorkItemEntity, ProfileSanitationCarWorkItemEntity, bool> skipWhere, Func <ProfileSanitationCarWorkItemEntity, ProfileSanitationCarWorkItemEntity, bool> coverWhere) { if (skipWhere != null) { Func <ProfileSanitationCarWorkItemEntity, bool> dbskipWhere = db => skipWhere(db, entity); var dbSkipQuery = this.workItemService.dbcontext.Set <ProfileSanitationCarWorkItemEntity>().Where(dbskipWhere); if (dbSkipQuery.Count() > 0) { return; } } if (coverWhere != null) { Func <ProfileSanitationCarWorkItemEntity, bool> dbCoverWhere = db => coverWhere(db, entity); var dbCoverQuery = this.workItemService.dbcontext.Set <ProfileSanitationCarWorkItemEntity>().Where(dbCoverWhere); if (dbCoverQuery.Count() > 0) { var dbEntity = dbCoverQuery.FirstOrDefault(); dbEntity.Note = entity.Note; dbEntity.Subscript = entity.Subscript; dbEntity.WorkAddress = entity.WorkAddress; dbEntity.WorkName = entity.WorkName; dbEntity.WorkShift = entity.WorkShift; dbEntity.WorkTime = entity.WorkTime; dbEntity.Modify(dbEntity.F_Id); this.workItemService.Update(dbEntity); return; } } entity.Create(); this.workItemService.Insert(entity); }
public void SubmitForm(ProfileSanitationCarEntity entity, string keyValue, ProfileCarWorkItemContracts[] works) { using (var db = new RepositoryBase().BeginTrans()) { if (!string.IsNullOrEmpty(keyValue))//修改 { db.Update <ProfileSanitationCarEntity>(entity); #region 查看有没有要删除项 var workItemDbIds = db.IQueryable <ProfileSanitationCarWorkItemEntity>().Where(d => d.WorkShift == entity.WorkShift).Select(d => d.F_Id).ToArray(); var workItemIds = works.Select(d => d.id).ToArray(); string[] delworkItems = workItemDbIds.Except(workItemIds).ToArray(); foreach (var item in delworkItems) { db.Delete <ProfileSanitationCarWorkItemEntity>(db.FindEntity <ProfileSanitationCarWorkItemEntity>(item)); } #endregion ProfileSanitationCarWorkItemEntity workEntity = null; foreach (var item in works) { workEntity = new ProfileSanitationCarWorkItemEntity(); workEntity.WorkShift = entity.WorkShift; workEntity.Subscript = item.subscript; workEntity.WorkTime = item.time; workEntity.WorkName = item.rinseName; workEntity.WorkAddress = item.rinseAddress; workEntity.Note = item.Note; if (string.IsNullOrEmpty(item.id) || item.id.Equals("-1")) { workEntity.Create(); db.Insert <ProfileSanitationCarWorkItemEntity>(workEntity); } else { workEntity.F_Id = item.id; workEntity.Modify(item.id); db.Update <ProfileSanitationCarWorkItemEntity>(workEntity); } } } else { db.Insert <ProfileSanitationCarEntity>(entity); ProfileSanitationCarWorkItemEntity workEntity = null; foreach (var item in works) { workEntity = new ProfileSanitationCarWorkItemEntity(); workEntity.WorkShift = entity.WorkShift; workEntity.Subscript = item.subscript; workEntity.WorkTime = item.time; workEntity.WorkName = item.rinseName; workEntity.WorkAddress = item.rinseAddress; workEntity.Note = item.Note; workEntity.Create(); db.Insert <ProfileSanitationCarWorkItemEntity>(workEntity); } } db.Commit(); } }